Skip to content

Commit

Permalink
Untangle node and layout
Browse files Browse the repository at this point in the history
  • Loading branch information
docwilmot committed Sep 1, 2018
1 parent 8c8e72a commit 91b35b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
25 changes: 5 additions & 20 deletions core/modules/layout/layout.module
Original file line number Diff line number Diff line change
Expand Up @@ -1063,35 +1063,20 @@ function layout_get_layout_by_path($path = NULL, $router_item = NULL) {
$cache = &backdrop_static(__FUNCTION__);

if (empty($cache[$router_item['path']])) {
// If the path is a node preview path, check if a custom layout exists for
// nodes and use that instead.
$layouts = layout_load_multiple_by_path($router_item['path'], TRUE);
$data = NULL;
$node_types = node_type_get_types();
foreach ($node_types as $type) {
$preview_path = 'node/' . $type->type . '/preview';
if ($router_item['path'] == $preview_path) {
$tempstore_id = node_build_tempstore_id($type->type);
$data = node_get_node_tempstore($tempstore_id);
$break;
}
}
if ($data && $node_layouts = layout_load_multiple_by_path('node/%', TRUE)) {
$layouts = $node_layouts;
}
else {
$layouts = layout_load_multiple_by_path($router_item['path'], TRUE);
}
backdrop_alter('layout_get_layout_by_path', $layouts, $router_item, $data);
$selected_layout = NULL;
foreach ($layouts as $layout) {
// Contexts must be set before the layout's access may be checked.
$contexts = $layout->getContexts();
foreach ($contexts as $context) {
if (isset($context->position)) {

// Check for an object loaded by the menu router. Use a preview from
// Tempstore if on a node preview page.
// Check for an object loaded by the menu router or one provided by a
// module implementing hook_layout_get_layout_by_path_alter();
if (isset($router_item['map'][$context->position])) {
$data = isset($data) ? $data : $router_item['map'][$context->position];
$data = !empty($data) ? $data : $router_item['map'][$context->position];
$context->setData($data);
}

Expand Down
18 changes: 18 additions & 0 deletions core/modules/node/node.module
Original file line number Diff line number Diff line change
Expand Up @@ -3732,6 +3732,24 @@ function node_language_delete($language) {
->execute();
}

/**
* Implements hook_layout_get_layout_by_path().
*/
function node_layout_get_layout_by_path_alter(&$layouts, $router_item, $data) {
// If the path is a node preview path, check if a custom layout exists for
// nodes and use that instead.
if ((strpos($router_item['path'], 'node/preview') === 0) && isset($router_item['map'][3])) {
$tempstore_id = $router_item['map'][3];
$data = node_get_node_tempstore($tempstore_id);
}
if ($data && $node_layouts = layout_load_multiple_by_path('node/%', TRUE)) {
$layouts = $node_layouts;
}
else {
$data = NULL;
}
}

/**
* Get a node from the tempstore.
*
Expand Down

0 comments on commit 91b35b5

Please sign in to comment.