You are here

public function DevelopmentEnvironmentSettingsForm::buildForm in Development 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 FormInterface::buildForm

File

src/Form/DevelopmentEnvironmentSettingsForm.php, line 65

Class

DevelopmentEnvironmentSettingsForm
DevelopmentEnvironmentConfigurationForm class.

Namespace

Drupal\development_environment\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Retrieve a value from settings.php, if one has been set.
  $settings_value = $this->settings
    ->get('development_environment.log_emails');
  if (is_null($settings_value)) {
    $form['log_emails'] = [
      '#title' => $this
        ->t('Log Emails'),
      '#type' => 'checkbox',
      '#default_value' => $this->state
        ->get('development_environment.log_emails'),
      '#description' => $this
        ->t('If this box is checked, emails will not longer be sent from this system, and will instead be written to a log. Note that this setting is NOT configuration, and will not migrate between environments. This value needs to be set independently for each environment.'),
    ];
    $form['log_emails_gui_description'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this
        ->t("To set this value and prevent it from being able to be managed through the admin UI, add a line containing <code>&#36;settings[\\'development_environment.log_emails\\'] = TRUE;</code> (or FALSE) to settings.php."),
    ];
  }
  else {
    $form['log_emails'] = [
      '#type' => 'value',
      '#value' => $settings_value,
    ];
    $form['log_emails_display'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
    if ($settings_value) {
      $form['log_emails_display']['#markup'] = $this
        ->t("Emails on the system are set to be logged in settings.php, and will NOT be sent from the system. To set emails to be sent rather than logged, edit settings.php, and set the value of <code>&#36;settings[\\'development_environment.log_emails\\']</code> to FALSE.");
    }
    else {
      $form['log_emails_display']['#markup'] = $this
        ->t("Emails on the system are NOT set to be logged in settings.php, and will be sent from the system. To set emails to be logged rather than sent, edit settings.php, and set the value of <code>&#36;settings[\\'development_environment.log_emails\\']</code> to TRUE.");
    }
    $form['log_emails_gui_description'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this
        ->t("To manage this setting through the admin UI, remove the line containing <code>&#36;settings[\\'development_environment.log_emails\\']</code> from settings.php altogether."),
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}