You are here

public function EnvironmentAdminSettings::buildForm in Environment 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/EnvironmentAdminSettings.php, line 44
Contains \Drupal\environment\Form\EnvironmentAdminSettings.

Class

EnvironmentAdminSettings

Namespace

Drupal\environment\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  $env_req_override = \Drupal::config('environment.settings')
    ->get('environment_require_override');
  $env_current = environment_current(FALSE);
  if (!$env_current) {
    drupal_set_message($this
      ->t('Not in a valid environment. Saving this form will put it into a valid environment if one exists.'), 'warning');
  }
  $form['environment'] = [
    '#title' => t('Current Environment'),
    '#markup' => '<p>' . $this
      ->t('Current Environment') . ': ' . $env_current . '</p>',
  ];
  if ($env_req_override) {
    $active = $this
      ->t('Active');
  }
  else {
    $active = $this
      ->t('Not Active');
  }
  $form['environment_override'] = [
    '#markup' => '<p>' . $this
      ->t('Environment Override') . ': ' . $active . '</p>',
  ];
  if (!$env_req_override) {
    $form['environments'] = [
      '#title' => $this
        ->t('Select an environment'),
      '#description' => $this
        ->t('This is the environment you want to switch to.'),
      '#type' => 'select',
      '#options' => _environment_options(),
      '#default_value' => $env_current,
    ];
  }
  $form['environment_require_override'] = [
    '#type' => 'checkbox',
    '#title' => t('Require environment override'),
    '#description' => t('Used to require that an environment is set in the settings.php file.'),
    '#default_value' => \Drupal::config('environment.settings')
      ->get('environment_require_override'),
  ];
  return parent::buildForm($form, $form_state);
}