function RequiredContext::add

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

Custom ajax form submission handler.

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

\Drupal\Core\Ajax\AjaxResponse

File

src/Form/RequiredContext.php, line 122

Class

RequiredContext
Required Context Form.

Namespace

Drupal\ctools\Form

Code

public function add(array &$form, FormStateInterface $form_state) {
    $context = $form_state->getValue('contexts');
    $content = $this->formBuilder
        ->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
    $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response = new AjaxResponse();
    $response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, [
        'width' => '700',
    ]));
    return $response;
}