diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php index 0dcb14c..3092233 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php @@ -29,6 +29,9 @@ class LayoutManager extends PluginManagerBase { * An array of paths keyed by it's corresponding namespaces. */ public function __construct($namespaces) { + // Allow themes to provide plugins. + $namespaces += $this->getThemeNamespaces(); + // Create layout plugin derivatives from declaratively defined layouts. $this->discovery = new AnnotatedClassDiscovery('layout', 'layout', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); @@ -36,4 +39,28 @@ public function __construct($namespaces) { $this->factory = new ReflectionFactory($this->discovery); } + + /** + * Returns namespaces for themes to be used for the annotated class discovery. + * + * @todo: Move into the base class? + * + * @return array + * Array of namespaces keyed by the directory. + */ + protected function getThemeNamespaces() { + global $theme, $base_theme_info; + $namespaces = array(); + if (isset($theme)) { + $theme_keys = array(); + foreach ($base_theme_info as $base) { + $theme_keys[] = $base->name; + } + $theme_keys[] = $theme; + foreach ($theme_keys as $theme_key) { + $namespaces[drupal_get_path('theme', $theme_key) . '/lib'] = 'Drupal\\' . $theme_key; + } + } + return $namespaces; + } }