Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Layout/LayoutPluginManager.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
10 use Drupal\Core\Plugin\DefaultPluginManager; | 10 use Drupal\Core\Plugin\DefaultPluginManager; |
11 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; | 11 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; |
12 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; | 12 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; |
13 use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator; | 13 use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator; |
14 use Drupal\Core\Layout\Annotation\Layout; | 14 use Drupal\Core\Layout\Annotation\Layout; |
15 use Drupal\Core\Plugin\FilteredPluginManagerTrait; | |
16 use Drupal\Core\StringTranslation\TranslatableMarkup; | |
15 | 17 |
16 /** | 18 /** |
17 * Provides a plugin manager for layouts. | 19 * Provides a plugin manager for layouts. |
18 */ | 20 */ |
19 class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginManagerInterface { | 21 class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginManagerInterface { |
22 | |
23 use FilteredPluginManagerTrait; | |
20 | 24 |
21 /** | 25 /** |
22 * The theme handler. | 26 * The theme handler. |
23 * | 27 * |
24 * @var \Drupal\Core\Extension\ThemeHandlerInterface | 28 * @var \Drupal\Core\Extension\ThemeHandlerInterface |
40 */ | 44 */ |
41 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { | 45 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { |
42 parent::__construct('Plugin/Layout', $namespaces, $module_handler, LayoutInterface::class, Layout::class); | 46 parent::__construct('Plugin/Layout', $namespaces, $module_handler, LayoutInterface::class, Layout::class); |
43 $this->themeHandler = $theme_handler; | 47 $this->themeHandler = $theme_handler; |
44 | 48 |
45 $this->setCacheBackend($cache_backend, 'layout'); | 49 $type = $this->getType(); |
46 $this->alterInfo('layout'); | 50 $this->setCacheBackend($cache_backend, $type); |
51 $this->alterInfo($type); | |
52 } | |
53 | |
54 /** | |
55 * {@inheritdoc} | |
56 */ | |
57 protected function getType() { | |
58 return 'layout'; | |
47 } | 59 } |
48 | 60 |
49 /** | 61 /** |
50 * {@inheritdoc} | 62 * {@inheritdoc} |
51 */ | 63 */ |
58 */ | 70 */ |
59 protected function getDiscovery() { | 71 protected function getDiscovery() { |
60 if (!$this->discovery) { | 72 if (!$this->discovery) { |
61 $discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces); | 73 $discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces); |
62 $discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories()); | 74 $discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories()); |
75 $discovery | |
76 ->addTranslatableProperty('label') | |
77 ->addTranslatableProperty('description') | |
78 ->addTranslatableProperty('category'); | |
63 $discovery = new AnnotationBridgeDecorator($discovery, $this->pluginDefinitionAnnotationName); | 79 $discovery = new AnnotationBridgeDecorator($discovery, $this->pluginDefinitionAnnotationName); |
64 $discovery = new ContainerDerivativeDiscoveryDecorator($discovery); | 80 $discovery = new ContainerDerivativeDiscoveryDecorator($discovery); |
65 $this->discovery = $discovery; | 81 $this->discovery = $discovery; |
66 } | 82 } |
67 return $this->discovery; | 83 return $this->discovery; |
127 } | 143 } |
128 | 144 |
129 if (!$definition->getDefaultRegion()) { | 145 if (!$definition->getDefaultRegion()) { |
130 $definition->setDefaultRegion(key($definition->getRegions())); | 146 $definition->setDefaultRegion(key($definition->getRegions())); |
131 } | 147 } |
148 // Makes sure region names are translatable. | |
149 $regions = array_map(function ($region) { | |
150 if (!$region['label'] instanceof TranslatableMarkup) { | |
151 // Region labels from YAML discovery needs translation. | |
152 $region['label'] = new TranslatableMarkup($region['label'], [], ['context' => 'layout_region']); | |
153 } | |
154 return $region; | |
155 }, $definition->getRegions()); | |
156 $definition->setRegions($regions); | |
132 } | 157 } |
133 | 158 |
134 /** | 159 /** |
135 * {@inheritdoc} | 160 * {@inheritdoc} |
136 */ | 161 */ |