public function PageVariantContextsForm::addContext in Page Manager 8.4
Same name and namespace in other branches
- 8 page_manager_ui/src/Form/PageVariantContextsForm.php \Drupal\page_manager_ui\Form\PageVariantContextsForm::addContext()
Override to add the variant id.
Overrides ManageContext::addContext
File
- page_manager_ui/
src/ Form/ PageVariantContextsForm.php, line 26
Class
Namespace
Drupal\page_manager_ui\FormCode
public function addContext(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/** @var $page_variant \Drupal\page_manager\Entity\PageVariant */
$page_variant = $cached_values['page_variant'];
$context = $form_state
->getValue('context');
$content = $this->formBuilder
->getForm($this
->getContextClass($cached_values), $context, $this
->getTempstoreId(), $this->machine_name, $page_variant
->id());
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
list(, $route_parameters) = $this
->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context);
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = Url::fromRoute($this
->getContextAddRoute($cached_values), $route_parameters, [
'query' => [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
])
->toString();
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($this
->t('Add new context'), $content, [
'width' => '700',
]));
return $response;
}