You are here

public function SettingsForm::buildForm in Habitat 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

habitat_ui/src/Form/SettingsForm.php, line 40
Contains \Drupal\habitat_ui\Form\SettingsForm.

Class

SettingsForm
Defines a form that configures habitat settings.

Namespace

Drupal\habitat_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('habitat.settings');
  $habitats = $config
    ->get('habitat_habitats');
  $form['variable'] = array(
    '#type' => 'textfield',
    '#title' => t('Habitat variable name'),
    '#required' => TRUE,
    '#default_value' => $config
      ->get('habitat_variable'),
    '#description' => t('The habitat variable used in your settings.php files to indicate the habitat. This should be placed into settings.php like $settings[\'!variable\'] = \'dev\'. Defaults to \'fetcher_environment\' which is added to settings.php when sites are built with the !fetcher system.', array(
      '!variable' => $config
        ->get('habitat_variable'),
      '!fetcher' => '<a href="http://drupal.org/project/fetcher">fetcher</a>',
    )),
  );
  $form['habitats'] = array(
    '#type' => 'textarea',
    '#title' => t('Habitats'),
    '#description' => t('The habitats to manage. Use machine_name conventions and enter one per line.'),
    '#required' => TRUE,
    '#default_value' => implode("\n", $habitats),
  );
  foreach ($habitats as $habitat) {
    $form['install_' . $habitat] = array(
      '#type' => 'textarea',
      '#title' => t('%habitat installed modules', array(
        '%habitat' => $habitat,
      )),
      '#description' => t('The modules to force install in this habitat. Use machine_name conventions and enter one per line.'),
      '#default_value' => implode("\n", $config
        ->get('habitat_install_' . $habitat)),
    );
    $form['uninstall_' . $habitat] = array(
      '#type' => 'textarea',
      '#title' => t('%habitat uninstalled modules', array(
        '%habitat' => $habitat,
      )),
      '#description' => t('The modules to force uninstall in this habitat. Use machine_name conventions and enter one per line.'),
      '#default_value' => implode("\n", $config
        ->get('habitat_uninstall_' . $habitat)),
    );
  }
  return parent::buildForm($form, $form_state);
}