You are here

public function ContextFormBase::form in Context 8

Same name and namespace in other branches
  1. 8.4 modules/context_ui/src/Form/ContextFormBase.php \Drupal\context_ui\Form\ContextFormBase::form()
  2. 8.0 modules/context_ui/src/Form/ContextFormBase.php \Drupal\context_ui\Form\ContextFormBase::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

1 call to ContextFormBase::form()
ContextEditForm::form in modules/context_ui/src/Form/ContextEditForm.php
Gets the actual form array to be built.
1 method overrides ContextFormBase::form()
ContextEditForm::form in modules/context_ui/src/Form/ContextEditForm.php
Gets the actual form array to be built.

File

modules/context_ui/src/Form/ContextFormBase.php, line 61

Class

ContextFormBase

Namespace

Drupal\context_ui\Form

Code

public function form(array $form, FormStateInterface $formState) {
  $form['general'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('General details'),
  ];
  $form['general']['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#default_value' => $this->entity
      ->getLabel(),
    '#required' => TRUE,
    '#description' => $this
      ->t('Enter label for this context.'),
  ];
  $form['general']['name'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $this->entity
      ->getName(),
    '#machine_name' => [
      'source' => [
        'general',
        'label',
      ],
      'exists' => [
        $this,
        'contextExists',
      ],
    ],
  ];
  $form['general']['group'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Group'),
    '#default_value' => $this->entity
      ->getGroup(),
    '#description' => $this
      ->t('Enter name of the group this context should belong to.'),
    '#autocomplete_route_name' => 'context.groups.autocomplete',
  ];
  $form['general']['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $this->entity
      ->getDescription(),
    '#description' => $this
      ->t('Enter a description for this context definition.'),
  ];
  return $form;
}