final class ComponentPluginTranslate in Layout Builder Symmetric Translations 8
Translates the plugin configuration if needed.
@internal Tagged services are internal.
Hierarchy
- class \Drupal\layout_builder_st\EventSubscriber\ComponentPluginTranslate implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses LayoutEntityHelperTrait, TranslationsHelperTrait
Expanded class hierarchy of ComponentPluginTranslate
1 string reference to 'ComponentPluginTranslate'
1 service uses ComponentPluginTranslate
File
- src/
EventSubscriber/ ComponentPluginTranslate.php, line 20
Namespace
Drupal\layout_builder_st\EventSubscriberView source
final class ComponentPluginTranslate implements EventSubscriberInterface {
use LayoutEntityHelperTrait;
// This trait will be merged into core's.
use TranslationsHelperTrait;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The current route match.
*
* @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
* The current route match.
*/
public function __construct(LanguageManagerInterface $language_manager, RouteMatchInterface $route_match) {
$this->languageManager = $language_manager;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = [
'onBuildRender',
200,
];
return $events;
}
/**
* 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);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ComponentPluginTranslate:: |
protected | property | The language manager. | |
ComponentPluginTranslate:: |
protected | property | The current route match. | |
ComponentPluginTranslate:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ComponentPluginTranslate:: |
public | function | Translates the plugin configuration if needed. | |
ComponentPluginTranslate:: |
public | function | Creates a ComponentPluginTranslate object. | |
LayoutEntityHelperTrait:: |
protected | property | The section storage manager. | 1 |
LayoutEntityHelperTrait:: |
protected | function | Gets the sections for an entity if any. | |
LayoutEntityHelperTrait:: |
protected | function | Gets components that have Inline Block plugins. | |
LayoutEntityHelperTrait:: |
protected | function | Gets revision IDs for layout sections. | |
LayoutEntityHelperTrait:: |
protected | function | Gets the section storage for an entity. | |
LayoutEntityHelperTrait:: |
protected | function | Determines if an entity is using a field for the layout override. | |
LayoutEntityHelperTrait:: |
protected | function | Determines if an entity can have a layout. | |
LayoutEntityHelperTrait:: |
protected | function | Determines if the original entity used the default section storage. | |
LayoutEntityHelperTrait:: |
private | function | Gets the section storage manager. | 1 |
TranslationsHelperTrait:: |
protected static | function | Determines if the sections is for a translation. |