Commit daa0ec16 authored by Dries's avatar Dries

- Patch #367215 by yched, sun et al: remove 'exclude from ' display setting. Feel good moment!

parent 48d3eff2
......@@ -901,17 +901,6 @@ function field_attach_view($obj_type, $object, $build_mode = 'full') {
}
/**
* To be called in entity preprocessor.
*
* - Adds $FIELD_NAME_rendered variables
* containing the themed output for the whole field.
* - Adds the formatted values in the 'view' key of the items.
*/
function field_attach_preprocess($obj_type, $object) {
return _field_invoke_default('preprocess', $obj_type, $object);
}
/**
* Implement hook_node_prepare_translation.
*
......
......@@ -145,8 +145,6 @@
* - label (string)
* Position of the label. 'inline', 'above' and 'hidden' are the
* values recognized by the default 'field' theme implementation.
* - exclude (integer)
* TODO This is subject to change, see: http://drupal.org/node/367215
* - type (string)
* The type of the display formatter to use for the field in
* this context.
......@@ -405,8 +403,6 @@ function field_delete_field($field_name) {
* Settings for the 'full' build mode will be added, and each build mode
* will be completed with the follwong default values:
* - label: 'above'
* - exclude: FALSE
* TODO This is subject to change, see: http://drupal.org/node/367215
* - type: the default formatter specified in hook_field_info().
* - settings: each omitted setting is given the default value specified in
* hook_field_formatter_info().
......@@ -540,7 +536,6 @@ function _field_write_instance($instance, $update = FALSE) {
foreach ($instance['display'] as $context => $display) {
$instance['display'][$context] += array(
'label' => 'above',
'exclude' => 0,
// TODO: what if no 'default_formatter' specified ?
'type' => $field_type['default_formatter'],
'settings' => array(),
......
......@@ -70,7 +70,7 @@ function field_default_insert($obj_type, $object, $field, $instance, &$items) {
* designated as such in formatter_info().
*
* The $object array will look like:
* $object->content['field_foo']['wrapper'] = array(
* $object->content['field_foo'] = array(
* '#theme' => 'field',
* '#title' => 'label'
* '#field_name' => 'field_name',
......@@ -141,6 +141,7 @@ function field_default_view($obj_type, $object, $field, $instance, $items, $buil
$element = $info + array(
'#theme' => 'field',
'#weight' => $instance['weight'],
'#title' => check_plain(t($instance['label'])),
'#access' => field_access('view', $field),
'#label_display' => $label_display,
......@@ -175,66 +176,11 @@ function field_default_view($obj_type, $object, $field, $instance, $items, $buil
$element['items'] += $format_info;
}
// The wrapper lets us get the themed output for the whole field
// to populate the $FIELD_NAME_rendered variable for templates,
// and hide it from the $content variable if needed.
// See 'preprocess' op and theme_content_field_wrapper().
$wrapper = $info + array(
'field' => $element,
'#weight' => $instance['weight'],
'#post_render' => array('field_wrapper_post_render'),
'#build_mode' => $build_mode,
);
$addition = array($field['field_name'] => $wrapper);
$addition = array($field['field_name'] => $element);
}
return $addition;
}
/**
* Hide excluded fields from the $content variable in templates.
*/
function field_wrapper_post_render($content, $element) {
$instance = field_info_instance($element['#field_name'], $element['#bundle']);
if (theme('field_exclude', $content, $instance, $element['#build_mode'])) {
return '';
}
return $content;
}
/**
* 'Theme' function for a field's addition to the combined template output,
* i.e. the node's $content or the user's $user_profile value.
* This allows more flexibility in templates : you can use custom markup
* around a few specific fields, and print the rest normally.
*
* This is a theme function, so it can be overridden in different
* themes to produce different results.
*
* The html for individual fields are available in the $FIELD_NAME_rendered
* variables.
*
* @return
* Whether or not the field's content is to be added in this context.
* Uses the 'exclude' value from the field's display settings.
*/
function theme_field_exclude($content, $object, $build_mode) {
if (empty($object['display'])
|| empty($object['display'][$build_mode])
|| empty($object['display'][$build_mode]['exclude'])) {
return FALSE;
}
else {
return TRUE;
}
}
function field_default_preprocess($obj_type, $object, $field, $instance, &$items) {
return array(
$field['field_name'] . '_rendered' => isset($object->content[$field['field_name']]['#children']) ? $object->content[$field['field_name']]['#children'] : '',
);
}
function field_default_prepare_translation($obj_type, $object, $field, $instance, &$items) {
$addition = array();
if (isset($object->translation_source->$field['field_name'])) {
......
......@@ -169,13 +169,6 @@ function field_theme() {
'arguments' => array('element' => NULL),
'path' => $path,
),
// TODO D7 : do we need exclude in core? See [#367215].
// This is just adding '#post_render' => array('field_wrapper_post_render')
// at the right places in the render array generated by field_default_view().
// Can be done in hook_field_attach_post_view if we want.
'field_exclude' => array(
'arguments' => array('content' => NULL, 'object' => array(), 'context' => NULL),
),
'field_multiple_value_form' => array(
'arguments' => array('element' => NULL),
),
......@@ -511,9 +504,7 @@ function field_view_field($obj_type, $object, $field, $instance, $build_mode = '
$view = field_default_view($obj_type, $object, $field, $instance, $items, $build_mode);
// TODO : what about hook_field_attach_view ?
// field_default_view() adds a wrapper to handle variables and 'excluded'
// fields for node templates. We bypass it and return the actual field.
$output = $view[$field['field_name']]['field'];
$output = $view[$field['field_name']];
}
return $output;
}
......
......@@ -491,18 +491,11 @@ class FieldAttachTestCase extends DrupalWebTestCase {
field_update_instance($this->instance);
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$variables = field_attach_preprocess($entity_type, $entity);
$variable = $this->instance['field_name'] . '_rendered';
$this->assertTrue(isset($variables[$variable]), "Variable $variable is available in templates.");
$this->content = $output;
$this->assertRaw($this->instance['label'], "Label is displayed.");
$this->content = $variables[$variable];
$this->assertRaw($this->instance['label'], "Label is displayed (template variable).");
foreach ($values as $delta => $value) {
$this->content = $output;
$this->assertRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
$this->content = $variables[$variable];
$this->assertRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied (template variable).");
}
// Label hidden.
......@@ -510,11 +503,8 @@ class FieldAttachTestCase extends DrupalWebTestCase {
field_update_instance($this->instance);
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$variables = field_attach_preprocess($entity_type, $entity);
$this->content = $output;
$this->assertNoRaw($this->instance['label'], "Hidden label: label is not displayed.");
$this->content = $variables[$variable];
$this->assertNoRaw($this->instance['label'], "Hidden label: label is not displayed (template variable).");
// Field hidden.
$this->instance['display'] = array(
......@@ -526,8 +516,6 @@ class FieldAttachTestCase extends DrupalWebTestCase {
field_update_instance($this->instance);
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$variables = field_attach_preprocess($entity_type, $entity);
$this->assertTrue(isset($variables[$variable]), "Hidden field: variable $variable is available in templates.");
$this->content = $output;
$this->assertNoRaw($this->instance['label'], "Hidden field: label is not displayed.");
foreach ($values as $delta => $value) {
......@@ -548,18 +536,14 @@ class FieldAttachTestCase extends DrupalWebTestCase {
field_update_instance($this->instance);
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$variables = field_attach_preprocess($entity_type, $entity);
$display = $formatter_setting;
foreach ($values as $delta => $value) {
$display .= "|$delta:{$value['value']}";
}
$this->content = $output;
$this->assertRaw($display, "Multiple formatter: all values are displayed, formatter settings are applied.");
$this->content = $variables[$variable];
$this->assertRaw($display, "Multiple formatter: all values are displayed, formatter settings are applied (template variable).");
// TODO:
// - check that the 'exclude' option works (if we keep it in core)
// - check display order with several fields
}
......
......@@ -478,15 +478,13 @@ function node_configure_fields($type) {
'full' => array(
'label' => 'hidden',
'type' => 'text_default',
'exclude' => 0,
),
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
'exclude' => 0,
),
),
);
),
);
field_create_instance($instance);
}
else {
......@@ -1251,10 +1249,6 @@ function template_preprocess_node(&$variables) {
// Clean up name so there are no underscores.
$variables['template_files'][] = 'node-' . str_replace('_', '-', $node->type);
$variables['template_files'][] = 'node-' . $node->nid;
// Add $FIELD_NAME_rendered variables for fields.
drupal_function_exists('field_attach_preprocess');
$variables += field_attach_preprocess('node', $node);
}
/**
......
......@@ -7,9 +7,9 @@
*
* Available variables:
* - $title: the (sanitized) title of the node.
* - $content: An array of node items. Use render($content) to print them all, or
* print a subset such as render($content['field_example']). Use
* hide($content['field_example]) to temporarily suppress the printing of a
* - $content: An array of node items. Use render($content) to print them all, or
* print a subset such as render($content['field_example']). Use
* hide($content['field_example]) to temporarily suppress the printing of a
* given element.
* - $comments: the themed list of comments (if any).
* - $picture: The authors picture of the node output from
......@@ -36,7 +36,6 @@
* - node-promoted: Nodes promoted to the front page.
* - node-sticky: Nodes ordered above other non-sticky nodes in teaser listings.
* - node-unpublished: Unpublished nodes visible only to administrators.
* TODO D7 : document $FIELD_NAME_rendered variables.
*
* Other variables:
* - $node: Full node object. Contains data that may not be safe.
......
......@@ -23,7 +23,6 @@
*
* Available variables:
* - $user_profile: An array of profile items. Use render() to print them.
* - TODO D7 : document $FIELD_NAME_rendered variables.
*
* @see template_preprocess_user_profile()
*/
......
......@@ -190,9 +190,6 @@ function user_view($account) {
function template_preprocess_user_profile(&$variables) {
$account = $variables['elements']['#account'];
$variables['user_profile'] = $account->content;
// Add $FIELD_NAME_rendered variables for fields.
$variables += field_attach_preprocess('user', $account);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment