Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Layout / LayoutPluginManager.php
index 179d1ede9ab7392aaaae32c3d08a7875131d3f4b..2cd0c689573591a414b4732cc3be1bfc0412c6df 100644 (file)
@@ -12,12 +12,16 @@ use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
 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.
    *
@@ -42,8 +46,16 @@ class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginMa
     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';
   }
 
   /**
@@ -60,6 +72,10 @@ class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginMa
     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;
@@ -129,6 +145,15 @@ class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginMa
     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);
   }
 
   /**