diff --git a/core/modules/layout_builder/layout_builder.services.yml b/core/modules/layout_builder/layout_builder.services.yml index 7c776ab31b..72ae100fb8 100644 --- a/core/modules/layout_builder/layout_builder.services.yml +++ b/core/modules/layout_builder/layout_builder.services.yml @@ -51,7 +51,7 @@ services: - { name: event_subscriber } layout_builder.translate_block_component_subscriber: class: Drupal\layout_builder\EventSubscriber\ComponentPluginTranslate - arguments: ['@language_manager'] + arguments: ['@language_manager', '@current_route_match'] tags: - { name: event_subscriber } logger.channel.layout_builder: diff --git a/core/modules/layout_builder/src/EventSubscriber/ComponentPluginTranslate.php b/core/modules/layout_builder/src/EventSubscriber/ComponentPluginTranslate.php index 6bda46501a..6ac6d74eb0 100644 --- a/core/modules/layout_builder/src/EventSubscriber/ComponentPluginTranslate.php +++ b/core/modules/layout_builder/src/EventSubscriber/ComponentPluginTranslate.php @@ -4,6 +4,7 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Routing\RouteMatchInterface; use Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent; use Drupal\layout_builder\LayoutBuilderEvents; use Drupal\layout_builder\LayoutEntityHelperTrait; @@ -27,14 +28,21 @@ class ComponentPluginTranslate implements EventSubscriberInterface { */ protected $languageManager; + /** + * @var \Drupal\Core\Routing\RouteMatchInterface + */ + protected $routeMatch; + /** * Creates a ComponentPluginTranslate object. * * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match */ - public function __construct(LanguageManagerInterface $language_manager) { + public function __construct(LanguageManagerInterface $language_manager, RouteMatchInterface $route_match) { $this->languageManager = $language_manager; + $this->routeMatch = $route_match; } /** @@ -64,7 +72,13 @@ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) { $entity = $contexts['layout_builder.entity']->getContextValue(); $configuration = $plugin->getConfiguration(); - $section_storage = $this->getSectionStorageForEntity($entity); + if ($event->inPreview()) { + $section_storage = $this->routeMatch->getParameter('section_storage'); + } + else { + $section_storage = $this->getSectionStorageForEntity($entity); + } + if ($section_storage instanceof TranslatableSectionStorageInterface && !$section_storage->isDefaultTranslation()) { if ($translated_plugin_configuration = $section_storage->getTranslatedComponentConfiguration($component->getUuid())) { $translated_plugin_configuration += $configuration;