Security update for Core, with self-updated composer
[yaffs-website] / web / modules / contrib / environment_indicator / src / Form / EnvironmentIndicatorSettingsForm.php
1 <?php
2
3 namespace Drupal\environment_indicator\Form;
4
5 use Drupal\Core\Form\FormInterface;
6 use Drupal\Core\Form\ConfigFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8
9 class EnvironmentIndicatorSettingsForm extends ConfigFormBase implements FormInterface {
10
11   /**
12    * {@inheritdoc}
13    */
14   public function getFormID() {
15     return 'environment_indicator_settings_form';
16   }
17
18   /**
19    * {@inheritdoc}
20    */
21   public function buildForm(array $form, FormStateInterface $form_state) {
22     $config = $this->config('environment_indicator.settings');
23     $form = parent::buildForm($form, $form_state);
24     $form['toolbar_integration'] = [
25       '#type' => 'checkboxes',
26       '#title' => $this->t('Toolbar integration'),
27       '#options' => [
28         'toolbar' => $this->t('Toolbar'),
29       ],
30       '#description' => $this->t('Select the toolbars that you want to integrate with.'),
31       '#default_value' => $config->get('toolbar_integration') ?: [],
32     ];
33     $form['favicon'] = [
34       '#type' => 'checkbox',
35       '#title' => $this->t('Show favicon'),
36       '#description' => $this->t('If checked, a favicon will be added with the environment colors when the indicator is shown.'),
37       '#default_value' => $config->get('favicon') ?: FALSE,
38     ];
39     return $form;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   protected function getEditableConfigNames() {
46     return ['environment_indicator.settings'];
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function submitForm(array &$form, FormStateInterface $form_state) {
53     $config = $this->config('environment_indicator.settings');
54     $properties = ['toolbar_integration', 'favicon'];
55     array_walk($properties, function ($property) use ($config, $form_state) {
56       $config->set($property, $form_state->getValue($property));
57     });
58     $config->save();
59     parent::submitForm($form, $form_state);
60   }
61
62 }