You are here

public function ConfigSplitActivateForm::buildForm in Configuration Split 2.0.x

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/ConfigSplitActivateForm.php, line 84

Class

ConfigSplitActivateForm
The form for activating a split.

Namespace

Drupal\config_split\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $split = $this
    ->getSplit();
  $comparer = new StorageComparer($this->manager
    ->singleActivate($split, !$split
    ->get('status')), $this->activeStorage);
  $options = [
    'route' => [
      'config_split' => $split
        ->getName(),
      'operation' => 'activate',
    ],
    'operation label' => $this
      ->t('Import all'),
  ];
  $form = $this
    ->buildFormWithStorageComparer($form, $form_state, $comparer, $options);
  if (!$split
    ->get('status')) {
    $locallyDeactivated = $this->statusOverride
      ->getSplitOverride($split
      ->getName()) === FALSE;
    $form['activate_local_only'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Activate locally only'),
      '#description' => $this
        ->t('If this is set, the split config will not be made active by default but instead it will be locally overwritten to be active.'),
      '#default_value' => !$locallyDeactivated,
    ];
    if ($locallyDeactivated) {
      $form['deactivation_notice'] = [
        '#type' => 'markup',
        '#markup' => $this
          ->t('The local inactivation state override will be removed'),
      ];
    }
  }
  return $form;
}