summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-12-26 16:50:09 +0000
committerDries Buytaert <dries@buytaert.net>2009-12-26 16:50:09 +0000
commit53748ab5e24de5e33e9cf115e91a5845daa2ecbd (patch)
tree6a2c0c9d2f933ef6d112db66a4655ce0f557126a /modules
parenta838c8be49ed46f9ffb911113c55f9944ae7f952 (diff)
downloadbrdo-53748ab5e24de5e33e9cf115e91a5845daa2ecbd.tar.gz
brdo-53748ab5e24de5e33e9cf115e91a5845daa2ecbd.tar.bz2
- Patch #664544 by yched: clean-up entity build/view modes.
Diffstat (limited to 'modules')
-rw-r--r--modules/blog/blog.module6
-rw-r--r--modules/book/book.module29
-rw-r--r--modules/comment/comment.api.php2
-rw-r--r--modules/comment/comment.module49
-rw-r--r--modules/field/field.api.php12
-rw-r--r--modules/field/field.attach.inc22
-rw-r--r--modules/field/field.crud.inc28
-rw-r--r--modules/field/field.default.inc14
-rw-r--r--modules/field/field.info.inc16
-rw-r--r--modules/field/field.module30
-rw-r--r--modules/field/tests/field.test29
-rw-r--r--modules/field/tests/field_test.entity.inc25
-rw-r--r--modules/field/theme/field.tpl.php2
-rw-r--r--modules/field_ui/field_ui.admin.inc35
-rw-r--r--modules/field_ui/field_ui.module38
-rw-r--r--modules/forum/forum.module2
-rw-r--r--modules/locale/locale.field.inc2
-rw-r--r--modules/locale/locale.test4
-rw-r--r--modules/node/node.api.php18
-rw-r--r--modules/node/node.module102
-rw-r--r--modules/node/node.test6
-rw-r--r--modules/node/node.tpl.php4
-rw-r--r--modules/node/tests/node_test.module6
-rw-r--r--modules/poll/poll.module6
-rw-r--r--modules/statistics/statistics.module4
-rw-r--r--modules/system/system.api.php11
-rw-r--r--modules/taxonomy/taxonomy.module21
-rw-r--r--modules/translation/translation.module2
-rw-r--r--modules/trigger/trigger.module4
-rw-r--r--modules/user/user.api.php8
-rw-r--r--modules/user/user.module40
31 files changed, 277 insertions, 300 deletions
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index 712eb9050..2b0e3c55a 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 496b68afe..4361c7eb7 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 1eb3a891e..0d2c17d76 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 c4554d91a..93aad8e73 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 4aec48407..52000d922 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) {
@@ -1579,16 +1579,6 @@ function hook_field_read_instance($instance) {
**********************************************************************/
/**
- * 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.
*
* @param $op
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index ef26af253..052d22811 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -143,7 +143,7 @@ define('FIELD_STORAGE_INSERT', 'insert');
* 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 9ccf55488..8b8273ee9 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 f26f46ba3..3bd5f10f9 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 520f012a0..8c71418c9 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 f4dba7cbe..0f44c99b0 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -368,18 +368,6 @@ function _field_sort_items_value_helper($a, $b) {
}
/**
- * 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.
*
* @param $bundle_name
@@ -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 b148f31c8..f4ba5a8cc 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 fec43fcdf..0a15bccb6 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,
),
);
}
@@ -110,20 +121,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.
*/
function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle') {
diff --git a/modules/field/theme/field.tpl.php b/modules/field/theme/field.tpl.php
index 069ed48fa..ee4d5142c 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 1907e3126..9143e99f4 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 18275dd4d..b24ef7776 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 2ee98f936..085a4bc9c 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 3ad4672ff..45a94bcfe 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 10f60109c..b6306399f 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 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' => '<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 554d62d24..45df576a3 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 bcb476d76..810564fc1 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 db3c45485..57ad53536 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 f886366a6..5c63fc057 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) {
@@ -179,21 +185,6 @@ function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = arr
}
/**
- * 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().
*/
function taxonomy_theme() {
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 24cd021ac..937f66364 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 939218fcd..4d8190bba 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 72608ecfa..481002b41 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 432f936b9..9767c3288 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -142,25 +142,17 @@ 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().
*/
function user_field_extra_fields($bundle) {
@@ -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);
}
/**