Commit d0d18177 authored by alexpott's avatar alexpott

Issue #1822000 by Berdir, plach, amateescu, yched: Remove...

Issue #1822000 by Berdir, plach, amateescu, yched: Remove Drupal\field_test\Plugin\Entity\Type\TestEntity in favor of EntityTest.
parent 760292ee
......@@ -235,6 +235,13 @@ protected function getTranslatedField($property_name, $langcode) {
if (isset($this->values[$property_name][$langcode])) {
$value = $this->values[$property_name][$langcode];
}
// @todo Remove this once the BC decorator is gone.
elseif ($property_name != 'langcode') {
$default_langcode = $this->language()->langcode;
if ($langcode == Language::LANGCODE_DEFAULT && isset($this->values[$property_name][$default_langcode])) {
$value = $this->values[$property_name][$default_langcode];
}
}
$this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
}
}
......
......@@ -900,16 +900,9 @@ function field_attach_update(EntityInterface $entity) {
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['uuid'];
$field_name = $field['field_name'];
// Leave the field untouched if $entity comes with no $field_name property,
// but empty the field if it comes as a NULL value or an empty array.
// Function property_exists() is slower, so we catch the more frequent
// cases where it's an empty array with the faster isset().
if (isset($entity->$field_name) || property_exists($entity, $field_name)) {
// Collect the storage backend if the field has not been written yet.
if (!isset($skip_fields[$field_id])) {
$storages[$field['storage']['type']][$field_id] = $field_id;
}
// Collect the storage backend if the field has not been written yet.
if (!isset($skip_fields[$field_id])) {
$storages[$field['storage']['type']][$field_id] = $field_id;
}
}
......
......@@ -657,6 +657,9 @@ function _field_filter_xss_display_allowed_tags() {
function field_view_value(EntityInterface $entity, $field_name, $item, $display = array(), $langcode = NULL) {
$output = array();
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
if ($field = field_info_field($field_name)) {
// Determine the langcode that will be used by language fallback.
$langcode = field_language($entity, $field_name, $langcode);
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
......@@ -59,36 +60,6 @@ public static function getInfo() {
);
}
/**
* Converts the passed entities to partially created ones.
*
* This replicates the partial entities created in field_purge_data_batch(),
* which only have the ids and the to be deleted field defined.
*
* @param $entities
* An array of entities of type test_entity.
* @param $field_name
* A field name whose data should be copied from $entities into the returned
* partial entities.
* @return array An array of partial entities corresponding to $entities.
*/
protected function convertToPartialEntities($entities, $field_name) {
$partial_entities = array();
foreach ($entities as $id => $entity) {
// Re-create the entity to match what is expected
// _field_create_entity_from_ids().
$ids = (object) array(
'entity_id' => $entity->ftid,
'revision_id' => $entity->ftvid,
'bundle' => $entity->fttype,
'entity_type' => 'test_entity',
);
$partial_entities[$id] = _field_create_entity_from_ids($ids);
$partial_entities[$id]->$field_name = $entity->$field_name;
}
return $partial_entities;
}
/**
* Tests that the expected hooks have been invoked on the expected entities.
*
......@@ -110,8 +81,15 @@ function checkHooksInvocations($expected_hooks, $actual_hooks) {
foreach ($invocations as $argument) {
$found = FALSE;
foreach ($actual_invocations as $actual_arguments) {
// $entity is sometimes the first and sometimes the second argument.
if ($actual_arguments[0] == $argument || $actual_arguments[1] == $argument) {
// The argument we are looking for is either an array of entities as
// the second argument or a single entity object as the first.
if ($argument instanceof EntityInterface && $actual_arguments[0]->id() == $argument->id()) {
$found = TRUE;
break;
}
// In case of an array, compare the array size and make sure it
// contains the same elements.
elseif (is_array($argument) && count($actual_arguments[1]) == count($argument) && count(array_diff_key($actual_arguments[1], $argument)) == 0) {
$found = TRUE;
break;
}
......@@ -131,7 +109,7 @@ function setUp() {
// Create two bundles.
$this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
foreach ($this->bundles as $name => $desc) {
field_test_create_bundle($name, $desc);
entity_test_create_bundle($name, $desc);
}
// Create two fields.
......@@ -152,7 +130,7 @@ function setUp() {
// For each bundle, create an instance of each field, and 10
// entities with values for each field.
$id = 1;
$this->entity_type = 'entity_test';
foreach ($this->bundles as $bundle) {
foreach ($this->fields as $field) {
entity_create('field_instance', array(
......@@ -161,20 +139,18 @@ function setUp() {
'bundle' => $bundle,
))->save();
}
for ($i = 0; $i < 10; $i++) {
$entity = field_test_create_entity($id, $id, $bundle);
$entity = entity_create($this->entity_type, array('type' => $bundle));
foreach ($this->fields as $field) {
$entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field->cardinality);
$entity->{$field['field_name']}->setValue($this->_generateTestFieldValues($field->cardinality));
}
$entity->save();
$id++;
}
}
$this->entities = entity_load_multiple($this->entity_type, range(1, $id));
$this->entities = entity_load_multiple($this->entity_type);
foreach ($this->entities as $entity) {
// Also keep track of the entities per bundle.
$this->entities_by_bundles[$entity->fttype][$entity->ftid] = $entity;
$this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity;
}
}
......@@ -193,8 +169,8 @@ function testDeleteFieldInstance() {
$factory = \Drupal::service('entity.query');
// There are 10 entities of this bundle.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->execute();
$this->assertEqual(count($found), 10, 'Correct number of entities found before deleting');
......@@ -209,21 +185,21 @@ function testDeleteFieldInstance() {
$this->assertEqual($instance['bundle'], $bundle, 'The deleted instance is for the correct bundle');
// There are 0 entities of this bundle with non-deleted data.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->condition("$field_name.deleted", 0)
->execute();
$this->assertFalse($found, 'No entities found after deleting');
// There are 10 entities of this bundle when deleted fields are allowed, and
// their values are correct.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->condition("$field_name.deleted", 1)
->sort('ftid')
->sort('id')
->execute();
$ids = (object) array(
'entity_type' => 'test_entity',
'entity_type' => 'entity_test',
'bundle' => $bundle,
);
$entities = array();
......@@ -234,7 +210,7 @@ function testDeleteFieldInstance() {
field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('instance' => $instance));
$this->assertEqual(count($found), 10, 'Correct number of entities found after deleting');
foreach ($entities as $id => $entity) {
$this->assertEqual($this->entities[$id]->{$field->id()}, $entity->{$field->id()}, "Entity $id with deleted data loaded correctly");
$this->assertEqual($this->entities[$id]->{$field->id()}->value, $entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Entity $id with deleted data loaded correctly");
}
}
......@@ -263,8 +239,8 @@ function testPurgeInstance() {
field_purge_batch($batch_size);
// There are $count deleted entities left.
$found = \Drupal::entityQuery('test_entity')
->condition('fttype', $bundle)
$found = \Drupal::entityQuery('entity_test')
->condition('type', $bundle)
->condition($field->id() . '.deleted', 1)
->execute();
$this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2');
......@@ -275,7 +251,7 @@ function testPurgeInstance() {
// for each entity in the bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......@@ -325,7 +301,7 @@ function testPurgeField() {
// for each entity in the bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......@@ -354,7 +330,7 @@ function testPurgeField() {
// Check hooks invocations (same as above, for the 2nd bundle).
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......
......@@ -139,11 +139,11 @@ function testCreateField() {
}
// Check that field name can not be an entity key.
// "ftvid" is known as an entity key from the "test_entity" type.
// "id" is known as an entity key from the "entity_test" type.
try {
$field_definition = array(
'type' => 'test_field',
'field_name' => 'ftvid',
'field_name' => 'id',
);
entity_create('field_entity', $field_definition)->save();
$this->fail(t('Cannot create a field bearing the name of an entity key.'));
......@@ -216,8 +216,8 @@ function testReadFields() {
// Create an instance of the field.
$instance_definition = array(
'field_name' => $field_definition['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
entity_create('field_instance', $instance_definition)->save();
}
......@@ -283,8 +283,8 @@ function testDeleteField() {
// Create instances for each.
$this->instance_definition = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
entity_create('field_instance', $this->instance_definition)->save();
$another_instance_definition = $this->instance_definition;
......@@ -303,7 +303,7 @@ function testDeleteField() {
// Make sure that this field's instance is marked as deleted when it is
// specifically loaded.
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance['deleted']), 'An instance for a deleted field is marked for deletion.');
// Try to load the field normally and make sure it does not show up.
......@@ -311,13 +311,13 @@ function testDeleteField() {
$this->assertTrue(empty($field), 'A deleted field is not loaded by default.');
// Try to load the instance normally and make sure it does not show up.
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.');
// Make sure the other field (and its field instance) are not deleted.
$another_field = field_read_field($this->another_field['field_name']);
$this->assertTrue(!empty($another_field) && empty($another_field['deleted']), 'A non-deleted field is not marked for deletion.');
$another_instance = field_read_instance('test_entity', $another_instance_definition['field_name'], $another_instance_definition['bundle']);
$another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $another_instance_definition['bundle']);
$this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), 'An instance of a non-deleted field is not marked for deletion.');
// Try to create a new field the same name as a deleted field and
......@@ -326,23 +326,22 @@ function testDeleteField() {
entity_create('field_instance', $this->instance_definition)->save();
$field = field_read_field($this->field['field_name']);
$this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field with a previously used name is created.');
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(!empty($instance) && empty($instance['deleted']), 'A new instance for a previously used field name is created.');
// Save an entity with data for the field
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$entity = entity_create('entity_test', array('id' => 0, 'revision_id' => 0));
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field['field_name']}[$langcode] = $values;
$entity_type = 'test_entity';
$entity->{$field['field_name']}->value = $values[0]['value'];
field_attach_insert($entity);
// Verify the field is present on load
$entity = field_test_create_entity(0, 0, $this->instance_definition['bundle']);
field_attach_load($entity_type, array(0 => $entity));
$this->assertIdentical(count($entity->{$field['field_name']}[$langcode]), count($values), "Data in previously deleted field saves and loads correctly");
$entity = entity_create('entity_test', array('id' => 0, 'revision_id' => 0));
field_attach_load('entity_test', array(0 => $entity));
$this->assertIdentical(count($entity->{$field['field_name']}), count($values), "Data in previously deleted field saves and loads correctly");
foreach ($values as $delta => $value) {
$this->assertEqual($entity->{$field['field_name']}[$langcode][$delta]['value'], $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
$this->assertEqual($entity->{$field['field_name']}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
}
}
......@@ -377,28 +376,28 @@ function testUpdateField() {
$field->save();
$instance = entity_create('field_instance', array(
'field_name' => 'field_update',
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
));
$instance->save();
do {
// We need a unique ID for our entity. $cardinality will do.
$id = $cardinality;
$entity = field_test_create_entity($id, $id, $instance->bundle);
$entity = entity_create('entity_test', array('id' => $id, 'revision_id' => $id));
// Fill in the entity with more values than $cardinality.
for ($i = 0; $i < 20; $i++) {
$entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$i]['value'] = $i;
$entity->field_update[$i]->value = $i;
}
// Save the entity.
field_attach_insert($entity);
// Load back and assert there are $cardinality number of values.
$entity = field_test_create_entity($id, $id, $instance->bundle);
field_attach_load('test_entity', array($id => $entity));
$this->assertEqual(count($entity->field_update[Language::LANGCODE_NOT_SPECIFIED]), $field->cardinality, 'Cardinality is kept');
$entity = entity_create('entity_test', array('id' => $id, 'revision_id' => $id));
field_attach_load('entity_test', array($id => $entity));
$this->assertEqual(count($entity->field_update), $field->cardinality, 'Cardinality is kept');
// Now check the values themselves.
for ($delta = 0; $delta < $cardinality; $delta++) {
$this->assertEqual($entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$delta]['value'], $delta, 'Value is kept');
$this->assertEqual($entity->field_update[$delta]->value, $delta, 'Value is kept');
}
// Increase $cardinality and set the field cardinality to the new value.
$field->cardinality = ++$cardinality;
......
......@@ -40,7 +40,7 @@ class DisplayApiTest extends FieldUnitTestBase {
protected $display_options;
/**
* The field display options to use in this test.
* The test entity.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
......@@ -76,8 +76,8 @@ function setUp() {
);
$instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->label,
);
......@@ -109,10 +109,9 @@ function setUp() {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = field_test_create_entity();
$this->is_new = TRUE;
$this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = $this->values;
field_test_entity_save($this->entity);
$this->entity = entity_create('entity_test', array());
$this->entity->{$this->field_name}->setValue($this->values);
$this->entity->save();
}
/**
......@@ -197,7 +196,7 @@ function testFieldViewValue() {
$settings = field_info_formatter_settings('field_test_default');
$setting = $settings['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item);
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -213,7 +212,7 @@ function testFieldViewValue() {
$setting = $display['settings']['test_formatter_setting_multiple'];
$array = array();
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, $display);
$this->content = drupal_render($output);
$this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -229,7 +228,7 @@ function testFieldViewValue() {
$setting = $display['settings']['test_formatter_setting_additional'];
$array = array();
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, $display);
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -239,7 +238,7 @@ function testFieldViewValue() {
// used.
$setting = $this->display_options['teaser']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, 'teaser');
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -249,7 +248,7 @@ function testFieldViewValue() {
// are used.
$setting = $this->display_options['default']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, 'unknown_view_mode');
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -278,8 +277,8 @@ function testFieldEmpty() {
$this->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = array();
field_test_entity_save($this->entity);
$this->entity->{$this->field_name} = array();
$this->entity->save();
$output = field_view_field($this->entity, $this->field_name, $display);
$view = drupal_render($output);
$this->content = $view;
......
......@@ -47,16 +47,16 @@ public function setUp() {
function testFieldAttachView() {
$this->createFieldWithInstance('_2');
$entity_type = 'test_entity';
$entity_init = field_test_create_entity();
$entity_type = 'entity_test';
$entity_init = entity_create($entity_type, array());
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$options = array('field_name' => $this->field_name_2);
// Populate values to be displayed.
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity_init->{$this->field_name}[$langcode] = $values;
$entity_init->{$this->field_name}->setValue($values);
$values_2 = $this->_generateTestFieldValues($this->field_2['cardinality']);
$entity_init->{$this->field_name_2}[$langcode] = $values_2;
$entity_init->{$this->field_name_2}->setValue($values_2);
// Simple formatter, label displayed.
$entity = clone($entity_init);
......@@ -84,9 +84,9 @@ function testFieldAttachView() {
$display->setComponent($this->field_2['field_name'], $display_options_2);
// View all fields.
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays);
$entity->content = field_attach_view($entity, $display);
$output = drupal_render($entity->content);
field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays);
$content = field_attach_view($entity, $display);
$output = drupal_render($content);
$this->content = $output;
$this->assertRaw($this->instance['label'], "First field's label is displayed.");
foreach ($values as $delta => $value) {
......@@ -103,7 +103,7 @@ function testFieldAttachView() {
$entity = clone($entity_init);
$display_options['label'] = 'hidden';
$display->setComponent($this->field['field_name'], $display_options);
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays);
field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays);
$entity->content = field_attach_view($entity, $display);
$output = drupal_render($entity->content);
$this->content = $output;
......@@ -112,7 +112,7 @@ function testFieldAttachView() {
// Field hidden.
$entity = clone($entity_init);
$display->removeComponent($this->field['field_name']);
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays);
field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays);
$entity->content = field_attach_view($entity, $display);
$output = drupal_render($entity->content);
$this->content = $output;
......@@ -131,7 +131,7 @@ function testFieldAttachView() {
'test_formatter_setting_multiple' => $formatter_setting,
),
));
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays);
field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays);
$entity->content = field_attach_view($entity, $display);
$output = drupal_render($entity->content);
$expected_output = $formatter_setting;
......@@ -151,7 +151,7 @@ function testFieldAttachView() {
'test_formatter_setting_additional' => $formatter_setting,
),
));
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays);
field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays);
$entity->content = field_attach_view($entity, $display);
$output = drupal_render($entity->content);
$this->content = $output;
......@@ -180,23 +180,22 @@ function testFieldAttachView() {
* Tests the 'multiple entity' behavior of field_attach_prepare_view().
*/
function testFieldAttachPrepareViewMultiple() {
$entity_type = 'test_entity';
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$entity_type = 'entity_test';
// Set the instance to be hidden.
$display = entity_get_display('test_entity', 'test_bundle', 'full')
$display = entity_get_display('entity_test', 'entity_test', 'full')
->removeComponent($this->field['field_name']);
// 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');
entity_test_create_bundle('test_bundle_2');
$formatter_setting = $this->randomName();
$instance_definition = $this->instance_definition;
$instance_definition['bundle'] = 'test_bundle_2';
$this->instance2 = entity_create('field_instance', $instance_definition);
$this->instance2->save();
$display_2 = entity_get_display('test_entity', 'test_bundle_2', 'full')
$display_2 = entity_get_display('entity_test', 'test_bundle_2', 'full')
->setComponent($this->field['field_name'], array(
'type' => 'field_test_with_prepare_view',
'settings' => array(
......@@ -204,32 +203,32 @@ function testFieldAttachPrepareViewMultiple() {
),
));
$displays = array('test_bundle' => $display, 'test_bundle_2' => $display_2);
$displays = array('entity_test' => $display, 'test_bundle_2' => $display_2);
// Create one entity in each bundle.
$entity1_init = field_test_create_entity(1, 1, 'test_bundle');
$entity1_init = entity_create('entity_test', array('id' => 1, 'type' => 'entity_test'));
$values1 = $this->_generateTestFieldValues($this->field['cardinality']);
$entity1_init->{$this->field_name}[$langcode] = $values1;
$entity1_init->{$this->field_name}->setValue($values1);
$entity2_init = field_test_create_entity(2, 2, 'test_bundle_2');
$entity2_init = entity_create('entity_test', array('id' => 2, 'type' =>