From 53748ab5e24de5e33e9cf115e91a5845daa2ecbd Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 26 Dec 2009 16:50:09 +0000 Subject: - Patch #664544 by yched: clean-up entity build/view modes. --- modules/node/node.api.php | 18 +++---- modules/node/node.module | 102 ++++++++++++++++++------------------ modules/node/node.test | 6 +-- modules/node/node.tpl.php | 4 +- modules/node/tests/node_test.module | 6 +-- 5 files changed, 68 insertions(+), 68 deletions(-) (limited to 'modules/node') diff --git a/modules/node/node.api.php b/modules/node/node.api.php index 474398045..eb948eae0 100644 --- a/modules/node/node.api.php +++ b/modules/node/node.api.php @@ -545,13 +545,11 @@ function hook_node_validate($node, $form) { /** * Act on a node that is being assembled before rendering. * - * TODO D7 This needs work to clearly explain the different build modes. - * * The module may add elements to $node->content prior to rendering. This hook * will be called after hook_view(). The structure of $node->content is a * renderable array as expected by drupal_render(). * - * When $build_mode is 'rss', modules can also add extra RSS elements and + * When $view_mode is 'rss', modules can also add extra RSS elements and * namespaces to $node->rss_elements and $node->rss_namespaces respectively for * the RSS item generated for this node. * For details on how this is used @see node_feed() @@ -562,10 +560,10 @@ function hook_node_validate($node, $form) { * * @param $node * The node that is being assembled for rendering. - * @param $build_mode - * The $build_mode parameter from node_view(). + * @param $view_mode + * The $view_mode parameter from node_view(). */ -function hook_node_view($node, $build_mode) { +function hook_node_view($node, $view_mode) { $node->content['my_additional_field'] = array( '#value' => $additional_field, '#weight' => 10, @@ -591,7 +589,7 @@ function hook_node_view($node, $build_mode) { * @see node_view() */ function hook_node_view_alter($build) { - if ($build['#build_mode'] == 'full' && isset($build['an_additional_field'])) { + if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; } @@ -982,8 +980,8 @@ function hook_validate($node, &$form) { * * @param $node * The node to be displayed, as returned by node_load(). - * @param $build_mode - * Build mode, e.g. 'full', 'teaser', ... + * @param $view_mode + * View mode, e.g. 'full', 'teaser', ... * @return * $node. The passed $node parameter should be modified as necessary and * returned so it can be properly presented. Nodes are prepared for display @@ -998,7 +996,7 @@ function hook_validate($node, &$form) { * * For a detailed usage example, see node_example.module. */ -function hook_view($node, $build_mode = 'full') { +function hook_view($node, $view_mode = 'full') { if (node_is_page($node)) { $breadcrumb = array(); $breadcrumb[] = array('path' => 'example', 'title' => t('example')); diff --git a/modules/node/node.module b/modules/node/node.module index 149468784..a7c839d94 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -204,8 +204,33 @@ function node_entity_info() { // Node.module handles its own caching. // 'cacheable' => FALSE, 'bundles' => array(), + 'view modes' => array( + 'full' => array( + 'label' => t('Full node'), + ), + 'teaser' => array( + 'label' => t('Teaser'), + ), + 'rss' => array( + 'label' => t('RSS'), + ), + ), ), ); + + // Search integration is provided by node.module, so search-related + // view modes for nodes are defined here and not in search.module. + if (module_exists('search')) { + $return['node']['view modes'] += array( + 'search_index' => array( + 'label' => t('Search Index'), + ), + 'search_result' => array( + 'label' => t('Search Result'), + ), + ); + } + // Bundles must provide a human readable name so we can create help and error // messages, and the path to attach Field admin pages to. foreach (node_type_get_names() as $type => $name) { @@ -219,31 +244,8 @@ function node_entity_info() { ), ); } - return $return; -} - -/** - * Implements hook_field_build_modes(). - */ -function node_field_build_modes($obj_type) { - $modes = array(); - if ($obj_type == 'node') { - $modes = array( - 'teaser' => t('Teaser'), - 'full' => t('Full node'), - 'rss' => t('RSS'), - ); - // Search integration is provided by node.module, so search-related - // build-modes for nodes are defined here and not in search.module. - if (module_exists('search')) { - $modes += array( - 'search_index' => t('Search Index'), - 'search_result' => t('Search Result'), - ); - } - } - return $modes; + return $return; } /** @@ -1167,15 +1169,15 @@ function node_revision_delete($revision_id) { * * @param $node * A node object. - * @param $build_mode - * Build mode, e.g. 'full', 'teaser'... + * @param $view_mode + * View mode, e.g. 'full', 'teaser'... * * @return * An array as expected by drupal_render(). */ -function node_view($node, $build_mode = 'full') { +function node_view($node, $view_mode = 'full') { // Populate $node->content with a render() array. - node_build_content($node, $build_mode); + node_build_content($node, $view_mode); $build = $node->content; // We don't need duplicate rendering info in node->content. @@ -1184,10 +1186,10 @@ function node_view($node, $build_mode = 'full') { $build += array( '#theme' => 'node', '#node' => $node, - '#build_mode' => $build_mode, + '#view_mode' => $view_mode, ); // Add contextual links for this node. - // @todo Make this configurable per build mode. + // @todo Make this configurable per view mode. $build['#contextual_links']['node'] = array('node', array($node->nid)); // Allow modules to modify the structured node. @@ -1200,9 +1202,9 @@ function node_view($node, $build_mode = 'full') { * Builds a structured array representing the node's content. * * The content built for the node (field values, comments, file attachments or - * other node components) will vary depending on the $build_mode parameter. + * other node components) will vary depending on the $view_mode parameter. * - * Drupal core defines the following build modes for nodes, with the following + * Drupal core defines the following view modes for nodes, with the following * default use cases: * - full (default): node is being displayed on its own page (node/123) * - teaser: node is being displayed on the default home page listing, on @@ -1213,34 +1215,34 @@ function node_view($node, $build_mode = 'full') { * - search_result: node is being displayed as a search result. * If book.module is enabled: * - print: node is being displayed in print-friendly mode. - * Contributed modules might define additional build modes, or use existing - * build modes in additional contexts. + * Contributed modules might define additional view modes, or use existing + * view modes in additional contexts. * * @param $node * A node object. - * @param $build_mode - * Build mode, e.g. 'full', 'teaser'... + * @param $view_mode + * View mode, e.g. 'full', 'teaser'... */ -function node_build_content($node, $build_mode = 'full') { +function node_build_content($node, $view_mode = 'full') { // Remove previously built content, if exists. $node->content = array(); // The 'view' hook can be implemented to overwrite the default function // to display nodes. if (node_hook($node, 'view')) { - $node = node_invoke($node, 'view', $build_mode); + $node = node_invoke($node, 'view', $view_mode); } // Build fields content. // @todo field_attach_prepare_view() is only invoked by node_view_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); + //field_attach_prepare_view('node', array($node->nid => $node), $view_mode); + $node->content += field_attach_view('node', $node, $view_mode); // Always display a read more link on teasers because we have no way // to know when a teaser view is different than a full view. $links = array(); - if ($build_mode == 'teaser') { + if ($view_mode == 'teaser') { $links['node_readmore'] = array( 'title' => t('Read more'), 'href' => 'node/' . $node->nid, @@ -1254,7 +1256,7 @@ function node_build_content($node, $build_mode = 'full') { ); // Allow modules to make their own additions to the node. - module_invoke_all('node_view', $node, $build_mode); + module_invoke_all('node_view', $node, $view_mode); } /** @@ -1345,15 +1347,15 @@ function node_is_page($node) { * * The $variables array contains the following arguments: * - $node - * - $build_mode + * - $view_mode * - $page * * @see node.tpl.php */ function template_preprocess_node(&$variables) { - $variables['build_mode'] = $variables['elements']['#build_mode']; + $variables['view_mode'] = $variables['elements']['#view_mode']; // Provide a distinct $teaser boolean. - $variables['teaser'] = $variables['build_mode'] == 'teaser'; + $variables['teaser'] = $variables['view_mode'] == 'teaser'; $variables['node'] = $variables['elements']['#node']; $node = $variables['node']; @@ -2140,18 +2142,18 @@ function node_feed($nids = FALSE, $channel = array()) { * * @param $nodes * An array of nodes as returned by node_load_multiple(). - * @param $build_mode - * Build mode, e.g. 'full', 'teaser'... + * @param $view_mode + * View mode, e.g. 'full', 'teaser'... * @param $weight * An integer representing the weight of the first node in the list. * @return * An array in the format expected by drupal_render(). */ -function node_view_multiple($nodes, $build_mode = 'teaser', $weight = 0) { - field_attach_prepare_view('node', $nodes, $build_mode); +function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0) { + field_attach_prepare_view('node', $nodes, $view_mode); $build = array(); foreach ($nodes as $node) { - $build['nodes'][$node->nid] = node_view($node, $build_mode); + $build['nodes'][$node->nid] = node_view($node, $view_mode); $build['nodes'][$node->nid]['#weight'] = $weight; $weight++; } diff --git a/modules/node/node.test b/modules/node/node.test index 699e9dc4f..29fb04c7a 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -630,11 +630,11 @@ class NodeRSSContentTestCase extends DrupalWebTestCase { $this->drupalGet('rss.xml'); - // Check that content added in 'rss' build mode appear in RSS feed. + // Check that content added in 'rss' view mode appear in RSS feed. $rss_only_content = t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->nid)); $this->assertText($rss_only_content, t('Node content designated for RSS appear in RSS feed.')); - // Check that content added in build modes other than 'rss' doesn't + // Check that content added in view modes other than 'rss' doesn't // appear in RSS feed. $non_rss_content = t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid)); $this->assertNoText($non_rss_content, t('Node content not designed for RSS doesn\'t appear in RSS feed.')); @@ -648,7 +648,7 @@ class NodeRSSContentTestCase extends DrupalWebTestCase { $this->assertRaw(format_xml_elements(array($test_element)), t('Extra RSS elements appear in RSS feed.')); $this->assertRaw($test_ns, t('Extra namespaces appear in RSS feed.')); - // Check that content added in 'rss' build mode doesn't appear when + // Check that content added in 'rss' view mode doesn't appear when // viewing node. $this->drupalGet("node/$node->nid"); $this->assertNoText($rss_only_content, t('Node content designed for RSS doesn\'t appear when viewing node.')); diff --git a/modules/node/node.tpl.php b/modules/node/node.tpl.php index 6435cdf94..1cbd06a7a 100644 --- a/modules/node/node.tpl.php +++ b/modules/node/node.tpl.php @@ -46,8 +46,8 @@ * - $id: Position of the node. Increments each time it's output. * * Node status variables: - * - $build_mode: Build mode, e.g. 'full', 'teaser'... - * - $teaser: Flag for the teaser state (shortcut for $build_mode == 'teaser'). + * - $view_mode: View mode, e.g. 'full', 'teaser'... + * - $teaser: Flag for the teaser state (shortcut for $view_mode == 'teaser'). * - $page: Flag for the full page state. * - $promote: Flag for front page promotion state. * - $sticky: Flags for sticky post setting. diff --git a/modules/node/tests/node_test.module b/modules/node/tests/node_test.module index 3fcdb08f4..48518d9f0 100644 --- a/modules/node/tests/node_test.module +++ b/modules/node/tests/node_test.module @@ -10,8 +10,8 @@ /** * Implements hook_node_view(). */ -function node_test_node_view($node, $build_mode) { - if ($build_mode == 'rss') { +function node_test_node_view($node, $view_mode) { + if ($view_mode == 'rss') { // Add RSS elements and namespaces when building the RSS feed. $node->rss_elements[] = array( 'key' => 'testElement', @@ -26,7 +26,7 @@ function node_test_node_view($node, $build_mode) { ); } - if ($build_mode != 'rss') { + if ($view_mode != 'rss') { // Add content that should NOT be displayed in the RSS feed. $node->content['extra_non_feed_content'] = array( '#markup' => '

' . t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid)) . '

', -- cgit v1.2.3