Commit ba6591cd authored by catch's avatar catch

Issue #2018319 by yched, swentel, pcambra: Remove field_read_field(s)() and...

Issue #2018319 by yched, swentel, pcambra: Remove field_read_field(s)() and field_read_instance(s) in favor of entity_load() and entity_load_multiple_by_properties().
parent 255d7304
...@@ -1185,7 +1185,7 @@ public function onBundleRename($bundle, $bundle_new) { ...@@ -1185,7 +1185,7 @@ public function onBundleRename($bundle, $bundle_new) {
// We need to account for deleted fields and instances. The method runs // We need to account for deleted fields and instances. The method runs
// before the instance definitions are updated, so we need to fetch them // before the instance definitions are updated, so we need to fetch them
// using the old bundle name. // using the old bundle name.
$instances = field_read_instances(array('entity_type' => $this->entityType, 'bundle' => $bundle), array('include_deleted' => TRUE)); $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $this->entityType, 'bundle' => $bundle, 'include_deleted' => TRUE));
foreach ($instances as $instance) { foreach ($instances as $instance) {
$field = $instance->getField(); $field = $instance->getField();
$table_name = static::_fieldTableName($field); $table_name = static::_fieldTableName($field);
......
...@@ -198,10 +198,8 @@ function field_info_field_map() { ...@@ -198,10 +198,8 @@ function field_info_field_map() {
* non-deleted field. For deleted fields, use field_info_field_by_id(). * non-deleted field. For deleted fields, use field_info_field_by_id().
* *
* @return * @return
* The field array, as returned by field_read_fields(), with an * The \Drupal\field\FieldInterface field definition, as returned by
* additional element 'bundles', whose value is an array of all the bundles * entity_load_multiple_by_properties(), NULL if the field was not found.
* this field belongs to keyed by entity type. NULL if the field was not
* found.
* *
* @see field_info_field_by_id() * @see field_info_field_by_id()
...@@ -219,9 +217,8 @@ function field_info_field($entity_type, $field_name) { ...@@ -219,9 +217,8 @@ function field_info_field($entity_type, $field_name) {
* The ID of the field to retrieve. $field_id can refer to a deleted field. * The ID of the field to retrieve. $field_id can refer to a deleted field.
* *
* @return * @return
* The field array, as returned by field_read_fields(), with an additional * The \Drupal\field\FieldInterface field definition, as returned by
* element 'bundles', whose value is an array of all the bundles this field * entity_load_multiple_by_properties(), NULL if the field was not found.
* belongs to.
* *
* @see field_info_field() * @see field_info_field()
* *
...@@ -239,13 +236,11 @@ function field_info_field_by_id($field_id) { ...@@ -239,13 +236,11 @@ function field_info_field_by_id($field_id) {
* statically caches a potentially large array of information. * statically caches a potentially large array of information.
* *
* When iterating over the fields present in a given bundle after a call to * When iterating over the fields present in a given bundle after a call to
* field_info_instances($entity_type, $bundle), it is recommended to use * field_info_instances($entity_type, $bundle), it is recommended to use the
* field_info_field() on each individual field instead. * getField() method on each $instance instead.
* *
* @return * @return \Drupal\field\FieldInterface[]
* An array, each key is a field ID and the values are field arrays as * An array of FieldInterface configuration entities, keyed by UUID.
* returned by field_read_fields(), with an additional element 'bundles',
* whose value is an array of all the bundle this field belongs to.
* *
* @see field_info_field() * @see field_info_field()
* @see field_info_field_by_id() * @see field_info_field_by_id()
......
...@@ -153,9 +153,10 @@ function field_cron() { ...@@ -153,9 +153,10 @@ function field_cron() {
* required if there are any active fields of that type. * required if there are any active fields of that type.
*/ */
function field_system_info_alter(&$info, $file, $type) { function field_system_info_alter(&$info, $file, $type) {
// It is not safe to call field_read_fields() during maintenance mode. // It is not safe to call entity_load_multiple_by_properties() during
// maintenance mode.
if ($type == 'module' && !defined('MAINTENANCE_MODE')) { if ($type == 'module' && !defined('MAINTENANCE_MODE')) {
$fields = field_read_fields(array('module' => $file->name), array('include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_entity', array('module' => $file->name, 'include_deleted' => TRUE));
if ($fields) { if ($fields) {
$info['required'] = TRUE; $info['required'] = TRUE;
...@@ -222,10 +223,10 @@ function field_entity_bundle_create($entity_type, $bundle) { ...@@ -222,10 +223,10 @@ function field_entity_bundle_create($entity_type, $bundle) {
* Implements hook_entity_bundle_rename(). * Implements hook_entity_bundle_rename().
*/ */
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
$instances = field_read_instances(); $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $entity_type, 'bundle' => $bundle_old));
foreach ($instances as $instance) { foreach ($instances as $instance) {
if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) { if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) {
$id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->getName(); $id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name;
$instance->id = $id_new; $instance->id = $id_new;
$instance->bundle = $bundle_new; $instance->bundle = $bundle_new;
$instance->allowBundleRename(); $instance->allowBundleRename();
...@@ -248,10 +249,10 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { ...@@ -248,10 +249,10 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
* simple DELETE query). * simple DELETE query).
*/ */
function field_entity_bundle_delete($entity_type, $bundle) { function field_entity_bundle_delete($entity_type, $bundle) {
// Get the instances on the bundle. field_read_instances() must be used // Get the instances on the bundle. entity_load_multiple_by_properties() must
// here since field_info_instances() does not return instances for disabled // be used here since field_info_instances() does not return instances for
// entity types or bundles. // disabled entity types or bundles.
$instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle)); $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $entity_type, 'bundle' => $bundle));
foreach ($instances as $instance) { foreach ($instances as $instance) {
$instance->delete(); $instance->delete();
} }
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
function field_purge_batch($batch_size) { function field_purge_batch($batch_size) {
// Retrieve all deleted field instances. We cannot use field_info_instances() // Retrieve all deleted field instances. We cannot use field_info_instances()
// because that function does not return deleted instances. // because that function does not return deleted instances.
$instances = field_read_instances(array('deleted' => TRUE), array('include_deleted' => TRUE)); $instances = entity_load_multiple_by_properties('field_instance', array('deleted' => TRUE, 'include_deleted' => TRUE));
$factory = \Drupal::service('entity.query'); $factory = \Drupal::service('entity.query');
$info = entity_get_info(); $info = entity_get_info();
foreach ($instances as $instance) { foreach ($instances as $instance) {
...@@ -130,7 +130,7 @@ function field_purge_batch($batch_size) { ...@@ -130,7 +130,7 @@ function field_purge_batch($batch_size) {
continue; continue;
} }
$instances = field_read_instances(array('field_id' => $field->uuid()), array('include_deleted' => 1)); $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid(), 'include_deleted' => TRUE));
if (empty($instances)) { if (empty($instances)) {
field_purge_field($field); field_purge_field($field);
} }
...@@ -169,7 +169,7 @@ function field_purge_instance($instance) { ...@@ -169,7 +169,7 @@ function field_purge_instance($instance) {
* The field record to purge. * The field record to purge.
*/ */
function field_purge_field($field) { function field_purge_field($field) {
$instances = field_read_instances(array('field_id' => $field->uuid()), array('include_deleted' => 1)); $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid(), 'include_deleted' => TRUE));
if (count($instances) > 0) { if (count($instances) > 0) {
throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field->getName()))); throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field->getName())));
} }
......
...@@ -231,7 +231,7 @@ public function getFields() { ...@@ -231,7 +231,7 @@ public function getFields() {
} }
else { else {
// Collect and prepare fields. // Collect and prepare fields.
foreach (field_read_fields(array(), array('include_deleted' => TRUE)) as $field) { foreach (entity_load_multiple_by_properties('field_entity', array('include_deleted' => TRUE)) as $field) {
$this->fieldsById[$field->uuid()] = $this->prepareField($field); $this->fieldsById[$field->uuid()] = $this->prepareField($field);
} }
...@@ -277,7 +277,7 @@ public function getInstances($entity_type = NULL) { ...@@ -277,7 +277,7 @@ public function getInstances($entity_type = NULL) {
// be set by subsequent getBundleInstances() calls. // be set by subsequent getBundleInstances() calls.
$this->getFields(); $this->getFields();
foreach (field_read_instances() as $instance) { foreach (entity_load_multiple('field_instance') as $instance) {
$instance = $this->prepareInstance($instance); $instance = $this->prepareInstance($instance);
$this->bundleInstances[$instance->entity_type][$instance->bundle][$instance->getName()] = $instance; $this->bundleInstances[$instance->entity_type][$instance->bundle][$instance->getName()] = $instance;
} }
...@@ -359,7 +359,7 @@ public function getFieldById($field_id) { ...@@ -359,7 +359,7 @@ public function getFieldById($field_id) {
// bundle. // bundle.
// Cache miss: read from definition. // Cache miss: read from definition.
if ($fields = field_read_fields(array('uuid' => $field_id), array('include_deleted' => TRUE))) { if ($fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field_id, 'include_deleted' => TRUE))) {
$field = current($fields); $field = current($fields);
$field = $this->prepareField($field); $field = $this->prepareField($field);
......
...@@ -164,8 +164,6 @@ public function loadByProperties(array $conditions = array()) { ...@@ -164,8 +164,6 @@ public function loadByProperties(array $conditions = array()) {
} }
} }
$this->moduleHandler->invokeAll('field_read_instance', $instance);
$matching_instances[] = $instance; $matching_instances[] = $instance;
} }
......
...@@ -138,8 +138,6 @@ public function loadByProperties(array $conditions = array()) { ...@@ -138,8 +138,6 @@ public function loadByProperties(array $conditions = array()) {
} }
} }
$this->moduleHandler->invokeAll('field_read_field', $field);
// When returning deleted fields, key the results by UUID since they can // When returning deleted fields, key the results by UUID since they can
// include several fields with the same ID. // include several fields with the same ID.
$key = $include_deleted ? $field->uuid : $field->id; $key = $include_deleted ? $field->uuid : $field->id;
......
...@@ -180,7 +180,7 @@ function testDeleteFieldInstance() { ...@@ -180,7 +180,7 @@ function testDeleteFieldInstance() {
$instance->delete(); $instance->delete();
// The instance still exists, deleted. // The instance still exists, deleted.
$instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE)); $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 1, 'There is one deleted instance'); $this->assertEqual(count($instances), 1, 'There is one deleted instance');
$instance = $instances[0]; $instance = $instances[0];
$this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle'); $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle');
...@@ -258,18 +258,18 @@ function testPurgeInstance() { ...@@ -258,18 +258,18 @@ function testPurgeInstance() {
$this->checkHooksInvocations($hooks, $actual_hooks); $this->checkHooksInvocations($hooks, $actual_hooks);
// The instance still exists, deleted. // The instance still exists, deleted.
$instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE)); $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 1, 'There is one deleted instance'); $this->assertEqual(count($instances), 1, 'There is one deleted instance');
// Purge the instance. // Purge the instance.
field_purge_batch($batch_size); field_purge_batch($batch_size);
// The instance is gone. // The instance is gone.
$instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE)); $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 0, 'The instance is gone'); $this->assertEqual(count($instances), 0, 'The instance is gone');
// The field still exists, not deleted, because it has a second instance. // The field still exists, not deleted, because it has a second instance.
$fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]), 'The field exists and is not deleted'); $this->assertTrue(isset($fields[$field->uuid]), 'The field exists and is not deleted');
} }
...@@ -310,7 +310,7 @@ function testPurgeField() { ...@@ -310,7 +310,7 @@ function testPurgeField() {
field_purge_batch(0); field_purge_batch(0);
// The field still exists, not deleted. // The field still exists, not deleted.
$fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted'); $this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted');
// Delete the second instance. // Delete the second instance.
...@@ -335,14 +335,14 @@ function testPurgeField() { ...@@ -335,14 +335,14 @@ function testPurgeField() {
$this->checkHooksInvocations($hooks, $actual_hooks); $this->checkHooksInvocations($hooks, $actual_hooks);
// The field still exists, deleted. // The field still exists, deleted.
$fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]) && $fields[$field->uuid]->deleted, 'The field exists and is deleted'); $this->assertTrue(isset($fields[$field->uuid]) && $fields[$field->uuid]->deleted, 'The field exists and is deleted');
// Purge again to purge the instance and the field. // Purge again to purge the instance and the field.
field_purge_batch(0); field_purge_batch(0);
// The field is gone. // The field is gone.
$fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertEqual(count($fields), 0, 'The field is purged.'); $this->assertEqual(count($fields), 0, 'The field is purged.');
} }
......
...@@ -203,13 +203,13 @@ function testReadFields() { ...@@ -203,13 +203,13 @@ function testReadFields() {
$id = $field->id(); $id = $field->id();
// Check that 'single column' criteria works. // Check that 'single column' criteria works.
$fields = field_read_fields(array('id' => $id)); $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name']));
$this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');
// Check that 'multi column' criteria works. // Check that 'multi column' criteria works.
$fields = field_read_fields(array('id' => $id, 'type' => $field_definition['type'])); $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name'], 'type' => $field_definition['type']));
$this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');
$fields = field_read_fields(array('name' => $field_definition['name'], 'type' => 'foo')); $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name'], 'type' => 'foo'));
$this->assertTrue(empty($fields), 'No field was found.'); $this->assertTrue(empty($fields), 'No field was found.');
// Create an instance of the field. // Create an instance of the field.
...@@ -309,41 +309,41 @@ function testDeleteField() { ...@@ -309,41 +309,41 @@ function testDeleteField() {
entity_create('field_instance', $another_instance_definition)->save(); entity_create('field_instance', $another_instance_definition)->save();
// Test that the first field is not deleted, and then delete it. // Test that the first field is not deleted, and then delete it.
$field = field_read_field('entity_test', $this->field['name'], array('include_deleted' => TRUE)); $field = current(entity_load_multiple_by_properties('field_entity', array('field_name' => $this->field['name'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
field_info_field('entity_test', $this->field['name'])->delete(); field_info_field('entity_test', $this->field['name'])->delete();
// Make sure that the field is marked as deleted when it is specifically // Make sure that the field is marked as deleted when it is specifically
// loaded. // loaded.
$field = field_read_field('entity_test', $this->field['name'], array('include_deleted' => TRUE)); $field = current(entity_load_multiple_by_properties('field_entity', array('field_name' => $this->field['name'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($field->deleted), 'A deleted field is marked for deletion.'); $this->assertTrue(!empty($field->deleted), 'A deleted field is marked for deletion.');
// Make sure that this field's instance is marked as deleted when it is // Make sure that this field's instance is marked as deleted when it is
// specifically loaded. // specifically loaded.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($instance->deleted), 'An instance for a deleted field is marked for deletion.'); $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. // Try to load the field normally and make sure it does not show up.
$field = field_read_field('entity_test', $this->field['name']); $field = entity_load('field_entity', 'entity_test.' . $this->field['name']);
$this->assertTrue(empty($field), 'A deleted field is not loaded by default.'); $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. // Try to load the instance normally and make sure it does not show up.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance = entity_load('field_instance', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.'); $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. // Make sure the other field (and its field instance) are not deleted.
$another_field = field_read_field('entity_test', $this->another_field['name']); $another_field = entity_load('field_entity', 'entity_test.' . $this->another_field['name']);
$this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.'); $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.');
$another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $another_instance_definition['bundle']); $another_instance = entity_load('field_instance', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']);
$this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'An instance of a non-deleted field is not marked for deletion.'); $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 // Try to create a new field the same name as a deleted field and
// write data into it. // write data into it.
entity_create('field_entity', $this->field)->save(); entity_create('field_entity', $this->field)->save();
entity_create('field_instance', $this->instance_definition)->save(); entity_create('field_instance', $this->instance_definition)->save();
$field = field_read_field('entity_test', $this->field['name']); $field = entity_load('field_entity', 'entity_test.' . $this->field['name']);
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.'); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.');
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name'] );
$this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.'); $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 // Save an entity with data for the field
......
...@@ -396,9 +396,9 @@ function testEntityDeleteBundle() { ...@@ -396,9 +396,9 @@ function testEntityDeleteBundle() {
$this->assertTrue(empty($entity->{$this->field_name}), 'No data for first field'); $this->assertTrue(empty($entity->{$this->field_name}), 'No data for first field');
$this->assertTrue(empty($entity->{$field_name}), 'No data for second field'); $this->assertTrue(empty($entity->{$field_name}), 'No data for second field');
// Verify that the instances are gone // Verify that the instances are gone.
$this->assertFalse(field_read_instance('entity_test', $this->field_name, $new_bundle), "First field is deleted"); $this->assertFalse(entity_load('field_instance', 'entity_test.' . $this->instance->bundle . '.' . $this->field_name), "First field is deleted");
$this->assertFalse(field_read_instance('entity_test', $field_name, $new_bundle), "Second field is deleted"); $this->assertFalse(entity_load('field_instance', 'entity_test.' . $instance['bundle']. '.' . $field_name), "Second field is deleted");
} }
} }
...@@ -114,7 +114,7 @@ function testReadFieldInstance() { ...@@ -114,7 +114,7 @@ function testReadFieldInstance() {
entity_create('field_instance', $this->instance_definition)->save(); entity_create('field_instance', $this->instance_definition)->save();
// Read the instance back. // Read the instance back.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$this->assertTrue($this->instance_definition['field_name'] == $instance->getName(), 'The field was properly read.'); $this->assertTrue($this->instance_definition['field_name'] == $instance->getName(), 'The field was properly read.');
$this->assertTrue($this->instance_definition['entity_type'] == $instance->entity_type, 'The field was properly read.'); $this->assertTrue($this->instance_definition['entity_type'] == $instance->entity_type, 'The field was properly read.');
$this->assertTrue($this->instance_definition['bundle'] == $instance->bundle, 'The field was properly read.'); $this->assertTrue($this->instance_definition['bundle'] == $instance->bundle, 'The field was properly read.');
...@@ -127,14 +127,14 @@ function testUpdateFieldInstance() { ...@@ -127,14 +127,14 @@ function testUpdateFieldInstance() {
entity_create('field_instance', $this->instance_definition)->save(); entity_create('field_instance', $this->instance_definition)->save();
// Check that basic changes are saved. // Check that basic changes are saved.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$instance->required = !$instance->isRequired(); $instance->required = !$instance->isRequired();
$instance->label = $this->randomName(); $instance->label = $this->randomName();
$instance->description = $this->randomName(); $instance->description = $this->randomName();
$instance->settings['test_instance_setting'] = $this->randomName(); $instance->settings['test_instance_setting'] = $this->randomName();
$instance->save(); $instance->save();
$instance_new = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance_new = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$this->assertEqual($instance->isRequired(), $instance_new->isRequired(), '"required" change is saved'); $this->assertEqual($instance->isRequired(), $instance_new->isRequired(), '"required" change is saved');
$this->assertEqual($instance->getLabel(), $instance_new->getLabel(), '"label" change is saved'); $this->assertEqual($instance->getLabel(), $instance_new->getLabel(), '"label" change is saved');
$this->assertEqual($instance->getDescription(), $instance_new->getDescription(), '"description" change is saved'); $this->assertEqual($instance->getDescription(), $instance_new->getDescription(), '"description" change is saved');
...@@ -158,21 +158,21 @@ function testDeleteFieldInstance() { ...@@ -158,21 +158,21 @@ function testDeleteFieldInstance() {
entity_create('field_instance', $another_instance_definition)->save(); entity_create('field_instance', $another_instance_definition)->save();
// Test that the first instance is not deleted, and then delete it. // Test that the first instance is not deleted, and then delete it.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new field instance is not marked for deletion.'); $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new field instance is not marked for deletion.');
$instance->delete(); $instance->delete();
// Make sure the instance is marked as deleted when the instance is // Make sure the instance is marked as deleted when the instance is
// specifically loaded. // specifically loaded.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE)));
$this->assertTrue(!empty($instance->deleted), 'A deleted field instance is marked for deletion.'); $this->assertTrue(!empty($instance->deleted), 'A deleted field instance is marked for deletion.');
// Try to load the instance normally and make sure it does not show up. // Try to load the instance normally and make sure it does not show up.
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance = entity_load('field_instance', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']);
$this->assertTrue(empty($instance), 'A deleted field instance is not loaded by default.'); $this->assertTrue(empty($instance), 'A deleted field instance is not loaded by default.');
// Make sure the other field instance is not deleted. // Make sure the other field instance is not deleted.
$another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $another_instance_definition['bundle']); $another_instance = entity_load('field_instance', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']);
$this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'A non-deleted field instance is not marked for deletion.'); $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'A non-deleted field instance is not marked for deletion.');
} }
......
...@@ -94,7 +94,7 @@ function setUp() { ...@@ -94,7 +94,7 @@ function setUp() {
'translatable' => TRUE, 'translatable' => TRUE,
); );
entity_create('field_entity', $this->field_definition)->save(); entity_create('field_entity', $this->field_definition)->save();
$this->field = field_read_field($this->entity_type, $this->field_name); $this->field = entity_load('field_entity', $this->entity_type . '.' . $this->field_name);
$this->instance_definition = array( $this->instance_definition = array(
'field_name' => $this->field_name, 'field_name' => $this->field_name,
...@@ -102,7 +102,7 @@ function setUp() { ...@@ -102,7 +102,7 @@ function setUp() {
'bundle' => 'entity_test', 'bundle' => 'entity_test',
); );
entity_create('field_instance', $this->instance_definition)->save(); entity_create('field_instance', $this->instance_definition)->save();
$this->instance = field_read_instance($this->entity_type, $this->field_name, $this->entity_type); $this->instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->field_name);
for ($i = 0; $i < 3; ++$i) { for ($i = 0; $i < 3; ++$i) {
$language = new Language(array( $language = new Language(array(
......
...@@ -70,7 +70,7 @@ function setUp() { ...@@ -70,7 +70,7 @@ function setUp() {
'translatable' => TRUE, 'translatable' => TRUE,
); );
entity_create('field_entity', $field)->save(); entity_create('field_entity', $field)->save();
$this->field = field_read_field($this->entity_type, $this->field_name); $this->field = entity_load('field_entity', $this->entity_type . '.' . $this->field_name);
$instance = array( $instance = array(
'field_name' => $this->field_name, 'field_name' => $this->field_name,
...@@ -78,7 +78,7 @@ function setUp() { ...@@ -78,7 +78,7 @@ function setUp() {
'bundle' =