public function ManageContext::addContext in Chaos Tool Suite (ctools) 8.3
File
- src/
Form/ ManageContext.php, line 173
Class
Namespace
Drupal\ctools\FormCode
public function addContext(array &$form, FormStateInterface $form_state) {
$context = $form_state
->getValue('context');
$content = $this->formBuilder
->getForm($this
->getContextClass(), $context, $this
->getTempstoreId(), $this->machine_name);
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$cached_values = $form_state
->getTemporaryValue('wizard');
list(, $route_parameters) = $this
->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context);
$route_name = $this
->getContextAddRoute($cached_values);
$route_options = [
'query' => [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
];
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url
->toString();
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($this
->t('Add new context'), $content, [
'width' => '700',
]));
return $response;
}