diff options
Diffstat (limited to 'modules/node')
-rw-r--r-- | modules/node/node.api.php | 21 | ||||
-rw-r--r-- | modules/node/node.module | 32 |
2 files changed, 29 insertions, 24 deletions
diff --git a/modules/node/node.api.php b/modules/node/node.api.php index fc967e3ef..d922d9b47 100644 --- a/modules/node/node.api.php +++ b/modules/node/node.api.php @@ -540,9 +540,9 @@ function hook_node_view(stdClass $node, $build_mode) { } /** - * The node content was built, the module may modify the structured content. + * The node content was built; the module may modify the structured content. * - * This hook is called after the content has been assembled in $node->content + * This hook is called after the content has been assembled in a structured array * and may be used for doing processing which requires that the complete node * content structure has been built. * @@ -551,20 +551,19 @@ function hook_node_view(stdClass $node, $build_mode) { * Alternatively, it could also implement hook_preprocess_node(). See * drupal_render() and theme() documentation respectively for details. * - * @param $node - * The node the action is being performed on. - * @param $build_mode - * The $build_mode parameter from node_build(). + * @param $build + * A renderable array representing the node content. + * + * @see node_build() */ -function hook_node_build_alter(stdClass $node, $build_mode) { - // Check for the existence of a field added by another module. - if (isset($node->content['an_additional_field'])) { +function hook_node_build_alter($build) { + if ($build['#build_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. - $node->content['an_additional_field']['#weight'] = -10; + $build['an_additional_field']['#weight'] = -10; } // Add a #post_render callback to act on the rendered HTML of the node. - $node->content['#post_render'][] = 'my_module_node_post_render'; + $build['#post_render'][] = 'my_module_node_post_render'; } /** diff --git a/modules/node/node.module b/modules/node/node.module index ba326824a..e65251379 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1148,7 +1148,11 @@ function node_build($node, $build_mode = 'full') { '#build_mode' => $build_mode, ); // Add contextual links for this node. - $build['#contextual_links']['node'] = menu_contextual_links('node', array($node->nid)); + // @todo Make this configurable per build mode. + $build['#contextual_links']['node'] = array('node', array($node->nid)); + + // Allow modules to modify the structured node. + drupal_alter('node_build', $build); return $build; } @@ -1177,7 +1181,6 @@ function node_build($node, $build_mode = 'full') { * A node object. * @param $build_mode * Build mode, e.g. 'full', 'teaser'... - * */ function node_build_content(stdClass $node, $build_mode = 'full') { // Remove previously built content, if exists. @@ -1190,6 +1193,9 @@ function node_build_content(stdClass $node, $build_mode = 'full') { } // Build fields content. + // @todo field_attach_prepare_view() is only invoked by node_build_multiple(), + // all other entities invoke it _here_. + //field_attach_prepare_view('node', array($node->nid => $node), $build_mode); $node->content += field_attach_view('node', $node, $build_mode); // Always display a read more link on teasers because we have no way @@ -1210,9 +1216,6 @@ function node_build_content(stdClass $node, $build_mode = 'full') { // Allow modules to make their own additions to the node. module_invoke_all('node_view', $node, $build_mode); - - // Allow modules to modify the structured node. - drupal_alter('node_build', $node, $build_mode); } /** @@ -1543,8 +1546,9 @@ function node_search_execute($keys = NULL) { foreach ($find as $item) { // Render the node. $node = node_load($item->sid); - node_build_content($node, 'search_result'); - $node->rendered = drupal_render($node->content); + $build = node_build($node, 'search_result'); + unset($build['#theme']); + $node->rendered = drupal_render($build); // Fetch comments for snippet. $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node); @@ -2032,16 +2036,17 @@ function node_feed($nids = FALSE, $channel = array()) { // The node gets built and modules add to or modify $node->rss_elements // and $node->rss_namespaces. - node_build_content($node, 'rss'); + $build = node_build($node, 'rss'); + unset($build['#theme']); if (!empty($node->rss_namespaces)) { $namespaces = array_merge($namespaces, $node->rss_namespaces); } - if ($item_length != 'title' && !empty($node->content)) { + if ($item_length != 'title') { // We render node contents and force links to be last. - $links = drupal_render($node->content['links']); - $item_text .= drupal_render($node->content) . $links; + $build['links']['#weight'] = 1000; + $item_text .= drupal_render($build); } $items .= format_rss_item($node->title[FIELD_LANGUAGE_NONE][0]['value'], $node->link, $item_text, $node->rss_elements); @@ -2185,8 +2190,9 @@ function _node_index_node(stdClass $node) { variable_set('node_cron_last', $node->changed); // Render the node. - node_build_content($node, 'search_index'); - $node->rendered = drupal_render($node->content); + $build = node_build($node, 'search_index'); + unset($build['#theme']); + $node->rendered = drupal_render($build); $text = '<h1>' . check_plain($node->title[FIELD_LANGUAGE_NONE][0]['value']) . '</h1>' . $node->rendered; |