You are here

public function AddVariantContextsForm::addContext in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Form/AddVariantContextsForm.php \Drupal\page_manager_ui\Form\AddVariantContextsForm::addContext()

Override to add the variant id.

Overrides ManageContext::addContext

File

page_manager_ui/src/Form/AddVariantContextsForm.php, line 30
Contains \Drupal\page_manager_ui\Form\AddVariantContextsForm.

Class

AddVariantContextsForm

Namespace

Drupal\page_manager_ui\Form

Code

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(), $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'] = $this
    ->url($this
    ->getContextAddRoute($cached_values), $route_parameters, [
    'query' => [
      FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
    ],
  ]);
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand($this
    ->t('Add new context'), $content, array(
    'width' => '700',
  )));
  return $response;
}