- 🇩🇪Germany tomsaw Essen
I also had errors using layout_builder_st with ui_patterns 2.0.x → due to empty
$contexts['layout_builder.entity']
.
#4 fixed it.
Using page_manager with #2960739: Create a layout builder variant → led us into some edge case situations which should perhaps be handled more defensive in onBuildRender(). Just wanted to let you know to decide how to handle these cases:
Current function looks like this:
Drupal\layout_builder_st\EventSubscriber\ComponentPluginTranslate->onBuildRender():
/**
* Translates the plugin configuration if needed.
*
* @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
* The section component render event.
*/
public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
if (!$this->languageManager->isMultilingual()) {
return;
}
$plugin = $event->getPlugin();
$contexts = $event->getContexts();
$component = $event->getComponent();
if (!$plugin instanceof ConfigurableInterface && !isset($contexts['layout_builder.entity'])) {
return;
}
// @todo Change to 'entity' in https://www.drupal.org/node/3018782.
$entity = $contexts['layout_builder.entity']->getContextValue();
$configuration = $plugin->getConfiguration();
if ($event->inPreview()) {
$section_storage = $this->routeMatch->getParameter('section_storage');
}
else {
$section_storage = $this->getSectionStorageForEntity($entity);
}
if (static::isTranslation($section_storage)) {
if ($translated_plugin_configuration = $section_storage->getTranslatedComponentConfiguration($component->getUuid())) {
$translated_plugin_configuration += $configuration;
$plugin->setConfiguration($translated_plugin_configuration);
}
}
}
1. In a situation with a broken block (missing view) the variable
$plugin
was instanceof Drupal\Core\Block\Plugin\Block\Broken which resulted in a PHP error.
2. $contexts['layout_builder.entity'] is NULL in layout_builder which leads to null pointer in
$entity = $contexts['layout_builder.entity']->getContextValue();
I have no deeper understanding of the code in this area so I hope my bug report is helpful for this module and / or the core patch.
Thank you very much again.
Needs work
1.0
Code
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
I also had errors using layout_builder_st with
ui_patterns 2.0.x →
due to empty $contexts['layout_builder.entity']
.
#4 fixed it.