Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use layout builder inside the call of layoutManager getLayout #957

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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