function RequiredContext::buildForm

Same name in other branches
  1. 8.x-3.x src/Form/RequiredContext.php \Drupal\ctools\Form\RequiredContext::buildForm()

Overrides FormInterface::buildForm

File

src/Form/RequiredContext.php, line 69

Class

RequiredContext
Required Context Form.

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;
}