diff -u b/page_manager_ui/src/Form/PageVariantConfigureForm.php b/page_manager_ui/src/Form/PageVariantConfigureForm.php --- b/page_manager_ui/src/Form/PageVariantConfigureForm.php +++ b/page_manager_ui/src/Form/PageVariantConfigureForm.php @@ -42,7 +42,6 @@ ]; $variant_plugin = $page_variant->getVariantPlugin(); - // @todo $form['variant_settings'] = $variant_plugin->buildConfigurationForm([], (new FormState())->setValues($form_state->getValue('variant_settings', []) + ['page_variant' => $page_variant])); $form['variant_settings']['#tree'] = TRUE; reverted: --- b/src/Annotation/LayoutBuilderStorage.php +++ /dev/null @@ -1,17 +0,0 @@ - &$record) { + foreach ($records as &$record) { if (!empty($record['variant_settings']['sections'])) { $sections = &$record['variant_settings']['sections']; $sections = array_map([Section::class, 'fromArray'], $sections); diff -u b/src/Form/LayoutBuilderForm.php b/src/Form/LayoutBuilderForm.php --- b/src/Form/LayoutBuilderForm.php +++ b/src/Form/LayoutBuilderForm.php @@ -45,7 +45,8 @@ * * @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository * The layout tempstore repository. - * @param \Drupal\Core\Entity\EntityType $entity_type + * @param \Drupal\layout_builder\SectionStorage\SectionStorageManager $section_storage_manager + * The section storage manager. */ public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, SectionStorageManager $section_storage_manager) { $this->layoutTempstoreRepository = $layout_tempstore_repository; @@ -76,7 +77,7 @@ $page_variant = $form_state->getTemporaryValue('wizard')['page_variant']; $section_storage = $this->sectionStorageManager->load('page_manager', [ - 'page_variant' => EntityContext::fromEntity($page_variant), + 'entity' => EntityContext::fromEntity($page_variant), ]); $section_storage = $this->layoutTempstoreRepository->get($section_storage); @@ -99,7 +100,7 @@ // from the form temporary values. Let's update that with the new values. $cached_values = $form_state->getTemporaryValue('wizard'); // Override with the updated variant. - $cached_values['page']->addVariant($this->sectionStorage->getContextValue('page_variant')); + $cached_values['page']->addVariant($this->sectionStorage->getContextValue('entity')); $form_state->setTemporaryValue('wizard', $cached_values); $this->layoutTempstoreRepository->delete($this->sectionStorage); diff -u b/src/Plugin/DisplayVariant/LayoutBuilderDisplayVariant.php b/src/Plugin/DisplayVariant/LayoutBuilderDisplayVariant.php --- b/src/Plugin/DisplayVariant/LayoutBuilderDisplayVariant.php +++ b/src/Plugin/DisplayVariant/LayoutBuilderDisplayVariant.php @@ -5,6 +5,7 @@ use Drupal\Core\Display\VariantBase; use Drupal\Core\Form\FormStateInterface; use Drupal\ctools\Plugin\PluginWizardInterface; +use Drupal\layout_builder\LayoutEntityHelperTrait; use Drupal\layout_builder\SectionStorage\SectionStorageTrait; use Drupal\page_manager\Form\LayoutBuilderForm; @@ -19,6 +20,7 @@ class LayoutBuilderDisplayVariant extends VariantBase implements PluginWizardInterface { use SectionStorageTrait; + use LayoutEntityHelperTrait; /** * {@inheritdoc} @@ -31,6 +33,9 @@ return $build; } + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { return $form; } @@ -79,2 +84,3 @@ } + } diff -u b/src/Plugin/LayoutBuilderStorage/PageManagerLayoutBuilderStorage.php b/src/Plugin/LayoutBuilderStorage/PageManagerLayoutBuilderStorage.php --- b/src/Plugin/LayoutBuilderStorage/PageManagerLayoutBuilderStorage.php +++ b/src/Plugin/LayoutBuilderStorage/PageManagerLayoutBuilderStorage.php @@ -7,10 +7,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Session\AccountInterface; -use Drupal\layout_builder\Element\LayoutBuilder; use Drupal\page_manager\Plugin\DisplayVariant\LayoutBuilderDisplayVariant; -use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant; -use Drupal\panels\Storage\PanelsStorageBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -61,6 +58,8 @@ * The page variant entity's id. * * @return \Drupal\page_manager\PageVariantInterface + * + * @throws \Exception */ protected function loadPageVariant($id) { return $this->entityTypeManager->getStorage('page_variant')->load($id); reverted: --- b/src/Plugin/SectionStorage/PageManager.php +++ /dev/null @@ -1,189 +0,0 @@ -entityTypeManager = $entity_type_manager; - $this->sampleEntityGenerator = $sample_entity_generator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity_type.manager'), - $container->get('layout_builder.sample_entity_generator') - ); - } - - /** - * {@inheritdoc} - */ - protected function getSectionList() { - return $this->getContextValue('page_variant')->getVariantPlugin(); - } - - /** - * Gets the page variant entity. - * - * @return \Drupal\page_manager\Entity\PageVariant - * The page variant entity. - * - * @throws \Drupal\Component\Plugin\Exception\PluginException - */ - protected function getPageVariant() { - return $this->getContextValue('page_variant'); - } - - /** - * {@inheritdoc} - */ - public function getStorageId() { - return $this->getContextValue('page_variant')->id(); - } - - /** - * {@inheritdoc} - */ - public function getRedirectUrl() { - // @todo - return Url::fromRoute(''); - } - - /** - * {@inheritdoc} - */ - public function getLayoutBuilderUrl($rel = 'view') { - return Url::fromRoute("layout_builder.page_manager.view", ['page_variant' => $this->getPageVariant()->id()]); - } - - /** - * {@inheritdoc} - */ - public function buildRoutes(RouteCollection $collection) { - // @todo - $path = '/admin/structure/page_manager/{page_variant}/layout'; - - $options['parameters']['page_variant']['type'] = 'entity:page_variant'; - - $options['_admin_route'] = FALSE; - - $this->buildLayoutRoutes($collection, $this->getPluginDefinition(), $path, [], [], $options, '', 'page_variant'); - } - - /** - * {@inheritdoc} - */ - public function deriveContextsFromRoute($value, $definition, $name, array $defaults) { - $contexts = []; - - if ($entity = $this->extractEntityFromRoute($value, $defaults)) { - $contexts['page_variant'] = EntityContext::fromEntity($entity); - } - return $contexts; - } - - /** - * {@inheritdoc} - */ - private function extractEntityFromRoute($value, array $defaults) { - // @todo - if (!empty($value)) { - return PageVariant::load($value); - } - return PageVariant::load($defaults['page_variant']); - } - - /** - * {@inheritdoc} - */ - public function label() { - return $this->getPageVariant()->label(); - } - - /** - * {@inheritdoc} - */ - public function save() { - $page_variant = $this->getPageVariant(); - return $page_variant->save(); - } - - /** - * {@inheritdoc} - */ - public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) { - // @todo - return AccessResult::allowed(); - } - - /** - * {@inheritdoc} - */ - public function isApplicable(RefinableCacheableDependencyInterface $cacheability) { - // @todo - return TRUE; - } - - /** - * {@inheritdoc} - */ - public function getSectionListFromId($id) { - // @todo - } - - /** - * {@inheritdoc} - */ - public function extractIdFromRoute($value, $definition, $name, array $defaults) { - // @todo - } -} only in patch2: unchanged: --- a/page_manager.info.yml +++ b/page_manager.info.yml @@ -6,4 +6,5 @@ core: 8.x dependencies: - drupal:system (>=8.5) - drupal:block + - drupal:layout_builder - ctools:ctools only in patch2: unchanged: --- /dev/null +++ b/src/Plugin/SectionStorage/PageManagerSectionStorage.php @@ -0,0 +1,201 @@ +entityTypeManager = $entity_type_manager; + $this->sampleEntityGenerator = $sample_entity_generator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager'), + $container->get('layout_builder.sample_entity_generator') + ); + } + + /** + * {@inheritdoc} + */ + protected function getSectionList() { + return $this->getContextValue('entity')->getVariantPlugin(); + } + + /** + * Gets the page variant entity. + * + * @return \Drupal\page_manager\Entity\PageVariant + * The page variant entity. + * + * @throws \Drupal\Component\Plugin\Exception\PluginException + */ + protected function getPageVariant() { + return $this->getContextValue('entity'); + } + + /** + * {@inheritdoc} + */ + public function getStorageId() { + return $this->getContextValue('entity')->id(); + } + + /** + * {@inheritdoc} + */ + public function getRedirectUrl() { + return Url::fromUri($this->getPageVariant()->getPage()->getPath()); + } + + /** + * {@inheritdoc} + */ + public function getLayoutBuilderUrl($rel = 'view') { + return Url::fromRoute("layout_builder.page_manager.view", ['page_variant' => $this->getPageVariant()->id()]); + } + + /** + * {@inheritdoc} + */ + public function buildRoutes(RouteCollection $collection) { + // @todo + $path = '/admin/structure/page_manager/{page_variant}/layout'; + + $options['parameters']['page_variant']['type'] = 'entity:page_variant'; + + $options['_admin_route'] = FALSE; + + $this->buildLayoutRoutes($collection, $this->getPluginDefinition(), $path, [], [], $options, '', 'page_variant'); + } + + /** + * {@inheritdoc} + */ + public function deriveContextsFromRoute($value, $definition, $name, array $defaults) { + $contexts = []; + + if ($entity = $this->extractEntityFromRoute($value, $defaults)) { + $contexts['entity'] = EntityContext::fromEntity($entity); + } + return $contexts; + } + + /** + * {@inheritdoc} + */ + private function extractEntityFromRoute($value, array $defaults) { + // @todo + if (!empty($value)) { + return PageVariant::load($value); + } + return PageVariant::load($defaults['page_variant']); + } + + /** + * {@inheritdoc} + */ + public function label() { + return $this->getPageVariant()->label(); + } + + /** + * {@inheritdoc} + */ + public function save() { + $page_variant = $this->getPageVariant(); + return $page_variant->save(); + } + + /** + * {@inheritdoc} + */ + public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) { + $result = AccessResult::allowedIf($this->isLayoutBuilderEnabled())->addCacheableDependency($this); + return $return_as_object ? $result : $result->isAllowed(); + } + + /** + * {@inheritdoc} + */ + public function isApplicable(RefinableCacheableDependencyInterface $cacheability) { + return $this->isLayoutBuilderEnabled(); + } + + /** + * {@inheritdoc} + */ + public function getSectionListFromId($id) { + // @todo + } + + /** + * {@inheritdoc} + */ + public function extractIdFromRoute($value, $definition, $name, array $defaults) { + // @todo + } + + /** + * Determines if Layout Builder is enabled. + * + * @return bool + * TRUE if Layout Builder is enabled, FALSE otherwise. + * + * @throws \Drupal\Component\Plugin\Exception\PluginException + */ + public function isLayoutBuilderEnabled() { + return $this->getContextValue('entity')->getVariantPlugin() instanceof LayoutBuilderDisplayVariant; + } + +}