diff --git a/core/modules/layout/layout.module b/core/modules/layout/layout.module index 7b0ab2c..ecb325f 100644 --- a/core/modules/layout/layout.module +++ b/core/modules/layout/layout.module @@ -37,3 +37,24 @@ function layout_page_build(&$page) { function layout_manager() { return drupal_container()->get('plugin.manager.layout'); } + +/** + * Implements hook_theme(). + * + * Expose all layouts as theme items, so themes can override layout markup. + */ +function layout_theme($existing, $type, $theme, $path) { + $items = array(); + foreach (layout_manager()->getDefinitions() as $name => $layout) { + $regions = array(); + foreach (array_keys($layout['regions']) as $key) { + $regions[$key] = ''; + } + $items[$layout['theme']] = array( + 'variables' => $regions, + 'path' => $layout['path'], + 'template' => $layout['template'], + ); + } + return $items; +} diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php index ef603c3..7ee90bf 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php @@ -100,8 +100,10 @@ protected function iterateDirectories($dir, $provider) { // layout subdirectory. This provides all information about the layout // such as layout markup template and CSS and JavaScript files to use. $directory = new FileStorage($fileinfo->getPath()); - $this->derivatives[$provider['provider'] . '__' . $fileinfo->getBasename('.yml')] = $directory->read($fileinfo->getBasename('.yml')); - $this->derivatives[$provider['provider'] . '__' . $fileinfo->getBasename('.yml')]['path'] = $fileinfo->getPath(); + $key = $provider['provider'] . '__' . $fileinfo->getBasename('.yml'); + $this->derivatives[$key] = $directory->read($fileinfo->getBasename('.yml')); + $this->derivatives[$key]['theme'] = $key; + $this->derivatives[$key]['path'] = $fileinfo->getPath(); } } } diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php b/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php index 601e343..0f46e66 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php @@ -45,52 +45,47 @@ public function getRegions() { /** * Add the CSS files associated with this layout to the page. */ - public function addCss() { + public function getCssFiles() { $definition = $this->getDefinition(); $files = $definition['css']; if (is_string($files)) { $files = array($files); } - foreach ($files as $filename) { - drupal_add_css($definition['path'] . '/' . $filename); - } + return $files; } /** * Add the administrative CSS files associated with this layout to the page. */ - public function addAdminCss() { + public function getAdminCssFiles() { $definition = $this->getDefinition(); // Fall back on regular CSS for the admin page if admin CSS not provided. $files = isset($definition['admin css']) ? $definition['admin css'] : $definition['css']; if (is_string($files)) { $files = array($files); } - foreach ($files as $filename) { - drupal_add_css($definition['path'] . '/' . $filename); - } + return $files; } /** * Add the JS files associated with this layout to the page. */ - public function addJs() { + public function getJsFiles() { $definition = $this->getDefinition(); if (isset($definition['js'])) { $files = $definition['js']; if (is_string($files)) { $files = array($files); } - foreach ($files as $filename) { - drupal_add_js($definition['path'] . '/' . $filename); - } + return $files; } + return array(); } /** * Add the admin JS files associated with this layout to the page. */ - public function addAdminJs() { + public function getAdminJsFiles() { $definition = $this->getDefinition(); $files = array(); if (isset($definition['admin js'])) { @@ -103,9 +98,7 @@ public function addAdminJs() { if (is_string($files)) { $files = array($files); } - foreach ($files as $filename) { - drupal_add_js($definition['path'] . '/' . $filename); - } + return $files; } /** @@ -114,27 +107,40 @@ public function addAdminJs() { public function renderLayout($admin = FALSE) { $definition = $this->getDefinition(); + // Assemble a render array with the regions and attached CSS/JS. + $render = array( + '#theme' => $definition['theme'], + ); + // Render all regions needed for this layout. - $regions = array(); foreach ($this->getRegions() as $region => $title) { // @todo This is just stub code to fill in regions with stuff for now. // When blocks are related to layouts and not themes, we can make this // really be filled in with blocks. - $regions[$region] = '