diff --git a/src/Form/PanelizerWizardGeneralForm.php b/src/Form/PanelizerWizardGeneralForm.php index 79096e6..923e245 100644 --- a/src/Form/PanelizerWizardGeneralForm.php +++ b/src/Form/PanelizerWizardGeneralForm.php @@ -11,7 +11,6 @@ namespace Drupal\panelizer\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; -use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant; /** * General settings for a panelized bundle. @@ -71,6 +70,13 @@ class PanelizerWizardGeneralForm extends FormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) { + $cached_values = $form_state->getTemporaryValue('wizard'); + /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */ + $plugin = $cached_values['plugin']; + $plugin->submitConfigurationForm($form['variant_settings'], (new FormState())->setValues($form_state->getValue('variant_settings', []))); + $configuration = $plugin->getConfiguration(); + $cached_values['plugin']->setConfiguration($configuration); + } } diff --git a/src/Plugin/Field/FieldWidget/PanelizerWidget.php b/src/Plugin/Field/FieldWidget/PanelizerWidget.php index 6a3601f..31b8247 100644 --- a/src/Plugin/Field/FieldWidget/PanelizerWidget.php +++ b/src/Plugin/Field/FieldWidget/PanelizerWidget.php @@ -114,9 +114,11 @@ class PanelizerWidget extends WidgetBase { $panelizer_plugin = $this->getPanelizerManager()->createInstance($entity_type_id, []); // If any view modes are missing, then set the default. + $displays = []; foreach ($entity_view_modes as $view_mode => $view_mode_info) { if (!isset($values[$view_mode])) { $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); + $displays[$view_mode] = $display->getThirdPartySetting('panelizer', 'displays', []); if ($display->getThirdPartySetting('panelizer', 'enable', FALSE)) { $panels_display = $panelizer_plugin->getDefaultDisplay($display, $entity->bundle(), $view_mode); @@ -136,12 +138,17 @@ class PanelizerWidget extends WidgetBase { '#value' => $view_mode, ]; - if (!empty($this->getSetting('allow_panel_choice'))) { + //if (!empty($this->getSetting('allow_panel_choice'))) { + if (TRUE) { + $options = []; + foreach ($displays[$view_mode] as $machine_name => $panels_display) { + $options[$machine_name] = $panels_display['label']; + } $element[$delta]['default'] = [ '#type' => 'select', // @todo: list the view mode in the title // @todo: get the list of defaults - '#options' => [], + '#options' => $options, '#default_value' => $value['default'], ]; } diff --git a/src/Wizard/PanelizerAddWizard.php b/src/Wizard/PanelizerAddWizard.php index 658b3bd..500ca18 100644 --- a/src/Wizard/PanelizerAddWizard.php +++ b/src/Wizard/PanelizerAddWizard.php @@ -32,4 +32,34 @@ class PanelizerAddWizard extends PanelizerWizardBase { return $form; } + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + if (in_array((string)$form_state->getValue('op'), [(string)$this->getNextOp(), (string)$this->t('Update'), (string)$this->t('Update and save'), (string)$this->t('Save')])) { + $cached_values = $form_state->getTemporaryValue('wizard'); + if ($form_state->hasValue('label')) { + $config = $cached_values['plugin']->getConfiguration(); + $config['label'] = $form_state->getValue('label'); + $cached_values['plugin']->setConfiguration($config); + } + if ($form_state->hasValue('id')) { + $cached_values['id'] = $form_state->getValue('id'); + /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */ + $plugin = $cached_values['plugin']; + $plugin->setStorage($plugin->getStorageType(), $cached_values['id']); + } + } + parent::submitForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function finish(array &$form, FormStateInterface $form_state) { + parent::finish($form, $form_state); + $cached_values = $form_state->getTemporaryValue('wizard'); + $form_state->setRedirect('panelizer.wizard.edit', ['machine_name' => $cached_values['id'], 'step' => 'content']); + } + } diff --git a/src/Wizard/PanelizerWizardBase.php b/src/Wizard/PanelizerWizardBase.php index e31c06c..a5148df 100644 --- a/src/Wizard/PanelizerWizardBase.php +++ b/src/Wizard/PanelizerWizardBase.php @@ -100,9 +100,11 @@ abstract class PanelizerWizardBase extends FormWizardBase { public function initValues() { $cached_values = parent::initValues(); if (empty($cached_values['plugin'])) { + /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */ $plugin = \Drupal::service('plugin.manager.display_variant')->createInstance('panels_variant'); $plugin->setPattern('panelizer'); $plugin->setBuilder('ipe'); + $plugin->setStorage('panelizer_default', 'TEMPORARY_STORAGE_ID'); $cached_values['plugin'] = $plugin; } if (empty($cached_values['contexts'])) {