You are here

public function PanelizerWizardContextForm::addContext in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/Form/PanelizerWizardContextForm.php \Drupal\panelizer\Form\PanelizerWizardContextForm::addContext()
  2. 8.4 src/Form/PanelizerWizardContextForm.php \Drupal\panelizer\Form\PanelizerWizardContextForm::addContext()

Overrides ManageContext::addContext

File

src/Form/PanelizerWizardContextForm.php, line 143

Class

PanelizerWizardContextForm
Simple wizard step form.

Namespace

Drupal\panelizer\Form

Code

public function addContext(array &$form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');
  $context = $form_state
    ->getValue('context');
  $content = $this->formBuilder
    ->getForm($this
    ->getContextClass($cached_values), $context, $this
    ->getTempstoreId(), $this->machine_name);
  $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::fromUri($this
    ->getContextAddRoute($cached_values), [
    'query' => [
      FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
    ],
  ]);
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand($this
    ->t('Add new context'), $content, [
    'width' => '700',
  ]));
  return $response;
}