diff --git a/includes/common.inc b/includes/common.inc index e6db76cd59adab58587d4f91b157c47b65d6863d..c66db98aa1bb76b01f4d9ed5fc05e564dbe5b0f8 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6296,6 +6296,7 @@ function entity_get_info($entity_type = NULL) { 'static cache' => TRUE, 'load hook' => $name . '_load', 'bundles' => array(), + 'view modes' => array(), 'object keys' => array(), 'cacheable' => TRUE, 'translation' => array(), @@ -6325,6 +6326,7 @@ function entity_get_info($entity_type = NULL) { function entity_info_cache_clear() { drupal_static_reset('entity_get_info'); cache_clear_all('entity_info', 'cache'); + drupal_static_reset('entity_view_mode_info'); } /** diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 712eb905036353c61d282e5e73b98a1b148a16cc..2b0e3c55a0d0495821bae4c981fb20f516f4d322 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -66,7 +66,7 @@ function blog_form($node, $form_state) { /** * Implements hook_view(). */ -function blog_view($node, $build_mode) { +function blog_view($node, $view_mode) { if (node_is_page($node)) { // Breadcrumb navigation. drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => format_username($node))), 'blog/' . $node->uid))); @@ -77,8 +77,8 @@ function blog_view($node, $build_mode) { /** * Implements hook_node_view(). */ -function blog_node_view($node, $build_mode = 'full') { - if ($build_mode != 'rss') { +function blog_node_view($node, $view_mode = 'full') { + if ($view_mode != 'rss') { if ($node->type == 'blog' && arg(0) != 'blog' || arg(1) != $node->uid) { $links['blog_usernames_blog'] = array( 'title' => t("!username's blog", array('!username' => format_username($node))), diff --git a/modules/book/book.module b/modules/book/book.module index 496b68afe9224f4d72b422a46e328941f62434fb..4361c7eb72dc90f40a255c56e499215034336f70 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -87,11 +87,11 @@ function book_permission() { /** * Inject links into $node as needed. */ -function book_node_view_link($node, $build_mode) { +function book_node_view_link($node, $view_mode) { $links = array(); if (isset($node->book['depth'])) { - if ($build_mode == 'full') { + if ($view_mode == 'full') { $child_type = variable_get('book_child_type', 'book'); if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { $links['book_add_child'] = array( @@ -220,16 +220,15 @@ function book_init() { } /** - * Implements hook_field_build_modes(). + * Implements hook_entity_info_alter(). */ -function book_field_build_modes($obj_type) { - $modes = array(); - if ($obj_type == 'node') { - $modes = array( - 'print' => t('Print'), - ); - } - return $modes; +function book_entity_info_alter(&$info) { + // Add the 'Print' view mode for nodes. + $info['node']['view modes'] += array( + 'print' => array( + 'label' => t('Print'), + ), + ); } /** @@ -759,8 +758,8 @@ function book_node_load($nodes, $types) { /** * Implements hook_node_view(). */ -function book_node_view($node, $build_mode) { - if ($build_mode == 'full') { +function book_node_view($node, $view_mode) { + if ($view_mode == 'full') { if (!empty($node->book['bid']) && empty($node->in_preview)) { $node->content['book_navigation'] = array( '#markup' => theme('book_navigation', array('book_link' => $node->book)), @@ -769,8 +768,8 @@ function book_node_view($node, $build_mode) { } } - if ($build_mode != 'rss') { - book_node_view_link($node, $build_mode); + if ($view_mode != 'rss') { + book_node_view_link($node, $view_mode); } } diff --git a/modules/comment/comment.api.php b/modules/comment/comment.api.php index 1eb3a891eefba4f496be18b8e796e0bec46aed11..0d2c17d76c9103e1895ae865d10cdc7ab096998e 100644 --- a/modules/comment/comment.api.php +++ b/modules/comment/comment.api.php @@ -91,7 +91,7 @@ function hook_comment_view($comment) { */ function hook_comment_view_alter($build) { // Check for the existence of a field added by another module. - 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; } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index c4554d91a7a36edda7b877d66c10b70b3b73e31a..93aad8e73324ec328ca4afd3734dc161150b1c39 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -107,6 +107,11 @@ function comment_entity_info() { 'bundle' => 'type', ), 'bundles' => array(), + 'view modes' => array( + 'full' => array( + 'label' => t('Full comment'), + ), + ), 'static cache' => FALSE, ), ); @@ -484,11 +489,11 @@ function theme_comment_block() { /** * Implements hook_node_view(). */ -function comment_node_view($node, $build_mode) { +function comment_node_view($node, $view_mode) { $links = array(); if ($node->comment) { - if ($build_mode == 'rss') { + if ($view_mode == 'rss') { if ($node->comment != COMMENT_NODE_HIDDEN) { // Add a comments RSS element which is a URL to the comments of this node. $node->rss_elements[] = array( @@ -497,7 +502,7 @@ function comment_node_view($node, $build_mode) { ); } } - elseif ($build_mode == 'teaser') { + elseif ($view_mode == 'teaser') { // Main page: display the number of comments that have been posted. if (user_access('access comments')) { if (!empty($node->comment_count)) { @@ -576,7 +581,7 @@ function comment_node_view($node, $build_mode) { // Only append comments when we are building a node on its own node detail // page. We compare $node and $page_node to ensure that comments are not // appended to other nodes shown on the page, for example a node_reference - // displayed in 'full' build mode within another node. + // displayed in 'full' view mode within another node. if ($node->comment && node_is_page($node) && empty($node->in_preview) && user_access('access comments')) { $node->content['comments'] = comment_node_page_additions($node); } @@ -778,15 +783,15 @@ function comment_prepare_thread(&$comments) { * A comment object. * @param $node * The node the comment is attached to. - * @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 comment_view($comment, $node, $build_mode = 'full') { +function comment_view($comment, $node, $view_mode = 'full') { // Populate $comment->content with a render() array. - comment_build_content($comment, $node, $build_mode); + comment_build_content($comment, $node, $view_mode); $build = $comment->content; // We don't need duplicate rendering info in comment->content. @@ -796,7 +801,7 @@ function comment_view($comment, $node, $build_mode = 'full') { '#theme' => 'comment', '#comment' => $comment, '#node' => $node, - '#build_mode' => $build_mode, + '#view_mode' => $view_mode, ); $prefix = ''; @@ -831,16 +836,16 @@ function comment_view($comment, $node, $build_mode = 'full') { * Builds a structured array representing the comment's content. * * The content built for the comment (field values, comments, file attachments or - * other comment components) will vary depending on the $build_mode parameter. + * other comment components) will vary depending on the $view_mode parameter. * * @param $comment * A comment object. * @param $node * The node the comment is attached to. - * @param $build_mode - * Build mode, e.g. 'full', 'teaser'... + * @param $view_mode + * View mode, e.g. 'full', 'teaser'... */ -function comment_build_content($comment, $node, $build_mode = 'full') { +function comment_build_content($comment, $node, $view_mode = 'full') { // Remove previously built content, if exists. $comment->content = array(); @@ -850,8 +855,8 @@ function comment_build_content($comment, $node, $build_mode = 'full') { ); // Build fields content. - field_attach_prepare_view('comment', array($comment->cid => $comment), $build_mode); - $comment->content += field_attach_view('comment', $comment, $build_mode); + field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode); + $comment->content += field_attach_view('comment', $comment, $view_mode); if (empty($comment->in_preview)) { $comment->content['links']['comment'] = array( @@ -862,7 +867,7 @@ function comment_build_content($comment, $node, $build_mode = 'full') { } // Allow modules to make their own additions to the comment. - module_invoke_all('comment_view', $comment, $build_mode); + module_invoke_all('comment_view', $comment, $view_mode); } /** @@ -933,21 +938,21 @@ function comment_links($comment, $node) { * An array of comments as returned by comment_load_multiple(). * @param $node * The node the comments are attached to. - * @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 comment in the list. * @return * An array in the format expected by drupal_render(). */ -function comment_view_multiple($comments, $node, $build_mode = 'full', $weight = 0) { - field_attach_prepare_view('comment', $comments, $build_mode); +function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0) { + field_attach_prepare_view('comment', $comments, $view_mode); $build = array( '#sorted' => TRUE, ); foreach ($comments as $comment) { - $build[$comment->cid] = comment_view($comment, $node, $build_mode); + $build[$comment->cid] = comment_view($comment, $node, $view_mode); $build[$comment->cid]['#weight'] = $weight; $weight++; } @@ -1408,7 +1413,7 @@ function comment_save($comment) { catch (Exception $e) { $transaction->rollback('comment', $e->getMessage(), array(), WATCHDOG_ERROR); } - + } /** diff --git a/modules/field/field.api.php b/modules/field/field.api.php index 4aec4840703e6d5aa19bedb87546615e879f723c..52000d92270bf9806231fbf31a6d3b75b109ad0b 100644 --- a/modules/field/field.api.php +++ b/modules/field/field.api.php @@ -1030,7 +1030,7 @@ function hook_field_attach_delete_revision($obj_type, $object) { * An associative array containing: * - obj_type: The type of $object; e.g. 'node' or 'user'. * - object: The object with fields to render. - * - build_mode: Build mode, e.g. 'full', 'teaser'... + * - view_mode: View mode, e.g. 'full', 'teaser'... * - langcode: The language in which the field values will be displayed. */ function hook_field_attach_view_alter(&$output, $context) { @@ -1578,16 +1578,6 @@ function hook_field_read_instance($instance) { * TODO: I'm not sure where these belong yet. **********************************************************************/ -/** - * TODO - * - * Note : Right now this belongs to the "Fieldable Type API". - * Whether 'build modes' is actually a 'fields' concept is to be debated - * in a separate overhaul patch for core. - */ -function hook_field_build_modes($obj_type) { -} - /** * Determine whether the user has access to a given field. * diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc index ef26af253769ff3d18593583814197f7694a82be..052d22811e3dab72c7d1fdb30f14b6138a8500cc 100644 --- a/modules/field/field.attach.inc +++ b/modules/field/field.attach.inc @@ -143,7 +143,7 @@ class FieldQueryException extends FieldException {} * The fully formed $obj_type object. * @param $a * - The $form in the 'form' operation. - * - The value of $build_mode in the 'view' operation. + * - The value of $view_mode in the 'view' operation. * - Otherwise NULL. * @param $b * - The $form_state in the 'submit' operation. @@ -1113,20 +1113,20 @@ function field_attach_query_revisions($field_id, $conditions, $options = array() /** * Allow formatters to act on fieldable objects prior to rendering. */ -function field_attach_prepare_view($obj_type, $objects, $build_mode = 'full') { +function field_attach_prepare_view($obj_type, $objects, $view_mode = 'full') { // First let the field types do their preparation. _field_invoke_multiple('prepare_view', $obj_type, $objects); // Then let the formatters do their own specific massaging. // field_default_prepare_view() takes care of dispatching to the correct - // formatters according to the display settings for the build mode. - _field_invoke_multiple_default('prepare_view', $obj_type, $objects, $build_mode); + // formatters according to the display settings for the view mode. + _field_invoke_multiple_default('prepare_view', $obj_type, $objects, $view_mode); } /** * Returns a renderable array for the fields on an object. * * Each field is displayed according to the display options specified in the - * $instance definition for the given $build_mode. + * $instance definition for the given $view_mode. * * Sample structure: * @code @@ -1138,7 +1138,7 @@ function field_attach_prepare_view($obj_type, $objects, $build_mode = 'full') { * '#object' => the fieldable object being displayed, * '#object_type' => the type of the object being displayed, * '#language' => the language of the field values being displayed, - * '#build_mode' => the build mode, + * '#view_mode' => the view mode, * '#field_name' => the name of the field, * '#field_type' => the type of the field, * '#formatter' => the name of the formatter, @@ -1153,15 +1153,15 @@ function field_attach_prepare_view($obj_type, $objects, $build_mode = 'full') { * The type of $object; e.g. 'node' or 'user'. * @param $object * The object with fields to render. - * @param $build_mode - * Build mode, e.g. 'full', 'teaser'... + * @param $view_mode + * View mode, e.g. 'full', 'teaser'... * @param $langcode * The language the field values are to be shown in. If no language is * provided the current language is used. * @return * A renderable array for the field values. */ -function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode = NULL) { +function field_attach_view($obj_type, $object, $view_mode = 'full', $langcode = NULL) { // If no language is provided use the current UI language. $options = array('language' => field_multilingual_valid_language($langcode, FALSE)); @@ -1169,7 +1169,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode = $null = NULL; _field_invoke('sanitize', $obj_type, $object, $null, $null, $options); - $output = _field_invoke_default('view', $obj_type, $object, $build_mode, $null, $options); + $output = _field_invoke_default('view', $obj_type, $object, $view_mode, $null, $options); // Add custom weight handling. list($id, $vid, $bundle) = entity_extract_ids($obj_type, $object); @@ -1181,7 +1181,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode = $context = array( 'obj_type' => $obj_type, 'object' => $object, - 'build_mode' => $build_mode, + 'view_mode' => $view_mode, 'langcode' => $langcode, ); drupal_alter('field_attach_view', $output, $context); diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc index 9ccf554886d2dfa07985175ece8e16d802f8cca7..8b8273ee9706181d8271ab9746147e1d2163b498 100644 --- a/modules/field/field.crud.inc +++ b/modules/field/field.crud.inc @@ -149,11 +149,11 @@ * - module (string, read-only) * The name of the module that implements the widget type. * - display (array) - * A sub-array of key/value pairs identifying build modes and the way the - * field values should be displayed in each build mode. + * A sub-array of key/value pairs identifying view modes and the way the + * field values should be displayed in each mode. * - full (array) * A sub-array of key/value pairs of the display options to be used - * when the field is being displayed in the "full" build mode. + * when the field is being displayed in the "full" view mode. * - label (string) * Position of the label. 'inline', 'above' and 'hidden' are the * values recognized by the default 'field' theme implementation. @@ -164,12 +164,12 @@ * the formatter. * - weight (float) * The weight of the field relative to the other object components - * displayed in this build mode. + * displayed in this view mode. * - module (string, read-only) * The name of the module which implements the display formatter. * - teaser * - ... - * - other_build_mode + * - other_mode * - ... * * Bundles are represented by two strings, an entity type and a bundle name. @@ -588,7 +588,7 @@ function field_delete_field($field_name) { * - settings: each omitted setting is given the default value specified in * hook_field_widget_info(). * - display: - * Settings for the 'full' build mode will be added, and each build mode + * Settings for the 'full' view mode will be added, and each view mode * will be completed with the following default values: * - label: 'above' * - type: the default formatter specified in hook_field_info(). @@ -621,7 +621,7 @@ function field_create_instance($instance) { // TODO: Check that the widget type is known and can handle the field type ? // TODO: Check that the formatters are known and can handle the field type ? - // TODO: Check that the display build modes are known for the object type ? + // TODO: Check that the display view modes are known for the object type ? // Those checks should probably happen in _field_write_instance() ? // Problem : this would mean that a UI module cannot update an instance with a disabled formatter. @@ -722,23 +722,23 @@ function _field_write_instance($instance, $update = FALSE) { $instance['widget']['module'] = $widget_type['module']; $instance['widget']['settings'] += field_info_widget_settings($instance['widget']['type']); - // Make sure there is at least display info for the 'full' build mode. + // Make sure there is at least display info for the 'full' view mode. $instance['display'] += array( 'full' => array(), ); - // Set default display settings for each build mode. - foreach ($instance['display'] as $build_mode => $display) { - $instance['display'][$build_mode] += array( + // Set default display settings for each view mode. + foreach ($instance['display'] as $view_mode => $display) { + $instance['display'][$view_mode] += array( 'label' => 'above', // TODO: what if no 'default_formatter' specified ? 'type' => $field_type['default_formatter'], 'settings' => array(), 'weight' => 0, ); - $formatter_type = field_info_formatter_types($instance['display'][$build_mode]['type']); + $formatter_type = field_info_formatter_types($instance['display'][$view_mode]['type']); // TODO : 'hidden' will raise PHP warnings. - $instance['display'][$build_mode]['module'] = $formatter_type['module']; - $instance['display'][$build_mode]['settings'] += field_info_formatter_settings($instance['display'][$build_mode]['type']); + $instance['display'][$view_mode]['module'] = $formatter_type['module']; + $instance['display'][$view_mode]['settings'] += field_info_formatter_settings($instance['display'][$view_mode]['type']); } // The serialized 'data' column contains everything from $instance that does diff --git a/modules/field/field.default.inc b/modules/field/field.default.inc index f26f46ba3bdd4c73e6c5e646fcc8a29dd68c71af..3bd5f10f9010609b5af49c59e985b5f48c5f9f06 100644 --- a/modules/field/field.default.inc +++ b/modules/field/field.default.inc @@ -114,7 +114,7 @@ function field_default_insert($obj_type, $object, $field, $instance, $langcode, * Array of field values already loaded for the objects, keyed by object id. * @param $display * Can be either: - * - the name of a build mode + * - the name of a view mode * - or an array of display settings to use for display, as found in the * 'display' entry of $instance definitions. */ @@ -161,7 +161,7 @@ function field_default_prepare_view($obj_type, $objects, $field, $instances, $la * Array of field values already loaded for the objects, keyed by object id. * @param $display * Can be either: - * - the name of a build mode; + * - the name of a view mode; * - or an array of custom display settings, as found in the 'display' entry * of $instance definitions. */ @@ -172,16 +172,16 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i // Prepare incoming display specifications. if (is_string($display)) { - $build_mode = $display; - $display = $instance['display'][$build_mode]; + $view_mode = $display; + $display = $instance['display'][$view_mode]; } else { - $build_mode = '_custom_display'; + $view_mode = '_custom_display'; } if ($display['type'] !== 'hidden') { // We never want to index fields labels. - if ($build_mode == 'search_index') { + if ($view_mode == 'search_index') { $display['label'] = 'hidden'; } @@ -199,7 +199,7 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i '#title' => t($instance['label']), '#access' => field_access('view', $field, $obj_type, $object), '#label_display' => $display['label'], - '#build_mode' => $build_mode, + '#view_mode' => $view_mode, '#language' => $langcode, '#field_name' => $field['field_name'], '#field_type' => $field['type'], diff --git a/modules/field/field.info.inc b/modules/field/field.info.inc index 520f012a077e39a48706a0109a1b5c0a965c54f4..8c71418c99e386019c6313924bde80e9a2ccfe84 100644 --- a/modules/field/field.info.inc +++ b/modules/field/field.info.inc @@ -29,7 +29,6 @@ function field_info_cache_clear() { entity_info_cache_clear(); _field_info_collate_types(TRUE); - drupal_static_reset('field_build_modes'); _field_info_collate_fields(TRUE); } @@ -280,14 +279,15 @@ function _field_info_prepare_instance($instance, $field) { $instance['widget'] = _field_info_prepare_instance_widget($field, $instance['widget']); - foreach ($instance['display'] as $build_mode => $display) { - $instance['display'][$build_mode] = _field_info_prepare_instance_display($field, $display); + foreach ($instance['display'] as $view_mode => $display) { + $instance['display'][$view_mode] = _field_info_prepare_instance_display($field, $display); } - // Fallback to 'full' display settings for unspecified build modes. - foreach (field_build_modes($instance['object_type']) as $build_mode => $label) { - if (!isset($instance['display'][$build_mode])) { - $instance['display'][$build_mode] = $instance['display']['full']; + // Fallback to 'full' display settings for unspecified view modes. + $entity_info = entity_get_info($instance['object_type']); + foreach ($entity_info['view modes'] as $view_mode => $info) { + if (!isset($instance['display'][$view_mode])) { + $instance['display'][$view_mode] = $instance['display']['full']; } } @@ -301,7 +301,7 @@ function _field_info_prepare_instance($instance, $field) { * The field structure for the instance. * @param $display * Display specifications as found in - * $instance['display']['some_build_mode']. + * $instance['display']['some_view_mode']. */ function _field_info_prepare_instance_display($field, $display) { $field_type = field_info_field_types($field['type']); diff --git a/modules/field/field.module b/modules/field/field.module index f4dba7cbe7e3f8b7d835613653669cc6271f7ba3..0f44c99b07b627f6c875b47367afefa024d8d2ca 100644 --- a/modules/field/field.module +++ b/modules/field/field.module @@ -367,18 +367,6 @@ function _field_sort_items_value_helper($a, $b) { return ($a_weight < $b_weight) ? -1 : 1; } -/** - * Registry of available build modes. - */ -function field_build_modes($obj_type) { - $info = &drupal_static(__FUNCTION__, array()); - - if (!isset($info[$obj_type])) { - $info[$obj_type] = module_invoke_all('field_build_modes', $obj_type); - } - return $info[$obj_type]; -} - /** * Registry of pseudo-field components in a given bundle. * @@ -393,7 +381,7 @@ function field_extra_fields($bundle_name) { if (empty($info)) { $info = array(); $bundles = field_info_bundles(); - foreach ($bundles as $bundle => $bundle_label) { + foreach ($bundles as $bundle => $bundle_info) { // Gather information about non-field object additions. $extra = module_invoke_all('field_extra_fields', $bundle); drupal_alter('field_extra_fields', $extra, $bundle); @@ -588,11 +576,11 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL, * The name of the field to display. * @param $display * Can be either: - * - The name of a build mode. The field will be displayed according to the - * display settings specified for this build mode in the $instance + * - The name of a view mode. The field will be displayed according to the + * display settings specified for this view mode in the $instance * definition for the field in the object's bundle. - * If no display settings are found for the build mode, the settings for - * the 'full' build mode will be used. + * If no display settings are found for the view mode, the settings for + * the 'full' view mode will be used. * - An array of display settings, as found in the 'display' entry of * $instance definitions. The following kay/value pairs are allowed: * - label: (string) Position of the label. The default 'field' theme @@ -624,8 +612,8 @@ function field_view_field($obj_type, $object, $field_name, $display = array(), $ $display = _field_info_prepare_instance_display($field, $display); } else { - // When using a build mode, make sure we have settings for it, or fall - // back to the 'full' build mode. + // When using a view mode, make sure we have settings for it, or fall + // back to the 'full' view mode. list(, , $bundle) = entity_extract_ids($obj_type, $object); $instance = field_info_instance($obj_type, $field_name, $bundle); if (!isset($instance['display'][$display])) { @@ -651,7 +639,7 @@ function field_view_field($obj_type, $object, $field_name, $display = array(), $ $context = array( 'obj_type' => $obj_type, 'object' => $object, - 'build_mode' => '_custom', + 'view_mode' => '_custom', 'langcode' => $langcode, ); drupal_alter('field_attach_view', $result, $context); @@ -755,7 +743,7 @@ function template_preprocess_field(&$variables) { $additions = array( 'object' => $element['#object'], - 'build_mode' => $element['#build_mode'], + 'view_mode' => $element['#view_mode'], 'items' => $items, 'field_type' => $element['#field_type'], 'field_name' => $element['#field_name'], diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index b148f31c8c348147683700b4c413574f87661583..f4ba5a8cc3e174913285900f600b9c8a9887ce28 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -1339,10 +1339,11 @@ class FieldInfoTestCase extends FieldTestCase { $this->assertIdentical($instance['widget']['settings'], $widget_type['settings'] , t('All expected widget settings are present.')); // Check that the default formatter is used and expected settings are in place. - foreach (field_build_modes('test_entity') as $build_mode => $label) { - $this->assertIdentical($instance['display'][$build_mode]['type'], $field_type['default_formatter'], t('Unavailable formatter replaced with default formatter in build_mode %build_mode', array('%build_mode' => $build_mode))); - $formatter_type = field_info_formatter_types($instance['display'][$build_mode]['type']); - $this->assertIdentical($instance['display'][$build_mode]['settings'], $formatter_type['settings'] , t('All expected formatter settings are present in build_mode %build_mode', array('%build_mode' => $build_mode))); + $entity_info = entity_get_info('test_entity'); + foreach ($entity_info['view modes'] as $view_mode => $info) { + $this->assertIdentical($instance['display'][$view_mode]['type'], $field_type['default_formatter'], t('Unavailable formatter replaced with default formatter in view_mode %view_mode', array('%view_mode' => $view_mode))); + $formatter_type = field_info_formatter_types($instance['display'][$view_mode]['type']); + $this->assertIdentical($instance['display'][$view_mode]['settings'], $formatter_type['settings'] , t('All expected formatter settings are present in view_mode %view_mode', array('%view_mode' => $view_mode))); } } @@ -1807,7 +1808,7 @@ class FieldDisplayAPITestCase extends FieldTestCase { } $this->assertText($setting . '|' . implode('|', $array), t('Values were displayed with expected setting.')); - // Build mode: check that display settings specified in the instance are + // View mode: check that display settings specified in the instance are // used. $output = field_view_field('test_entity', $this->entity, $this->field_name, 'full'); $this->drupalSetContent(drupal_render($output)); @@ -1817,9 +1818,9 @@ class FieldDisplayAPITestCase extends FieldTestCase { $this->assertText($setting . '|' . $value['value'], t('Value @delta was displayed with expected setting.', array('@delta' => $delta))); } - // Unknown build mode: check that display settings for 'full' build mode + // Unknown view mode: check that display settings for 'full' view mode // are used. - $output = field_view_field('test_entity', $this->entity, $this->field_name, 'unknown_build_mode'); + $output = field_view_field('test_entity', $this->entity, $this->field_name, 'unknown_view_mode'); $this->drupalSetContent(drupal_render($output)); $setting = $this->instance['display']['full']['settings']['test_formatter_setting']; $this->assertText($this->label, t('Label was displayed.')); @@ -2327,13 +2328,13 @@ class FieldInstanceCrudTestCase extends FieldTestCase { $this->assertIdentical($record['data']['label'], $this->instance_definition['field_name'], t('Label defaults to field name.')); $this->assertIdentical($record['data']['description'], '', t('Description defaults to empty string.')); $this->assertIdentical($record['data']['widget']['type'], $field_type['default_widget'], t('Default widget has been written.')); - $this->assertTrue(isset($record['data']['display']['full']), t('Display for "full" build_mode has been written.')); - $this->assertIdentical($record['data']['display']['full']['type'], $field_type['default_formatter'], t('Default formatter for "full" build_mode has been written.')); + $this->assertTrue(isset($record['data']['display']['full']), t('Display for "full" view_mode has been written.')); + $this->assertIdentical($record['data']['display']['full']['type'], $field_type['default_formatter'], t('Default formatter for "full" view_mode has been written.')); // Check that default settings are set. $this->assertIdentical($record['data']['settings'], $field_type['instance_settings'] , t('Default instance settings have been written.')); $this->assertIdentical($record['data']['widget']['settings'], $widget_type['settings'] , t('Default widget settings have been written.')); - $this->assertIdentical($record['data']['display']['full']['settings'], $formatter_type['settings'], t('Default formatter settings for "full" build_mode have been written.')); + $this->assertIdentical($record['data']['display']['full']['settings'], $formatter_type['settings'], t('Default formatter settings for "full" view_mode have been written.')); // Guarantee that the field/bundle combination is unique. try { @@ -2411,17 +2412,17 @@ class FieldInstanceCrudTestCase extends FieldTestCase { $settings = $info['settings']; $this->assertIdentical($settings, array_intersect_key($instance_new['display']['full']['settings'], $settings) , t('Changing formatter type updates default settings.')); - // Check that adding a new build mode is saved and gets default settings. + // Check that adding a new view mode is saved and gets default settings. $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance['display']['teaser'] = array(); field_update_instance($instance); $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); - $this->assertTrue(isset($instance_new['display']['teaser']), t('Display for the new build_mode has been written.')); - $this->assertIdentical($instance_new['display']['teaser']['type'], $field_type['default_formatter'], t('Default formatter for the new build_mode has been written.')); + $this->assertTrue(isset($instance_new['display']['teaser']), t('Display for the new view_mode has been written.')); + $this->assertIdentical($instance_new['display']['teaser']['type'], $field_type['default_formatter'], t('Default formatter for the new view_mode has been written.')); $info = field_info_formatter_types($instance_new['display']['teaser']['type']); $settings = $info['settings']; - $this->assertIdentical($settings, $instance_new['display']['teaser']['settings'] , t('Default formatter settings for the new build_mode have been written.')); + $this->assertIdentical($settings, $instance_new['display']['teaser']['settings'] , t('Default formatter settings for the new view_mode have been written.')); // TODO: test failures. } diff --git a/modules/field/tests/field_test.entity.inc b/modules/field/tests/field_test.entity.inc index fec43fcdf9dc2262ff710e2743936622371a5387..0a15bccb67cb3874eeefb5a49faaf3fe444b78b5 100644 --- a/modules/field/tests/field_test.entity.inc +++ b/modules/field/tests/field_test.entity.inc @@ -11,6 +11,15 @@ */ function field_test_entity_info() { $bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle'))); + $test_entity_modes = array( + 'full' => array( + 'label' => t('Full object'), + ), + 'teaser' => array( + 'label' => t('Teaser'), + ), + ); + return array( 'test_entity' => array( 'name' => t('Test Entity'), @@ -22,6 +31,7 @@ function field_test_entity_info() { 'cacheable' => FALSE, 'bundles' => $bundles, 'fieldable' => TRUE, + 'view modes' => $test_entity_modes, ), // This entity type doesn't get form handling for now... 'test_cacheable_entity' => array( @@ -34,6 +44,7 @@ function field_test_entity_info() { 'fieldable' => TRUE, 'cacheable' => TRUE, 'bundles' => $bundles, + 'view modes' => $test_entity_modes, ), ); } @@ -109,20 +120,6 @@ function field_test_delete_bundle($bundle) { } } -/** - * Implements hook_field_build_modes(). - */ -function field_test_field_build_modes($obj_type) { - $modes = array(); - if ($obj_type == 'test_entity' || $obj_type == 'test_cacheable_entity') { - $modes = array( - 'full' => t('Full node'), - 'teaser' => t('Teaser'), - ); - } - return $modes; -} - /** * Creates a basic test_entity object. */ diff --git a/modules/field/theme/field.tpl.php b/modules/field/theme/field.tpl.php index 069ed48faac1e86bfec8008e67d670c2bfd10ad6..ee4d5142ccedb8cd3eb08cb989b6c2ef9e8420af 100644 --- a/modules/field/theme/field.tpl.php +++ b/modules/field/theme/field.tpl.php @@ -24,7 +24,7 @@ * * Other variables: * - $object: The object to which the field is attached. - * - $build_mode: Build mode, e.g. 'full', 'teaser'... + * - $view_mode: View mode, e.g. 'full', 'teaser'... * - $field_name: The field name. * - $field_type: The field type. * - $field_name_css: The css-compatible field name. diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc index 1907e312677c3eb46e58b0024154062d1c63ba95..9143e99f41e08e36e2fb7949a27661d1e48cb33f 100644 --- a/modules/field_ui/field_ui.admin.inc +++ b/modules/field_ui/field_ui.admin.inc @@ -469,8 +469,8 @@ function field_ui_field_overview_form_submit($form, &$form_state) { if (in_array($key, $form['#fields'])) { $instance = field_read_instance($obj_type, $key, $bundle); $instance['widget']['weight'] = $values['weight']; - foreach($instance['display'] as $build_mode => $display) { - $instance['display'][$build_mode]['weight'] = $values['weight']; + foreach($instance['display'] as $view_mode => $display) { + $instance['display'][$view_mode]['weight'] = $values['weight']; } field_update_instance($instance); } @@ -568,9 +568,9 @@ function field_ui_field_overview_form_submit($form, &$form_state) { * Menu callback; presents a listing of fields display settings for a content type. * * This form includes form widgets to select which fields appear in teaser and - * full build modes, and how the field labels should be rendered. + * full view modes, and how the field labels should be rendered. */ -function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, $build_modes_selector = 'basic') { +function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, $view_modes_selector = 'basic') { $bundle = field_extract_bundle($obj_type, $bundle); field_ui_inactive_message($obj_type, $bundle); @@ -579,14 +579,14 @@ function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, // Gather type information. $instances = field_info_instances($obj_type, $bundle); $field_types = field_info_field_types(); - $build_modes = field_ui_build_modes_tabs($obj_type, $build_modes_selector); + $view_modes = field_ui_view_modes_tabs($obj_type, $view_modes_selector); $form += array( '#tree' => TRUE, '#object_type' => $obj_type, '#bundle' => $bundle, '#fields' => array_keys($instances), - '#contexts' => $build_modes_selector, + '#contexts' => $view_modes_selector, ); if (empty($instances)) { @@ -612,14 +612,14 @@ function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, $formatter_options = field_ui_formatter_options($field['type']); $formatter_options['hidden'] = t('<Hidden>'); - foreach ($build_modes as $build_mode => $label) { - $display = isset($instance['display'][$build_mode]) ? $instance['display'][$build_mode] : $instance['display']['full']; - $form[$name][$build_mode]['label'] = array( + foreach ($view_modes as $view_mode) { + $display = isset($instance['display'][$view_mode]) ? $instance['display'][$view_mode] : $instance['display']['full']; + $form[$name][$view_mode]['label'] = array( '#type' => 'select', '#options' => $label_options, '#default_value' => $display['label'], ); - $form[$name][$build_mode]['type'] = array( + $form[$name][$view_mode]['type'] = array( '#type' => 'select', '#options' => $formatter_options, '#default_value' => $display['type'], @@ -631,7 +631,6 @@ function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, return $form; } - /** * Theme preprocess function for field_ui-display-overview-form.tpl.php. */ @@ -639,7 +638,13 @@ function template_preprocess_field_ui_display_overview_form(&$vars) { $form = &$vars['form']; $contexts_selector = $form['#contexts']; - $vars['contexts'] = field_ui_build_modes_tabs($form['#object_type'], $contexts_selector); + $view_modes = field_ui_view_modes_tabs($form['#object_type'], $contexts_selector); + $entity_info = entity_get_info($form['#object_type']); + $view_modes_info = $entity_info['view modes']; + $vars['contexts'] = array(); + foreach ($view_modes as $view_mode) { + $vars['contexts'][$view_mode] = $view_modes_info[$view_mode]['label']; + } $order = _field_ui_overview_order($form, $form['#fields']); if (empty($order)) { @@ -676,9 +681,9 @@ function field_ui_display_overview_form_submit($form, &$form_state) { foreach ($form_values as $key => $values) { if (in_array($key, $form['#fields'])) { $instance = field_info_instance($form['#object_type'], $key, $form['#bundle']); - foreach ($instance['display'] as $build_mode => $display) { - if (isset($values[$build_mode])) { - $instance['display'][$build_mode] = array_merge($instance['display'][$build_mode], $values[$build_mode]); + foreach ($instance['display'] as $view_mode => $display) { + if (isset($values[$view_mode])) { + $instance['display'][$view_mode] = array_merge($instance['display'][$view_mode], $values[$view_mode]); } } field_update_instance($instance); diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module index 18275dd4d5a6dd3e3a89b0299bc574403e1350ea..b24ef77764173490f5c417f999a0861ffee4e5b5 100644 --- a/modules/field_ui/field_ui.module +++ b/modules/field_ui/field_ui.module @@ -117,7 +117,7 @@ function field_ui_menu() { 'weight' => 2, 'file' => 'field_ui.admin.inc', ) + $access; - $tabs = field_ui_build_modes_tabs($obj_type); + $tabs = field_ui_view_modes_tabs($obj_type); foreach ($tabs as $key => $tab) { $items["$path/display/$key"] = array( 'title' => $tab['title'], @@ -171,26 +171,26 @@ function field_ui_theme() { } /** - * Group available build modes on tabs on the 'Manage display' page. + * Group available view modes on tabs on the 'Manage display' page. * * @todo Remove this completely and use vertical tabs? */ -function field_ui_build_modes_tabs($obj_type, $tab_selector = NULL) { +function field_ui_view_modes_tabs($obj_type, $tab_selector = NULL) { $info = &drupal_static(__FUNCTION__); if (!isset($info[$obj_type])) { - $info[$obj_type] = module_invoke_all('field_ui_build_modes_tabs'); - // Collect titles, and filter out non active modes. - $active_modes = field_build_modes($obj_type); + $info[$obj_type] = module_invoke_all('field_ui_view_modes_tabs', $obj_type); + // Filter out inactive modes. + $entity_info = entity_get_info($obj_type); foreach ($info[$obj_type] as $tab => $values) { $modes = array(); - foreach ($info[$obj_type][$tab]['build modes'] as $mode) { - if (isset($active_modes[$mode])) { - $modes[$mode] = $active_modes[$mode]; + foreach ($info[$obj_type][$tab]['view modes'] as $mode) { + if (isset($entity_info['view modes'][$mode])) { + $modes[] = $mode; } } if ($modes) { - $info[$obj_type][$tab]['build modes'] = $modes; + $info[$obj_type][$tab]['view modes'] = $modes; } else { unset($info[$obj_type][$tab]); @@ -198,16 +198,16 @@ function field_ui_build_modes_tabs($obj_type, $tab_selector = NULL) { } } if ($tab_selector) { - return isset($info[$obj_type][$tab_selector]) ? $info[$obj_type][$tab_selector]['build modes'] : array(); + return isset($info[$obj_type][$tab_selector]) ? $info[$obj_type][$tab_selector]['view modes'] : array(); } return $info[$obj_type]; } /** - * Implements hook_field_ui_build_modes_tabs() on behalf of other core modules. + * Implements hook_field_ui_view_modes_tabs() on behalf of other core modules. * * @return - * An array describing the build modes defined by the module, grouped by tabs. + * An array describing the view modes defined by the module, grouped by tabs. * * A module can add its render modes to a tab defined by another module. * Expected format: @@ -215,7 +215,7 @@ function field_ui_build_modes_tabs($obj_type, $tab_selector = NULL) { * array( * 'tab1' => array( * 'title' => t('The human-readable title of the tab'), - * 'build modes' => array('mymodule_mode1', 'mymodule_mode2'), + * 'view modes' => array('mymodule_mode1', 'mymodule_mode2'), * ), * 'tab2' => array( * // ... @@ -223,23 +223,23 @@ function field_ui_build_modes_tabs($obj_type, $tab_selector = NULL) { * ); * @endcode */ -function field_ui_field_ui_build_modes_tabs() { +function field_ui_field_ui_view_modes_tabs() { $modes = array( 'basic' => array( 'title' => t('Basic'), - 'build modes' => array('teaser', 'full'), + 'view modes' => array('teaser', 'full'), ), 'rss' => array( 'title' => t('RSS'), - 'build modes' => array('rss'), + 'view modes' => array('rss'), ), 'print' => array( 'title' => t('Print'), - 'build modes' => array('print'), + 'view modes' => array('print'), ), 'search' => array( 'title' => t('Search'), - 'build modes' => array('search_index', 'search_result'), + 'view modes' => array('search_index', 'search_result'), ), ); return $modes; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 2ee98f936782bc5f1de9f67fbbdfccc7ca0eb2b1..085a4bc9c3170c18539ff808b8c562191af80d8e 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -235,7 +235,7 @@ function _forum_node_check_node_type($node) { /** * Implements hook_node_view(). */ -function forum_node_view($node, $build_mode) { +function forum_node_view($node, $view_mode) { $vid = variable_get('forum_nav_vocabulary', 0); $vocabulary = taxonomy_vocabulary_load($vid); if (_forum_node_check_node_type($node)) { diff --git a/modules/locale/locale.field.inc b/modules/locale/locale.field.inc index 3ad4672ffb381b0008e5393c8f94f94b344af507..45a94bcfe8f06759783d10e0ca274d6cb95e5b4b 100644 --- a/modules/locale/locale.field.inc +++ b/modules/locale/locale.field.inc @@ -65,7 +65,7 @@ function locale_field_fallback_view(&$output, $context) { // Cache fallback values per language as fields might have different // fallback values. if (!isset($fallback_values[$langcode])) { - $fallback_values[$langcode] = field_attach_view($context['obj_type'], $context['object'], $context['build_mode'], $langcode); + $fallback_values[$langcode] = field_attach_view($context['obj_type'], $context['object'], $context['view_mode'], $langcode); } // We are done, skip to the next field. $output[$field_name] = $fallback_values[$langcode][$field_name]; diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 10f60109cd49e815c2448a82ad8779d564833193..b6306399f55e7b09850e1ec0c831eab80601aa3a 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -1712,8 +1712,8 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { $settings['body[full][type]'] = 'hidden'; $this->drupalPost('admin/structure/types/manage/page/display', $settings, t('Save')); $select_xpath = '//select[@id="edit-body-full-type"]/option[@selected="selected"]'; - // Check if body display is actually "hidden" for the "full" build mode. - $this->assertEqual(current($this->xpath($select_xpath)), '<Hidden>', 'Body display is actually "hidden" for the "full" build mode'); + // Check if body display is actually "hidden" for the "full" view mode. + $this->assertEqual(current($this->xpath($select_xpath)), '<Hidden>', 'Body display is actually "hidden" for the "full" view mode'); $this->drupalGet("node/$node->nid"); // Check if node body is not showed. $this->assertFalse(is_array($this->xpath($body_xpath)), 'Body correctly not showed.'); diff --git a/modules/node/node.api.php b/modules/node/node.api.php index 474398045d39078e25e47e07be2acaf21ce084dc..eb948eae04bb0f17c6197483dead3004667a05b7 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 149468784e5b08cf03ea485803c30cfed7023a00..a7c839d9406a271f2d6ef844d0a97921b6f3e1f5 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 699e9dc4f8918cb68442ad48c0fba4eac60f384a..29fb04c7ab207987791879813f44531af7ed1f8e 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 6435cdf94e54bc26a2ea57b996d52553576a6189..1cbd06a7a55b3b215450a07ad5b0f26a4bb8ba50 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 3fcdb08f4d039ec55f890b2eacd5228b8617b017..48518d9f09113499541eb4046ade383afbe41e5d 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' => '<p>' . t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid)) . '</p>', diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 554d62d24e3cdc441f4b838a838dafb0da89657b..45df576a3cd8ba5578435bfbb0817eba347a0b4d 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -598,7 +598,7 @@ function poll_block_latest_poll_view($node) { /** * Implements hook_view(). */ -function poll_view($node, $build_mode = 'full') { +function poll_view($node, $view_mode = 'full') { global $user; $output = ''; @@ -606,7 +606,7 @@ function poll_view($node, $build_mode = 'full') { $node->content['poll_view_voting'] = drupal_get_form('poll_view_voting', $node); } else { - $node->content['poll_view_results'] = array('#markup' => poll_view_results($node, $build_mode)); + $node->content['poll_view_results'] = array('#markup' => poll_view_results($node, $view_mode)); } return $node; } @@ -726,7 +726,7 @@ function template_preprocess_poll_vote(&$variables) { /** * Generates a graphical representation of the results of a poll. */ -function poll_view_results($node, $build_mode, $block = FALSE) { +function poll_view_results($node, $view_mode, $block = FALSE) { // Count the votes and find the maximum $total_votes = 0; $max_votes = 0; diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index bcb476d762edfa91aa4dd33d0ee9f52712167ddf..810564fc1edb2c9ad3582021d85e1512ab59d9d3 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -106,8 +106,8 @@ function statistics_permission() { /** * Implements hook_node_view(). */ -function statistics_node_view($node, $build_mode) { - if ($build_mode != 'rss') { +function statistics_node_view($node, $view_mode) { + if ($view_mode != 'rss') { $links = array(); if (user_access('view post access counter')) { $statistics = statistics_get($node->nid); diff --git a/modules/system/system.api.php b/modules/system/system.api.php index db3c454858fbe7bce47d2290c67f6012da56e302..57ad535364137ffa2504cd25888a15d96d42636e 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -55,7 +55,7 @@ function hook_hook_info() { * * @return * An array whose keys are entity type names and whose values identify - * properties of those types that the system needs to know about: + * properties of those types that the system needs to know about: * - name: The human-readable name of the type. * - controller class: The name of the class that is used to load the objects. * The class has to implement the DrupalEntityControllerInterface interface. @@ -109,6 +109,15 @@ function hook_hook_info() { * - access callback: As in hook_menu(). 'user_access' will be assumed if * no value is provided. * - access arguments: As in hook_menu(). + * - view modes: An array describing the view modes for the entity type. View + * modes let entities be displayed differently depending on the context. + * For instance, a node can be displayed differently on its own page + * ('full' mode), on the home page or taxonomy listings ('teaser' mode), or + * in an RSS feed ('rss' mode). Modules taking part in the display of the + * entity (notably the Field API) can adjust their behavior depending on + * the requested view mode. Keys of the array are view mode names. Each + * view mode is described by an array with the following key/value pairs: + * - label: The human-readable name of the view mode */ function hook_entity_info() { $return = array( diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index f886366a62dc57b2ef750ed1a7914d2f6a993543..5c63fc057eab54fd125d0c8345db4c459d2e33ef 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -98,6 +98,12 @@ function taxonomy_entity_info() { 'bundle' => 'machine_name', ), 'bundles' => array(), + 'view modes' => array( + // @todo View mode for display as a field (when attached to nodes etc). + 'full' => array( + 'label' => t('Taxonomy term page'), + ), + ), ), ); foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { @@ -178,21 +184,6 @@ function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = arr return $query->execute()->fetchCol(); } -/** - * Implements hook_field_build_modes(). - * - * @TODO: build mode for display as a field (when attached to nodes etc.). - */ -function taxonomy_field_build_modes($obj_type) { - $modes = array(); - if ($obj_type == 'term') { - $modes = array( - 'full' => t('Taxonomy term page'), - ); - } - return $modes; -} - /** * Implements hook_theme(). */ diff --git a/modules/translation/translation.module b/modules/translation/translation.module index 24cd021ac8c70d5d432271981c070606390674d9..937f66364d92479a284447be0ed7322b30ec4152 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -169,7 +169,7 @@ function translation_form_alter(&$form, &$form_state, $form_id) { * Display translation links with native language names, if this node * is part of a translation set. */ -function translation_node_view($node, $build_mode) { +function translation_node_view($node, $view_mode) { if (isset($node->tnid) && $translations = translation_node_get_translations($node->tnid)) { $path = 'node/' . $node->nid; $links = language_negotiation_get_switch_links(LANGUAGE_TYPE_CONTENT, $path); diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 939218fcd5631c840f7d0cf2c6a7bf8858ebd313..4d8190bbafd1b2027e5ca051fcfad0ff12762717 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -296,8 +296,8 @@ function _trigger_node($node, $hook, $a3 = NULL, $a4 = NULL) { /** * Implements hook_node_view(). */ -function trigger_node_view($node, $build_mode) { - _trigger_node($node, 'node_view', $build_mode); +function trigger_node_view($node, $view_mode) { + _trigger_node($node, 'node_view', $view_mode); } /** diff --git a/modules/user/user.api.php b/modules/user/user.api.php index 72608ecfab1e691f75d35f8a2ffe6645ed75f361..481002b41d7166cad5a027d8b5ee91c1a8322031 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -314,10 +314,10 @@ function hook_user_logout($account) { * * @param $account * The user object on which the operation is being performed. - * @param $build_mode - * Build mode, e.g. 'full'. + * @param $view_mode + * View mode, e.g. 'full'. */ -function hook_user_view($account, $build_mode) { +function hook_user_view($account, $view_mode) { if (user_access('create blog content', $account)) { $account->content['summary']['blog'] = array( '#type' => 'user_profile_item', @@ -402,7 +402,7 @@ function hook_user_role_update($role) { * Inform other modules that a user role has been deleted. * * This hook allows you act when a user role has been deleted. - * If your module stores references to roles, it's recommended that you + * If your module stores references to roles, it's recommended that you * implement this hook and delete existing instances of the deleted role * in your module database tables. * diff --git a/modules/user/user.module b/modules/user/user.module index 432f936b942e15b33b6d93871acb1c34f296e618..9767c32888a2a72ce471a5fcb8b4da3f67f18d3a 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -142,24 +142,16 @@ function user_entity_info() { ), ), ), + 'view modes' => array( + 'full' => array( + 'label' => t('User account'), + ), + ), ), ); return $return; } -/** - * Implements hook_field_build_modes(). - */ -function user_field_build_modes($obj_type) { - $modes = array(); - if ($obj_type == 'user') { - $modes = array( - 'full' => t('User account'), - ); - } - return $modes; -} - /** * Implements hook_field_extra_fields(). */ @@ -2129,15 +2121,15 @@ function _user_cancel($edit, $account, $method) { * * @param $account * A user object. - * @param $build_mode - * Build mode, e.g. 'full'. + * @param $view_mode + * View mode, e.g. 'full'. * * @return * An array as expected by drupal_render(). */ -function user_view($account, $build_mode = 'full') { +function user_view($account, $view_mode = 'full') { // Retrieve all profile fields and attach to $account->content. - user_build_content($account, $build_mode); + user_build_content($account, $view_mode); $build = $account->content; // We don't need duplicate rendering info in account->content. @@ -2146,7 +2138,7 @@ function user_view($account, $build_mode = 'full') { $build += array( '#theme' => 'user_profile', '#account' => $account, - '#build_mode' => $build_mode, + '#view_mode' => $view_mode, ); // Allow modules to modify the structured user. @@ -2160,19 +2152,19 @@ function user_view($account, $build_mode = 'full') { * * @param $account * A user object. - * @param $build_mode - * Build mode, e.g. 'full'. + * @param $view_mode + * View mode, e.g. 'full'. */ -function user_build_content($account, $build_mode = 'full') { +function user_build_content($account, $view_mode = 'full') { // Remove previously built content, if exists. $account->content = array(); // Build fields content. - field_attach_prepare_view('user', array($account->uid => $account), $build_mode); - $account->content += field_attach_view('user', $account, $build_mode); + field_attach_prepare_view('user', array($account->uid => $account), $view_mode); + $account->content += field_attach_view('user', $account, $view_mode); // Populate $account->content with a render() array. - module_invoke_all('user_view', $account, $build_mode); + module_invoke_all('user_view', $account, $view_mode); } /**