You are here

public function ConditionFormBase::buildForm in Block Visibility Groups 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/ConditionFormBase.php, line 94

Class

ConditionFormBase
Provides a base form for editing and adding a condition.

Namespace

Drupal\block_visibility_groups\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, BlockVisibilityGroupInterface $block_visibility_group = NULL, $condition_id = NULL, $redirect = NULL) {
  $this->block_visibility_group = $block_visibility_group;
  $this->condition = $this
    ->prepareCondition($condition_id);
  $this
    ->setRedirectValue($form, $redirect);

  // Store the gathered contexts in the form state for other objects to use
  // during form building.
  $form_state
    ->setTemporaryValue('gathered_contexts', $this->contextRepository
    ->getAvailableContexts());

  // Allow the condition to add to the form.
  $form['condition'] = $this->condition
    ->buildConfigurationForm([], $form_state);
  $form['condition']['#tree'] = TRUE;
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->submitButtonText(),
    '#button_type' => 'primary',
  ];
  return $form;
}