diff --git a/src/Form/PanelizerWizardContextForm.php b/src/Form/PanelizerWizardContextForm.php index bbb8a18..40857d4 100644 --- a/src/Form/PanelizerWizardContextForm.php +++ b/src/Form/PanelizerWizardContextForm.php @@ -10,6 +10,7 @@ namespace Drupal\panelizer\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\ctools\Form\ManageContext; +use Drupal\panelizer\Form\PanelizerWizardContextConfigure; /** * Simple wizard step form. @@ -108,4 +109,19 @@ class PanelizerWizardContextForm extends ManageContext { return !empty($context['value']); } + /** + * {@inheritdoc} + */ + 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'] = $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; + } + } diff --git a/src/Wizard/PanelizerEditWizard.php b/src/Wizard/PanelizerEditWizard.php index 1c2a355..491bc34 100644 --- a/src/Wizard/PanelizerEditWizard.php +++ b/src/Wizard/PanelizerEditWizard.php @@ -36,10 +36,20 @@ class PanelizerEditWizard extends FormWizardBase { if (empty($cached_values['page_variant'])) { // Load the page variant. - $cached_values['page_variant'] = \Drupal::entityManager() + $page_variant = \Drupal::entityManager() ->getStorage('page_variant') ->load($cached_values['id'] . '__variant'); + // Add a dummy page entity to the page variant. This is needed so the + // variant can be saved. + $page = \Drupal::entityManager() + ->getStorage('page') + ->create([ + 'id' => $cached_values['id'] . '__page', + ]); + $page_variant->setPageEntity($page); + $cached_values['page_variant'] = $page_variant; + // Load the panels display variant. $panelizer = \Drupal::service('panelizer'); list($entity_type, $bundle, $display_id) = explode('__', $this->getMachineName()); @@ -242,6 +252,52 @@ class PanelizerEditWizard extends FormWizardBase { } /** + * Submission callback for the variant plugin steps. + */ + public function submitVariantStep(array &$form, FormStateInterface $form_state) { + $cached_values = $form_state->getTemporaryValue('wizard'); + /** @var \Drupal\page_manager\PageVariantInterface $page_variant */ + $page_variant = $cached_values['page_variant']; + /** @var \Drupal\Core\Display\VariantInterface $plugin */ + $plugin = $cached_values['plugin']; + + // Make sure the variant plugin on the page variant gets the configuration + // from the 'plugin' which should have been setup by the variant's steps. + if (!empty($plugin) && !empty($page_variant)) { + $page_variant->getVariantPlugin()->setConfiguration($plugin->getConfiguration()); + } + } + + /** + * {@inheritdoc} + */ + public function finish(array &$form, FormStateInterface $form_state) { + $cached_values = $form_state->getTemporaryValue('wizard'); + + $cached_values['page_variant']->save(); + + // Save the panels display mode and its custom settings as third party + // data of the display mode for this entity+bundle+display. + $panelizer = \Drupal::service('panelizer'); + $panelizer_entity_manager = \Drupal::service('plugin.manager.panelizer_entity'); + $panels_display_manager = \Drupal::service('panels.display_manager'); + list($entity_type, $bundle, $display_id) = explode('__', $cached_values['id']); + $display = $panelizer->getEntityViewDisplay($entity_type, $bundle, $display_id); + $settings = $panelizer->getPanelizerSettings($entity_type, $bundle, $display_id); + $settings['enable'] = TRUE; + $settings['custom'] = $cached_values['custom']; + /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_entity_plugin */ + $panelizer_entity_plugin = $panelizer_entity_manager->createInstance($display->getTargetEntityTypeId(), []); + $displays = $display->getThirdPartySetting('panelizer', 'displays', []); + $displays[$display_id] = $panels_display_manager->exportDisplay($cached_values['plugin']); + $display->setThirdPartySetting('panelizer', 'displays', $displays); + $panelizer->setPanelizerSettings($entity_type, $bundle, $display_id, $settings, $display); + + parent::finish($form, $form_state); + $form_state->setRedirect('panelizer.wizard.edit', ['machine_name' => $cached_values['id']]); + } + + /** * Clears the temporary store. * * @param array $form