Commit 1a7a0810 authored by webchick's avatar webchick

#934726 by yched, jinglemansweep: Fixed Undefined index: taxonomy_term in...

#934726 by yched, jinglemansweep: Fixed Undefined index: taxonomy_term in taxonomy_field_formatter_view()
parent 61472dcd
......@@ -142,14 +142,18 @@ function field_default_prepare_view($entity_type, $entities, $field, $instances,
foreach ($instances as $id => $instance) {
if (is_string($display)) {
$view_mode = $display;
$display = field_get_display($instance, $view_mode, $entities[$id]);
$instance_display = field_get_display($instance, $view_mode, $entities[$id]);
}
if ($display['type'] !== 'hidden') {
$module = $display['module'];
else {
$instance_display = $display;
}
if ($instance_display['type'] !== 'hidden') {
$module = $instance_display['module'];
$modules[$module] = $module;
$grouped_entities[$module][$id] = $entities[$id];
$grouped_instances[$module][$id] = $instance;
$grouped_displays[$module][$id] = $display;
$grouped_displays[$module][$id] = $instance_display;
// hook_field_formatter_prepare_view() alters $items by reference.
$grouped_items[$module][$id] = &$items[$id];
}
......
......@@ -762,6 +762,55 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
$this->assertTrue($result, t('Variable $@field_name correctly populated.', array('@field_name' => $this->field_name)));
}
/**
* Tests the 'multiple entity' behavior of field_attach_prepare_view().
*/
function testFieldAttachPrepareViewMultiple() {
$entity_type = 'test_entity';
$langcode = LANGUAGE_NONE;
// Set the instance to be hidden.
$this->instance['display']['full']['type'] = 'hidden';
field_update_instance($this->instance);
// Set up a second instance on another bundle, with a formatter that uses
// hook_field_formatter_prepare_view().
field_test_create_bundle('test_bundle_2');
$formatter_setting = $this->randomName();
$this->instance2 = $this->instance;
$this->instance2['bundle'] = 'test_bundle_2';
$this->instance2['display']['full'] = array(
'type' => 'field_test_with_prepare_view',
'settings' => array(
'test_formatter_setting_additional' => $formatter_setting,
)
);
field_create_instance($this->instance2);
// Create one entity in each bundle.
$entity1_init = field_test_create_stub_entity(1, 1, 'test_bundle');
$values1 = $this->_generateTestFieldValues($this->field['cardinality']);
$entity1_init->{$this->field_name}[$langcode] = $values1;
$entity2_init = field_test_create_stub_entity(2, 2, 'test_bundle_2');
$values2 = $this->_generateTestFieldValues($this->field['cardinality']);
$entity2_init->{$this->field_name}[$langcode] = $values2;
// Run prepare_view, and check that the entities come out as expected.
$entity1 = clone($entity1_init);
$entity2 = clone($entity2_init);
field_attach_prepare_view($entity_type, array($entity1->ftid => $entity1, $entity2->ftid => $entity2), 'full');
$this->assertFalse(isset($entity1->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 1 did not run through the prepare_view hook.');
$this->assertTrue(isset($entity2->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 2 ran through the prepare_view hook.');
// Same thing, reversed order.
$entity1 = clone($entity1_init);
$entity2 = clone($entity2_init);
field_attach_prepare_view($entity_type, array($entity2->ftid => $entity2, $entity1->ftid => $entity1), 'full');
$this->assertFalse(isset($entity1->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 1 did not run through the prepare_view hook.');
$this->assertTrue(isset($entity2->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 2 ran through the prepare_view hook.');
}
/**
* Test field cache.
*/
......
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