3 namespace Drupal\environment_indicator;
6 use Drupal\Core\Entity\EntityForm;
7 use Drupal\Core\Form\FormStateInterface;
9 class EnvironmentIndicatorForm extends EntityForm {
12 * This actually builds your form.
14 public function form(array $form, FormStateInterface $form_state) {
15 /* @var \Drupal\environment_indicator\Entity\EnvironmentIndicator $environment_switcher */
16 $environment_switcher = $this->getEntity();
19 '#type' => 'textfield',
20 '#title' => t('Name'),
21 '#default_value' => $environment_switcher->label(),
24 '#type' => 'machine_name',
27 'exists' => 'environment_indicator_load',
29 '#default_value' => $environment_switcher->id(),
30 '#disabled' => !empty($environment_switcher->machine),
34 '#title' => t('Hostname'),
35 '#description' => t('The hostname you want to switch to.'),
36 '#default_value' => $environment_switcher->getUrl(),
40 '#title' => t('Background Color'),
41 '#description' => t('Background color for the indicator. Ex: #0D0D0D.'),
42 '#default_value' => $environment_switcher->getBgColor() ?: '#0D0D0D',
46 '#title' => t('Color'),
47 '#description' => t('Color for the indicator. Ex: #D0D0D0.'),
48 '#default_value' => $environment_switcher->getFgColor() ?: '#D0D0D0',
55 * Save your config entity.
57 * There will eventually be default code to rely on here, but it doesn't exist
60 public function save(array $form, FormStateInterface $form_state) {
61 $environment = $this->getEntity();
63 drupal_set_message(t('Saved the %label environment.', [
64 '%label' => $environment->label(),
67 $form_state->setRedirect('entity.environment_indicator.collection');