You are here

public function GroupAddForm::buildForm in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/Form/GroupAddForm.php \Drupal\context_groups\Form\GroupAddForm::buildForm()

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/GroupAddForm.php, line 93

Class

GroupAddForm
Class GroupDeleteForm.

Namespace

Drupal\context_groups\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $context = NULL, $theme = NULL) {
  $this->context = $this->entityTypeManager
    ->getStorage('context')
    ->load($context);

  // Group name field.
  $form['group_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Group name'),
    '#required' => TRUE,
  ];
  $form['name'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#machine_name' => [
      'source' => [
        'group_name',
      ],
      'exists' => [
        $this,
        'groupExists',
      ],
    ],
  ];
  $form['class'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Class'),
    '#descriptions' => $this
      ->t('Set classes to group. Separate multiple classes with space.'),
  ];
  $form['region'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Select region'),
    '#options' => $this
      ->getRegionsList($theme),
    '#description' => $this
      ->t('Select the region where this group should be inserted.'),
  ];
  $form['context_id'] = [
    '#type' => 'hidden',
    '#value' => $context,
  ];
  $form['theme'] = [
    '#type' => 'hidden',
    '#value' => $theme,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add group'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => '::submitFormAjax',
      'wrapper' => 'context-group-add-group',
      'effect' => 'fade',
    ],
  ];
  return $form;
}