diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2011-01-28 07:38:47 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2011-01-28 07:38:47 +0000 |
commit | 1a7a0810dd712d012719fe888017ff452430ff5b (patch) | |
tree | 4f03b743af30fc710a60b14ff9f350cb7f480dd4 /modules | |
parent | 61472dcdfb81df12d06e8f6cfef239769cbff59d (diff) | |
download | brdo-1a7a0810dd712d012719fe888017ff452430ff5b.tar.gz brdo-1a7a0810dd712d012719fe888017ff452430ff5b.tar.bz2 |
#934726 by yched, jinglemansweep: Fixed Undefined index: taxonomy_term in taxonomy_field_formatter_view()
Diffstat (limited to 'modules')
-rw-r--r-- | modules/field/field.default.inc | 12 | ||||
-rw-r--r-- | modules/field/tests/field.test | 49 |
2 files changed, 57 insertions, 4 deletions
diff --git a/modules/field/field.default.inc b/modules/field/field.default.inc index e2f012c8c..0a5fe6c86 100644 --- a/modules/field/field.default.inc +++ b/modules/field/field.default.inc @@ -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]; } diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index 817cdcdf8..231e57941 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -763,6 +763,55 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase { } /** + * 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. */ function testFieldAttachCache() { |