Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Layout / LayoutPluginManager.php
index a5a465293775b4b75c7d84899d44bcba1f28eb3a..2cd0c689573591a414b4732cc3be1bfc0412c6df 100644 (file)
@@ -13,6 +13,7 @@ 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.
@@ -71,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;
@@ -140,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);
   }
 
   /**