You are here

public function ConditionCreatorForm::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

block_visibility_groups_admin/src/Form/ConditionCreatorForm.php, line 52

Class

ConditionCreatorForm
Provides a form to create conditions.

Namespace

Drupal\block_visibility_groups_admin\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $route_name = NULL, $parameters = NULL) {
  $parameters = Json::decode($parameters);
  if (empty($route_name)) {

    // @todo Throw error
  }
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#description' => $this
      ->t("Label for the Block Visibility Group."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#machine_name' => [
      'exists' => '\\Drupal\\block_visibility_groups\\Entity\\BlockVisibilityGroup::load',
    ],
  ];
  $form['conditions'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Conditions'),
    '#description' => $this
      ->t('Select at least one condition that applies to the current page.'),
  ];
  $form['conditions'] += $this
    ->conditionOptions($route_name, $parameters);
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Create new Group'),
  ];
  $form['route_name'] = [
    '#type' => 'value',
    '#value' => $route_name,
  ];
  $form['parameters'] = [
    '#type' => 'value',
    '#value' => $parameters,
  ];
  return $form;
}