diff --git a/panels.routing.yml b/panels.routing.yml index 0402329..f1dfdb3 100644 --- a/panels.routing.yml +++ b/panels.routing.yml @@ -1,11 +1,3 @@ -panels.layout.change_form: - path: '/admin/structure/panels/{tempstore_id}/{machine_name}/layout/{step}' - defaults: - _wizard: '\Drupal\panels\Wizard\LayoutChangeWizard' - _title: 'Add page variant' - step: 'settings' - requirements: - _permission: 'administer pages' panels.select_block: path: '/admin/structure/panels/{tempstore_id}/{machine_name}/select_block' defaults: diff --git a/src/Plugin/DisplayVariant/PanelsDisplayVariant.php b/src/Plugin/DisplayVariant/PanelsDisplayVariant.php index 9cb30cb..a7854d7 100644 --- a/src/Plugin/DisplayVariant/PanelsDisplayVariant.php +++ b/src/Plugin/DisplayVariant/PanelsDisplayVariant.php @@ -25,9 +25,9 @@ use Drupal\panels\Form\LayoutChangeRegions; use Drupal\panels\Form\LayoutChangeSettings; use Drupal\panels\Form\LayoutPluginSelector; use Drupal\panels\Form\LayoutPluginUpdate; -use Drupal\panels\PanelsPattern\Plugin\PanelsPatternInterface; use Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderInterface; use Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderManagerInterface; +use Drupal\panels\Plugin\PanelsPattern\PanelsPatternInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -220,14 +220,29 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn */ public function getPattern() { if (!isset($this->pattern)) { - $this->pattern = \Drupal::service('plugin.manager.panels.pattern')->createInstance('default'); + if (empty($this->configuration['pattern'])) { + $this->pattern = \Drupal::service('plugin.manager.panels.pattern')->createInstance('default'); + } + else { + $this->pattern = \Drupal::service('plugin.manager.panels.pattern')->createInstance($this->configuration['pattern']); + } } return $this->pattern; } - public function setPattern(PanelsPatternInterface $pattern) { - $this->pattern = $pattern; - $this->configuration['pattern'] = $pattern->getPluginId(); + public function setPattern($pattern) { + if ($pattern instanceof PanelsPatternInterface) { + $this->pattern = $pattern; + $this->configuration['pattern'] = $pattern->getPluginId(); + } + elseif (is_string($pattern)) { + $this->pattern = NULL; + $this->configuration['pattern'] = $pattern; + } + else { + throw new \Exception("Pattern must be a string or PanelsPatternInterface object"); + } + return $this; } diff --git a/src/Wizard/LayoutChangeWizard.php b/src/Wizard/LayoutChangeWizard.php deleted file mode 100644 index 5bfa245..0000000 --- a/src/Wizard/LayoutChangeWizard.php +++ /dev/null @@ -1,113 +0,0 @@ -getTempstore()->get($this->getMachineName()); - $event = new WizardEvent($this, $values); - $this->dispatcher->dispatch(FormWizardInterface::LOAD_VALUES, $event); - return $event->getValues(); - } - - /** - * {@inheritdoc} - */ - public function getOperations($cached_values) { - $operations = []; - $operations['settings'] = [ - 'title' => $this->t('Settings'), - 'form' => LayoutChangeSettings::class, - ]; - $operations['regions'] = [ - 'title' => $this->t('Regions'), - 'form' => LayoutChangeRegions::class, - ]; - - return $operations; - } - - /** - * {@inheritdoc} - */ - protected function customizeForm(array $form, FormStateInterface $form_state) { - $form = parent::customizeForm($form, $form_state); - - // We set the variant id as part of form submission. - if ($this->step == 'type' && isset($form['name']['id'])) { - unset($form['name']['id']); - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getNextParameters($cached_values) { - $parameters = parent::getNextParameters($cached_values); - - // Add the page to the url parameters. - $parameters['tempstore_id'] = $cached_values['layout_change']['tempstore_id']; - return $parameters; - } - - /** - * {@inheritdoc} - */ - public function getPreviousParameters($cached_values) { - $parameters = parent::getPreviousParameters($cached_values); - - // Add the page to the url parameters. - $parameters['tempstore_id'] = $cached_values['layout_change']['tempstore_id']; - return $parameters; - } - - /** - * {@inheritdoc} - */ - public function finish(array &$form, FormStateInterface $form_state) { - $cached_values = $form_state->getTemporaryValue('wizard'); - - // Add the variant to the parent page tempstore. - $page_tempstore = $this->tempstore->get('page_manager.page')->get($cached_values['page']->id()); - $page_tempstore['page']->addVariant($cached_values['page_variant']); - $this->tempstore->get('page_manager.page')->set($cached_values['page']->id(), $page_tempstore); - - $variant_plugin = $cached_values['page_variant']->getVariantPlugin(); - drupal_set_message($this->t('The %label @entity_type has been added to the page, but has not been saved. Please save the page to store changes.', array( - '%label' => $cached_values['page_variant']->label(), - '@entity_type' => $variant_plugin->adminLabel(), - ))); - - $form_state->setRedirectUrl(new Url('entity.page.edit_form', [ - 'machine_name' => $cached_values['page']->id(), - 'step' => 'general', - ])); - } - -}