use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator;
use Drupal\Core\Layout\Annotation\Layout;
+use Drupal\Core\Plugin\FilteredPluginManagerTrait;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Provides a plugin manager for layouts.
*/
class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginManagerInterface {
+ use FilteredPluginManagerTrait;
+
/**
* The theme handler.
*
parent::__construct('Plugin/Layout', $namespaces, $module_handler, LayoutInterface::class, Layout::class);
$this->themeHandler = $theme_handler;
- $this->setCacheBackend($cache_backend, 'layout');
- $this->alterInfo('layout');
+ $type = $this->getType();
+ $this->setCacheBackend($cache_backend, $type);
+ $this->alterInfo($type);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getType() {
+ return 'layout';
}
/**
if (!$this->discovery) {
$discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces);
$discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories());
+ $discovery
+ ->addTranslatableProperty('label')
+ ->addTranslatableProperty('description')
+ ->addTranslatableProperty('category');
$discovery = new AnnotationBridgeDecorator($discovery, $this->pluginDefinitionAnnotationName);
$discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
$this->discovery = $discovery;
if (!$definition->getDefaultRegion()) {
$definition->setDefaultRegion(key($definition->getRegions()));
}
+ // Makes sure region names are translatable.
+ $regions = array_map(function ($region) {
+ if (!$region['label'] instanceof TranslatableMarkup) {
+ // Region labels from YAML discovery needs translation.
+ $region['label'] = new TranslatableMarkup($region['label'], [], ['context' => 'layout_region']);
+ }
+ return $region;
+ }, $definition->getRegions());
+ $definition->setRegions($regions);
}
/**