1 node.module | node_layout_load_by_router_item_alter(&$layouts, $router_item) |
Implements hook_layout_load_by_router_item_alter().
When creating node preview pages, the path will be of the form node/preview/<type>/<id>, where <type> is the node type and <id> is the tempstore ID of the node being previewed. But we want to display it using a layout whose system path is node/%. So we choose those layouts and set the context from the tempstore node.
When viewing old node revisions, the path will be of the form node/<nid>/revisions/<vid>/view, where <nid> is the node ID and <vid> is the revision ID. As with previews, we want to display it using a layout whose system path is node/%.
File
- core/
modules/ node/ node.module, line 1692 - The core module that allows content to be submitted to the site.
Code
function node_layout_load_by_router_item_alter(&$layouts, $router_item) {
$map = $router_item['map'];
// Check for node previews.
if (count($map) == 4 && $map[0] == 'node' && $map[1] == 'preview') {
// Add any node/% path as a fallback and set the context to the appropriate
// node from the tempstore.
$path_is_preview = FALSE;
foreach (node_type_get_types() as $type_obj) {
if ($type_obj->type == $map[2]) {
$path_is_preview = TRUE;
break;
}
}
if (!$path_is_preview) {
return;
}
$tempstore_id = $map[3];
$temp_node = node_get_node_tempstore($tempstore_id);
if ($temp_node) {
$node_layouts = layout_load_multiple_by_path('node/%', TRUE);
if ($node_layouts) {
$layouts += $node_layouts;
foreach ($layouts as $layout) {
foreach ($layout->getContexts() as $context) {
if (isset($context->position)) {
$context->setData($temp_node);
}
}
}
}
}
}
// Check for node revisions.
if (count($map) == 5 && $map[0] == 'node' && $map[2] == 'revisions' && $map[4] == 'view') {
// Add any node/% path as a fallback and set the context to the appropriate
// node revision.
$rev_node = $map[1];
if ($rev_node) {
$node_layouts = layout_load_multiple_by_path('node/%', TRUE);
if ($node_layouts) {
$layouts += $node_layouts;
foreach ($layouts as $layout) {
foreach ($layout->getContexts() as $context) {
if (isset($context->position)) {
$context->setData($rev_node);
}
}
}
}
}
}
// If either default was passed in originally, move it to the end of the list.
if (isset($layouts['admin_default'])) {
$admin_default = $layouts['admin_default'];
unset($layouts['admin_default']);
$layouts['admin_default'] = $admin_default;
}
if (isset($layouts['default'])) {
$default = $layouts['default'];
unset($layouts['default']);
$layouts['default'] = $default;
}
}