Issue #3294833 by claudiu.cristea, alexpott: Page variant plugin is not correctlly instantiated

merge-requests/2817/merge
Alex Pott 2022-10-03 14:22:33 +01:00
parent 6402539128
commit c0bee1ddda
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 5 additions and 3 deletions

View File

@ -219,6 +219,7 @@ class HtmlRenderer implements MainContentRendererInterface {
$event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
$this->eventDispatcher->dispatch($event, RenderEvents::SELECT_PAGE_DISPLAY_VARIANT);
$variant_id = $event->getPluginId();
$variant_configuration = $event->getPluginConfiguration();
// We must render the main content now already, because it might provide a
// title. We set its $is_root_call parameter to FALSE, to ensure
@ -244,15 +245,14 @@ class HtmlRenderer implements MainContentRendererInterface {
$title = $get_title($main_content);
// Instantiate the page display, and give it the main content.
$page_display = $this->displayVariantManager->createInstance($variant_id);
$page_display = $this->displayVariantManager->createInstance($variant_id, $variant_configuration);
if (!$page_display instanceof PageVariantInterface) {
throw new \LogicException('Cannot render the main content for this page because the provided display variant does not implement PageVariantInterface.');
}
$page_display
->setMainContent($main_content)
->setTitle($title)
->addCacheableDependency($event)
->setConfiguration($event->getPluginConfiguration());
->addCacheableDependency($event);
// Some display variants need to be passed an array of contexts with
// values because they can't get all their contexts globally. For example,
// in Page Manager, you can create a Page which has a specific static

View File

@ -67,6 +67,7 @@ class TestDisplayVariant extends VariantBase implements PageVariantInterface, Co
* {@inheritdoc}
*/
public function setMainContent(array $main_content) {
assert(!empty($this->getConfiguration()['required_configuration']), 'Ensure that ::setMainContent() is called with the variant configuration');
$this->mainContent = $main_content;
return $this;
}
@ -75,6 +76,7 @@ class TestDisplayVariant extends VariantBase implements PageVariantInterface, Co
* {@inheritdoc}
*/
public function setTitle($title) {
assert(!empty($this->getConfiguration()['required_configuration']), 'Ensure that ::setTitle() is called with the variant configuration');
$this->title = $title;
return $this;
}