You are here

public function GroupEditForm::buildForm in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/Form/GroupEditForm.php \Drupal\context_groups\Form\GroupEditForm::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/GroupEditForm.php, line 73

Class

GroupEditForm
Class GroupEditForm.

Namespace

Drupal\context_groups\Form

Code

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

  // Group name field.
  $form['group_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Group name'),
    '#required' => TRUE,
    '#default_value' => $group['label'],
    '#description' => $this
      ->t('machine name: @machine_name', [
      '@machine_name' => $group['name'],
    ]),
  ];
  $form['name'] = [
    '#type' => 'hidden',
    '#value' => $group['name'],
  ];
  $form['class'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Class'),
    '#descriptions' => $this
      ->t('Set classes to group. Separate multiple classes with space.'),
    '#default_value' => $group['class'],
  ];
  $form['context_id'] = [
    '#type' => 'hidden',
    '#value' => $context,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#ajax' => [
      'callback' => '::submitFormAjax',
      'wrapper' => 'context-group-edit-form',
      'effect' => 'fade',
    ],
  ];
  return $form;
}