Including security review as a submodule - with patched for Yaffs.
[yaffs-website] / web / modules / contrib / environment_indicator / src / EnvironmentIndicatorForm.php
1 <?php
2
3 namespace Drupal\environment_indicator;
4
5
6 use Drupal\Core\Entity\EntityForm;
7 use Drupal\Core\Form\FormStateInterface;
8
9 class EnvironmentIndicatorForm extends EntityForm {
10
11   /**
12    * This actually builds your form.
13    */
14   public function form(array $form, FormStateInterface $form_state) {
15     /* @var \Drupal\environment_indicator\Entity\EnvironmentIndicator $environment_switcher */
16     $environment_switcher = $this->getEntity();
17
18     $form['name'] = [
19       '#type' => 'textfield',
20       '#title' => t('Name'),
21       '#default_value' => $environment_switcher->label(),
22     ];
23     $form['machine'] = [
24       '#type' => 'machine_name',
25       '#machine_name' => [
26         'source' => ['name'],
27         'exists' => 'environment_indicator_load',
28       ],
29       '#default_value' => $environment_switcher->id(),
30       '#disabled' => !empty($environment_switcher->machine),
31     ];
32     $form['url'] = [
33       '#type' => 'url',
34       '#title' => t('Hostname'),
35       '#description' => t('The hostname you want to switch to.'),
36       '#default_value' => $environment_switcher->getUrl(),
37     ];
38     $form['bg_color'] = [
39       '#type' => 'color',
40       '#title' => t('Background Color'),
41       '#description' => t('Background color for the indicator. Ex: #0D0D0D.'),
42       '#default_value' => $environment_switcher->getBgColor() ?: '#0D0D0D',
43     ];
44     $form['fg_color'] = [
45       '#type' => 'color',
46       '#title' => t('Color'),
47       '#description' => t('Color for the indicator. Ex: #D0D0D0.'),
48       '#default_value' => $environment_switcher->getFgColor() ?: '#D0D0D0',
49     ];
50
51     return $form;
52   }
53
54   /**
55    * Save your config entity.
56    *
57    * There will eventually be default code to rely on here, but it doesn't exist
58    * yet.
59    */
60   public function save(array $form, FormStateInterface $form_state) {
61     $environment = $this->getEntity();
62     $environment->save();
63     drupal_set_message(t('Saved the %label environment.', [
64       '%label' => $environment->label(),
65     ]));
66
67     $form_state->setRedirect('entity.environment_indicator.collection');
68   }
69
70 }