diff --git a/core/lib/Drupal/Core/Booze/DrunkController.php b/core/lib/Drupal/Core/Booze/DrunkController.php index 4bd1cd3..ad07fdf 100644 --- a/core/lib/Drupal/Core/Booze/DrunkController.php +++ b/core/lib/Drupal/Core/Booze/DrunkController.php @@ -112,11 +112,12 @@ public function respond(Request $request, BoundDisplayInterface $_display) { $this->response = new Response(); $this->renderBlocks($request); - $this->renderLayout($request); + $this->renderRegions($request); // @todo handle out-of-band stuff, e.g. css/js - $content = $this->display->getLayoutPluginInstance()->renderLayout($this->renderedRegions); - $this->response->setContent($content); + $content = $this->display->getLayoutInstance()->renderLayout(FALSE, $this->renderedRegions); + + $this->response->setContent($this->wrapHtml($content)); return $this->response; } @@ -165,17 +166,75 @@ protected function renderBlocks(Request $request) { * * @param \Symfony\Component\HttpFoundation\Request $request */ - protected function renderLayout(Request $request) { - $layout = $this->display->getLayoutPluginInstance(); + protected function renderRegions(Request $request) { + $layout = $this->display->getLayoutInstance(); // @todo need to add this method to the layout plugin interface. - // @todo this is another place we could do block placement renegotiation by region role (@see Display) foreach ($layout->getRegions() as $region => $info) { // @todo region styles, if we do them, would go in around here $to_render = array(); - foreach ($this->display->getBlocksByRegion($region) as $block) { + // This sorting call will trigger automatic block remapping if the display + // has had a different layout plugin instance injected than the one + // indicated in storage. + foreach ($this->display->getSortedBlocksByRegion($region) as $block) { $to_render[] = $this->renderedBlocks[$block]; } - $this->renderedRegions[$region] = $layout->renderRegion($region); + /* + * @todo giant fat utter hack to just get it working. + * the responsibility for this in Panels is in styles - we haven't + * implemented those yet, and they create a potentially awkward additional + * separation for frontenders that we may not want to have. + * + * so, needs a little discussion, but it's (sorta) ok to just force this + * to work while we figure it out. + */ + $this->renderedRegions[$region] = implode("\n", $to_render); + } + } + + /** + * Wraps page output in the html template. + * + * @todo This is ENTIRELY a shim until https://drupal.org/node/1871596 gets in. + * + * @param $content + */ + protected function wrapHtml($content) { + $page = element_info('page'); + foreach ($this->moduleHandler->getImplementations('page_build') as $module) { + $function = $module . '_page_build'; + $function($page); + } + $this->moduleHandler->alter('page', $page); + + // ensure the #attached assets get picked up + drupal_process_attached($page); + + $vars = array( + 'page' => array( + '#type' => 'markup', + '#markup' => $content, + '#children' => $content, // @todo some preprocessors demand this be here + 'page_top' => empty($page['page_top']) ? array(): $page['page_top'], + 'page_bottom' => empty($page['page_bottom']) ? array(): $page['page_bottom'], + ), + ); + + // extra-ugly hack for sidebar-number-correctness. ugh, template_preprocess_html. + $layout = $this->display->getLayoutInstance(); + $i = 0; + foreach ($layout->getRegions() as $name => $info) { + if (strpos($name, 'sidebar') === 0) { + $i++; + } } + + if ($i >= 1) { + $vars['page']['sidebar_first'] = TRUE; + } + if ($i >= 2) { + $vars['page']['sidebar_second'] = TRUE; + } + + return theme('html', $vars); } } diff --git a/core/modules/layout/layout.module b/core/modules/layout/layout.module index c6ed7ae..12b0b9f 100644 --- a/core/modules/layout/layout.module +++ b/core/modules/layout/layout.module @@ -76,6 +76,7 @@ function layout_theme($existing, $type, $theme, $path) { 'variables' => array('content' => NULL), 'path' => $layout['path'], 'template' => $layout['template'], + 'base hook' => 'page', ); } return $items; diff --git a/core/modules/layout/lib/Drupal/layout/Config/DisplayBase.php b/core/modules/layout/lib/Drupal/layout/Config/DisplayBase.php index afe3229..02f6f3b 100644 --- a/core/modules/layout/lib/Drupal/layout/Config/DisplayBase.php +++ b/core/modules/layout/lib/Drupal/layout/Config/DisplayBase.php @@ -135,4 +135,15 @@ public function getAllRegionTypes() { } return array_unique($types); } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + * + * @return array + */ + public function getExportProperties() { + $properties = parent::getExportProperties(); + $properties['blockInfo'] = $this->blockInfo; + return $properties; + } } diff --git a/core/modules/layout/lib/Drupal/layout/Config/DisplayStorageController.php b/core/modules/layout/lib/Drupal/layout/Config/DisplayStorageController.php new file mode 100644 index 0000000..f6a9567 --- /dev/null +++ b/core/modules/layout/lib/Drupal/layout/Config/DisplayStorageController.php @@ -0,0 +1,19 @@ +entity->get('_content_closure'); - return call_user_func($callback); + return is_callable($callback) ? call_user_func($callback) : ''; } } diff --git a/core/profiles/standard/config/display.bound.frontend.yml b/core/profiles/standard/config/display.bound.frontend.yml index e1161b4..2c629cf 100644 --- a/core/profiles/standard/config/display.bound.frontend.yml +++ b/core/profiles/standard/config/display.bound.frontend.yml @@ -5,31 +5,31 @@ layoutSettings: { } blockInfo: # these have bartik in their namespace, but that's irrelevant to our use here - # we're just reusing them while we get everything together. - block.block.bartik.help: + bartik.help: region: help region-type: content weight: 0 # should float in unbound/master - block.block.bartik.content: + bartik.content: region: content region-type: content weight: 0 # should float in unbound/master - block.block.bartik.footer: + bartik.footer: region: footer region-type: footer weight: 0 # stick-top in unbound/master - block.block.bartik.powered: + bartik.powered: region: footer region-type: footer weight: 10 # float in unbound/master - block.block.bartik.search: + bartik.search: region: sidebar_first region-type: aside weight: 0 # stick-top in unbound/master - block.block.bartik.login: + bartik.login: region: sidebar_first region-type: aside weight: 10 # stick-top in unbound/master - block.block.bartik.tools: + bartik.tools: region: sidebar_first region-type: aside - weight: 20 # stick-top in unbound/master \ No newline at end of file + weight: 20 # stick-top in unbound/master diff --git a/core/themes/bartik/layouts/static/frontend/frontend.html.twig b/core/themes/bartik/layouts/static/frontend/frontend.html.twig index 195e411..857a1d1 100644 --- a/core/themes/bartik/layouts/static/frontend/frontend.html.twig +++ b/core/themes/bartik/layouts/static/frontend/frontend.html.twig @@ -63,24 +63,24 @@ Page content (in order of occurrence in the default page.tpl.php): comment/reply/12345). Regions: -- page.header: Items for the header region. -- page.featured: Items for the featured region. -- page.highlighted: Items for the highlighted content region. -- page.help: Dynamic help text, mostly for admin pages. -- page.content: The main content of the current page. -- page.sidebar_first: Items for the first sidebar. -- page.sidebar_second: Items for the second sidebar. -- page.triptych_first: Items for the first triptych. -- page.triptych_middle: Items for the middle triptych. -- page.triptych_last: Items for the last triptych. -- page.footer_firstcolumn: Items for the first footer column. -- page.footer_secondcolumn: Items for the second footer column. -- page.footer_thirdcolumn: Items for the third footer column. -- page.footer_fourthcolumn: Items for the fourth footer column. -- page.footer: Items for the footer region. +- content.header: Items for the header region. +- content.featured: Items for the featured region. +- content.highlighted: Items for the highlighted content region. +- content.help: Dynamic help text, mostly for admin pages. +- content.content: The main content of the current page. +- content.sidebar_first: Items for the first sidebar. +- content.sidebar_second: Items for the second sidebar. +- content.triptych_first: Items for the first triptych. +- content.triptych_middle: Items for the middle triptych. +- content.triptych_last: Items for the last triptych. +- content.footer_firstcolumn: Items for the first footer column. +- content.footer_secondcolumn: Items for the second footer column. +- content.footer_thirdcolumn: Items for the third footer column. +- content.footer_fourthcolumn: Items for the fourth footer column. +- content.footer: Items for the footer region. @see template_preprocess() -@see template_preprocess_page() +@see template_preprocess_content() @see template_process() @see bartik_process_page() @see html.tpl.php @@ -90,62 +90,60 @@ Regions: #} {# system is emitted before & above everything else #} -{% if page.system %}{{ page.system }}{% endif %} +{% if content.system %}{{ content.system }}{% endif %}