Skip to content

Conversation

vtsykun
Copy link
Contributor

@vtsykun vtsykun commented Oct 7, 2019

This PR allow to use layout builder twice to render any layout block inside the call of $layoutManager->getLayout() during rendering the main website page.

Use case
I want to create new CMS widget for landing page to allow user in UI reuse any layouts blocks on a landing page. For example, I'd created the CMS widget layout_block_render to display featured_categories block

Actual result
I got an error. It is happens, because the service ThemeExtension is caches the layout context. So the cached context is shared on the different layout builder instances

BlockViewNotFoundException: BlockView with id "featured_categories" is not found.

STR
Create the simple CMS widget to render layout

Selection_999(514)

<?php

class LayoutBlockRenderWidget implements WidgetInterface
{
    /**
     * @var LayoutManager
     */
    private $layoutManager;

    /**
     * @param LayoutManager $layoutManager
     */
    public function __construct(LayoutManager $layoutManager)
    {
        $this->layoutManager = $layoutManager;
    }

    /**
     * {@inheritdoc}
     */
    public function render(array $options = [])
    {
        $layoutContext = new LayoutContext();
        $layoutContext->set('route_name', 'oro_frontend_root');
//        $layoutContext->set('theme', 'default');

        $layoutBuilder = $this->layoutManager->getLayoutBuilder();
        $layoutBuilder->add('root', null, 'root');

        $layout = $layoutBuilder->getLayout($layoutContext, 'featured_categories');
        $html = $layout->render();

        return $html;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants