X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fenvironment_indicator%2Fmodules%2Fenvironment_indicator_ui%2Fsrc%2FForm%2FEnvironmentIndicatorUISettingsForm.php;fp=web%2Fmodules%2Fcontrib%2Fenvironment_indicator%2Fmodules%2Fenvironment_indicator_ui%2Fsrc%2FForm%2FEnvironmentIndicatorUISettingsForm.php;h=f2061016571dc042aac699657b65f0c350fe7115;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/modules/contrib/environment_indicator/modules/environment_indicator_ui/src/Form/EnvironmentIndicatorUISettingsForm.php b/web/modules/contrib/environment_indicator/modules/environment_indicator_ui/src/Form/EnvironmentIndicatorUISettingsForm.php new file mode 100644 index 000000000..f20610165 --- /dev/null +++ b/web/modules/contrib/environment_indicator/modules/environment_indicator_ui/src/Form/EnvironmentIndicatorUISettingsForm.php @@ -0,0 +1,82 @@ +config('environment_indicator.indicator'); + $form = parent::buildForm($form, $form_state); + $form['name'] = [ + '#type' => 'textfield', + '#title' => $this->t('Environment Name'), + '#description' => $this->t('Enter a name for this environment to be displayed in the admin toolbar.'), + '#default_value' => $config->get('name'), + ]; + $form['fg_color'] = [ + '#type' => 'color', + '#title' => $this->t('Foreground Color'), + '#description' => $this->t('Foreground color for the admin toolbar. Ex: #0D0D0D.'), + '#default_value' => $config->get('fg_color'), + ]; + $form['bg_color'] = [ + '#type' => 'color', + '#title' => $this->t('Background Color'), + '#description' => $this->t('Background color for the admin toolbar. Example: #4298f4.'), + '#default_value' => $config->get('bg_color'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['environment_indicator.indicator']; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + $colors = [ + 'fg_color' => $form_state->getValue('fg_color'), + 'bg_color' => $form_state->getValue('bg_color'), + ]; + + foreach ($colors as $property_name => $color) { + if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { + $form_state->setErrorByName($property_name, $this->t('Please enter a valid hex value.')); + } + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $config = $this->config('environment_indicator.indicator'); + $properties = ['name', 'fg_color', 'bg_color']; + array_walk($properties, function ($property) use ($config, $form_state) { + $config->set($property, $form_state->getValue($property)); + }); + $config->save(); + parent::submitForm($form, $form_state); + } + +}