diff --git a/panels.module b/panels.module index d56d8d9..5a09a5f 100644 --- a/panels.module +++ b/panels.module @@ -35,6 +35,8 @@ function panels_api_version() { * We need to set the storage information on Panels displays being storaged * in Page Manager as early as possible, to signal to Panels that features * requiring Panels storage (like the IPE) are supported. + * + * @see panels_page_variant_presave() */ function panels_page_variant_create(PageVariantInterface $page_variant) { if ($page_variant->getVariantPluginId() == 'panels_variant') { @@ -48,28 +50,23 @@ function panels_page_variant_create(PageVariantInterface $page_variant) { } /** - * Implements hook_form_FORM_ID_alter(). - */ -function panels_form_page_variant_add_form_alter(&$form, FormStateInterface $form_state) { - // We set a validation callback because it'll run before the forms built-in - // ::submitForm() method, which we need to make sure our changes get saved. - $form['actions']['submit']['#validate'][] = 'panels_page_variant_add_form_validate'; -} - -/** - * Form validation callback for page_variant_add_form(). + * Implements hook_ENTITY_TYPE_presave(). + * + * Now that we have the id for the page variant, we need to set the storage + * information again. + * + * @see panels_page_variant_create() */ -function panels_page_variant_add_form_validate($form, FormStateInterface $form_state) { - /** @var \Drupal\Core\Entity\EntityForm $form_obj */ - $form_obj = $form_state->getFormObject(); - /** @var \Drupal\page_manager\PageVariantInterface $page_variant */ - $page_variant = $form_obj->getEntity(); - +function panels_page_variant_presave(PageVariantInterface $page_variant) { if ($page_variant->getVariantPluginId() == 'panels_variant') { /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */ $panels_display = $page_variant->getVariantPlugin(); // Set the storage info now that we have the id. $panels_display->setStorage('page_manager', $page_variant->id()); + // Since the plugin collection magic has already run and copied the + // configuration from the $panels_display to the $page_variant, we need to + // do it again manually. + $page_variant->set('variant_settings', $panels_display->getConfiguration()); } }