Commit 53748ab5 authored by Dries's avatar Dries

- Patch #664544 by yched: clean-up entity build/view modes.

parent a838c8be
......@@ -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');
}
/**
......
......@@ -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))),
......
......@@ -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);
}
}
......
......@@ -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;
}
......
......@@ -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);
}
}
/**
......
......@@ -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.
*
......
......@@ -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);
......
......@@ -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
......
......@@ -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'],
......
......@@ -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']);
......
......@@ -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'],
......
......@@ -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.
}
......
......@@ -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.
*/
......