You are here

public function RequiredContext::buildForm in Chaos Tool Suite (ctools) 8.3

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/RequiredContext.php, line 60

Class

RequiredContext

Namespace

Drupal\ctools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');
  $this->machine_name = $cached_values['id'];
  $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
  $options = [];
  foreach ($this->typedDataManager
    ->getDefinitions() as $plugin_id => $definition) {
    $options[$plugin_id] = (string) $definition['label'];
  }
  $form['items'] = [
    '#type' => 'markup',
    '#prefix' => '<div id="configured-contexts">',
    '#suffix' => '</div>',
    '#theme' => 'table',
    '#header' => [
      $this
        ->t('Information'),
      $this
        ->t('Description'),
      $this
        ->t('Operations'),
    ],
    '#rows' => $this
      ->renderContexts($cached_values),
    '#empty' => $this
      ->t('No required contexts have been configured.'),
  ];
  $form['contexts'] = [
    '#type' => 'select',
    '#options' => $options,
  ];
  $form['add'] = [
    '#type' => 'submit',
    '#name' => 'add',
    '#value' => $this
      ->t('Add required context'),
    '#ajax' => [
      'callback' => [
        $this,
        'add',
      ],
      'event' => 'click',
    ],
    '#submit' => [
      'callback' => [
        $this,
        'submitform',
      ],
    ],
  ];
  return $form;
}