Using Layout Builder, when you add a block to a layout that has access controls and a user visits a page without access, the layout is empty.
How does one prevent the layout from rendering at all if its contents are empty? While the {% if content.foo|render|striptags|trim %}
trick works for block templates, I can't figure out how to get the same effect with layout templates.
The end result is I have extra markup in the page, which is classed and creating extra padding and vertical space between populated layout regions.
edit:
I have updated now with an event that Layout Builder needs:
class MyModuleEventSubscriber implements EventSubscriberInterface {
/**
* Layout Builder response event handler.
*
* @param SectionComponentBuildRenderArrayEvent $event
* Build render event.
*/
public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
$id = $event->getPlugin()->getPluginDefinition()['id'];
if ($id == 'inline_block' && !$event->inPreview()) {
$build = $event->getBuild();
$build['#create_placeholder'] = FALSE;
$event->setBuild($build);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = ['onBuildRender', 110];
return $events;
}
}