You are here

public function ComponentPluginTranslate::onBuildRender in Layout Builder Symmetric Translations 8

Translates the plugin configuration if needed.

Parameters

\Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event: The section component render event.

File

src/EventSubscriber/ComponentPluginTranslate.php, line 67

Class

ComponentPluginTranslate
Translates the plugin configuration if needed.

Namespace

Drupal\layout_builder_st\EventSubscriber

Code

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);
    }
  }
}