diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index 905be54e618f3870af8d3311e145b5630d3a4c49..53f5fe45e9361c747d651ded49cc74cca5835bb1 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -164,36 +164,6 @@ function entity_extract_ids($entity_type, $entity) { return array($id, $vid, $bundle); } -/** - * Assembles an object structure with initial IDs. - * - * This function can be seen as reciprocal to entity_extract_ids(). - * - * @param $entity_type - * The entity type; e.g. 'node' or 'user'. - * @param $ids - * A numerically indexed array, as returned by entity_extract_ids(), - * containing these elements: - * - 0: Primary ID of the entity. - * - 1: Revision ID of the entity, or NULL if $entity_type is not versioned. - * - 2: Bundle name of the entity, or NULL if $entity_type has no bundles. - * - * @return - * An entity object, initialized with the IDs provided. - */ -function entity_create_stub_entity($entity_type, $ids) { - $entity = new stdClass(); - $info = entity_get_info($entity_type); - $entity->{$info['entity keys']['id']} = $ids[0]; - if (!empty($info['entity keys']['revision']) && isset($ids[1])) { - $entity->{$info['entity keys']['revision']} = $ids[1]; - } - if (!empty($info['entity keys']['bundle']) && isset($ids[2])) { - $entity->{$info['entity keys']['bundle']} = $ids[2]; - } - return $entity; -} - /** * Loads an entity from the database. * diff --git a/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php b/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php index f42c675a02123d065db9965a314dfdc96abdda5e..8cc15b89058285629d7a12d75b381b14baea1f83 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php +++ b/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php @@ -710,20 +710,21 @@ public function addMetaData($key, $object) { * Executes the query. * * After executing the query, $this->orderedResults will contain a list of - * the same stub entities in the order returned by the query. This is only + * the same entity ids in the order returned by the query. This is only * relevant if there are multiple entity types in the returned value and * a field ordering was requested. In every other case, the returned value * contains everything necessary for processing. * * @return * Either a number if count() was called or an array of associative arrays - * of stub entities. The outer array keys are entity types, and the inner + * of the entity ids. The outer array keys are entity types, and the inner * array keys are the relevant ID. (In most cases this will be the entity * ID. The only exception is when age=FIELD_LOAD_REVISION is used and field * conditions or sorts are present -- in this case, the key will be the * revision ID.) The entity type will only exist in the outer array if - * results were found. The inner array values are always stub entities, as - * returned by entity_create_stub_entity(). To traverse the returned array: + * results were found. The inner array values consist of an object with the + * entity_id, revision_id and bundle properties. To traverse the returned + * array: * @code * foreach ($query->execute() as $entity_type => $entities) { * foreach ($entities as $entity_id => $entity) { @@ -922,11 +923,12 @@ function finishQuery($select_query, $id_key = 'entity_id') { return $select_query->countQuery()->execute()->fetchField(); } $return = array(); - foreach ($select_query->execute() as $partial_entity) { - $bundle = isset($partial_entity->bundle) ? $partial_entity->bundle : NULL; - $entity = entity_create_stub_entity($partial_entity->entity_type, array($partial_entity->entity_id, $partial_entity->revision_id, $bundle)); - $return[$partial_entity->entity_type][$partial_entity->$id_key] = $entity; - $this->ordered_results[] = $partial_entity; + foreach ($select_query->execute() as $ids) { + if (!isset($ids->bundle)) { + $ids->bundle = NULL; + } + $return[$ids->entity_type][$ids->$id_key] = $ids; + $this->ordered_results[] = $ids; } return $return; } diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index d85a656e38d2726557b504ab6120ec582ae06384..b748c51b4d242e34b9632629e77aac56b669c71c 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -867,11 +867,16 @@ function field_purge_batch($batch_size) { ->execute(); if ($results) { - foreach ($results as $entity_type => $stub_entities) { - field_attach_load($entity_type, $stub_entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); - foreach ($stub_entities as $stub_entity) { + foreach ($results as $entity_type => $ids_array) { + $entities = array(); + foreach ($ids_array as $ids) { + $entities[$ids->entity_id] = _field_create_entity_from_ids($ids); + } + + field_attach_load($entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); + foreach ($entities as $entity) { // Purge the data for the entity. - field_purge_data($entity_type, $stub_entity, $field, $instance); + field_purge_data($entity_type, $entity, $field, $instance); } } } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 952c1ab40f08e9a3a05604120217a2b52e10ed6f..d42e5ac6f6320170f283ec2fc5cefecc8720f65b 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -1206,3 +1206,29 @@ function theme_field($variables) { return $output; } + +/** + * Assembles a partial entity structure with initial IDs. + * + * This can be used to create an entity based on the the ids object returned by + * EntityFieldQuery. + * + * @param stdClass $ids + * An object with the properties entity_type (required), entity_id (required), + * revision_id (optional) and bundle (optional). + * + * @return + * An entity, initialized with the provided IDs. + */ +function _field_create_entity_from_ids($ids) { + $id_properties = array(); + $info = entity_get_info($ids->entity_type); + $id_properties[$info['entity keys']['id']] = $ids->entity_id; + if (!empty($info['entity keys']['revision']) && isset($ids->revision_id)) { + $id_properties[$info['entity keys']['revision']] = $ids->revision_id; + } + if (!empty($info['entity keys']['bundle']) && isset($ids->bundle)) { + $id_properties[$info['entity keys']['bundle']] = $ids->bundle; + } + return entity_create($ids->entity_type, $id_properties); + } diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 347f55c34c7b1c512ce00e3095793db659657153..17e879b4ec11e0b31e2e603ab957571e0298d6f6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -24,33 +24,29 @@ public static function getInfo() { } /** - * Convenience function for Field API tests. + * Converts the passed entities to partially created ones. * - * Given an array of potentially fully-populated entities and an - * optional field name, generate an array of stub entities of the - * same fieldable type which contains the data for the field name - * (if given). + * This replicates the partial entities created in field_purge_data_batch(), + * which only have the ids and the to be deleted field defined. * - * @param $entity_type - * The entity type of $entities. * @param $entities - * An array of entities of type $entity_type. + * An array of entities of type test_entity. * @param $field_name - * Optional; a field name whose data should be copied from - * $entities into the returned stub entities. + * A field name whose data should be copied from $entities into the returned + * partial entities. * @return - * An array of stub entities corresponding to $entities. + * An array of partial entities corresponding to $entities. */ - function _generateStubEntities($entity_type, $entities, $field_name = NULL) { - $stubs = array(); + protected function convertToPartialEntities($entities, $field_name) { + $partial_entities = array(); foreach ($entities as $id => $entity) { - $stub = entity_create_stub_entity($entity_type, entity_extract_ids($entity_type, $entity)); - if (isset($field_name)) { - $stub->{$field_name} = $entity->{$field_name}; - } - $stubs[$id] = $stub; + // Re-create the entity with only the required keys, remove label as that + // is not present when using _field_create_entity_from_ids(). + $partial_entities[$id] = field_test_create_entity($entity->ftid, $entity->ftvid, $entity->fttype, $entity->ftlabel); + unset($partial_entities[$id]->ftlabel); + $partial_entities[$id]->$field_name = $entity->$field_name; } - return $stubs; + return $partial_entities; } /** @@ -122,7 +118,7 @@ function setUp() { } for ($i = 0; $i < 10; $i++) { - $entity = field_test_create_stub_entity($id, $id, $bundle); + $entity = field_test_create_entity($id, $id, $bundle); foreach ($this->fields as $field) { $entity->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']); } @@ -182,9 +178,13 @@ function testDeleteFieldInstance() { ->entityCondition('bundle', $bundle) ->deleted(TRUE) ->execute(); - field_attach_load($this->entity_type, $found[$this->entity_type], FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); + $entities = array(); + foreach ($found[$this->entity_type] as $ids) { + $entities[$ids->entity_id] = _field_create_entity_from_ids($ids); + } + field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); $this->assertEqual(count($found['test_entity']), 10, 'Correct number of entities found after deleting'); - foreach ($found['test_entity'] as $id => $entity) { + foreach ($entities as $id => $entity) { $this->assertEqual($this->entities[$id]->{$field['field_name']}, $entity->{$field['field_name']}, "Entity $id with deleted data loaded correctly"); } } @@ -230,12 +230,12 @@ function testPurgeInstance() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']); - foreach (array_chunk($stubs, $batch_size, TRUE) as $chunk) { - $hooks['field_test_field_load'][] = $chunk; + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + foreach (array_chunk($entities, $batch_size, TRUE) as $chunk_entity) { + $hooks['field_test_field_load'][] = $chunk_entity; } - foreach ($stubs as $stub) { - $hooks['field_test_field_delete'][] = $stub; + foreach ($entities as $entity) { + $hooks['field_test_field_delete'][] = $entity; } $this->checkHooksInvocations($hooks, $actual_hooks); @@ -284,11 +284,9 @@ function testPurgeField() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']); - $hooks['field_test_field_load'][] = $stubs; - foreach ($stubs as $stub) { - $hooks['field_test_field_delete'][] = $stub; - } + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $hooks['field_test_field_load'][] = $entities; + $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); // Purge again to purge the instance. @@ -313,11 +311,9 @@ function testPurgeField() { // Check hooks invocations (same as above, for the 2nd bundle). $actual_hooks = field_test_memorize(); $hooks = array(); - $stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']); - $hooks['field_test_field_load'][] = $stubs; - foreach ($stubs as $stub) { - $hooks['field_test_field_delete'][] = $stub; - } + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $hooks['field_test_field_load'][] = $entities; + $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index be93f80ed9ae7219985e32b075b7cc7010bac958..589fe8d54cc8be1d725d8b7a0721611676f134e0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -297,7 +297,7 @@ function testDeleteField() { $this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new instance for a previously used field name is created.')); // Save an entity with data for the field - $entity = field_test_create_stub_entity(0, 0, $instance['bundle']); + $entity = field_test_create_entity(0, 0, $instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; $values[0]['value'] = mt_rand(1, 127); $entity->{$field['field_name']}[$langcode] = $values; @@ -305,7 +305,7 @@ function testDeleteField() { field_attach_insert('test_entity', $entity); // Verify the field is present on load - $entity = field_test_create_stub_entity(0, 0, $this->instance_definition['bundle']); + $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"); foreach ($values as $delta => $value) { @@ -362,7 +362,7 @@ function testUpdateField() { do { // We need a unique ID for our entity. $cardinality will do. $id = $cardinality; - $entity = field_test_create_stub_entity($id, $id, $instance['bundle']); + $entity = field_test_create_entity($id, $id, $instance['bundle']); // Fill in the entity with more values than $cardinality. for ($i = 0; $i < 20; $i++) { $entity->field_update[LANGUAGE_NOT_SPECIFIED][$i]['value'] = $i; @@ -370,7 +370,7 @@ function testUpdateField() { // Save the entity. field_attach_insert('test_entity', $entity); // Load back and assert there are $cardinality number of values. - $entity = field_test_create_stub_entity($id, $id, $instance['bundle']); + $entity = field_test_create_entity($id, $id, $instance['bundle']); field_attach_load('test_entity', array($id => $entity)); $this->assertEqual(count($entity->field_update[LANGUAGE_NOT_SPECIFIED]), $field_definition['cardinality'], 'Cardinality is kept'); // Now check the values themselves. diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index f848367bd39f1884fc7f4ffd421c4e3babebf38e..c64f11c7b724c8f2e100303c70619bc9fd393ced 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -54,7 +54,7 @@ function setUp() { // Create an entity with values. $this->values = $this->_generateTestFieldValues($this->cardinality); - $this->entity = field_test_create_stub_entity(); + $this->entity = field_test_create_entity(); $this->is_new = TRUE; $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED] = $this->values; field_test_entity_save($this->entity); diff --git a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php b/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php index 7a2712f8d437ee9ab68554930253d7fa630a0b64..02f5459174d01f4552abcf1141353829e6531663 100644 --- a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php @@ -33,10 +33,14 @@ function testEntityLabel() { 'test_entity_label_callback', ); - $entity = field_test_create_stub_entity(); + // @todo Remove once test_entity entity has been merged with entity_test. + $values = array( + 'ftlabel' => $this->randomName(), + ); foreach ($entity_types as $entity_type) { - $label = entity_create($entity_type, (array) $entity)->label(); + $entity = entity_create($entity_type, $values); + $label = $entity->label(); switch ($entity_type) { case 'test_entity_no_label': diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 19169328e83bc2e5f6de12472f129bdb179b5ec8..19c9614214d10ad504f85455cdc39a722746d06b 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -26,7 +26,7 @@ public static function getInfo() { */ function testFieldAttachView() { $entity_type = 'test_entity'; - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $langcode = LANGUAGE_NOT_SPECIFIED; // Populate values to be displayed. @@ -172,11 +172,11 @@ function testFieldAttachPrepareViewMultiple() { field_create_instance($this->instance2); // Create one entity in each bundle. - $entity1_init = field_test_create_stub_entity(1, 1, 'test_bundle'); + $entity1_init = field_test_create_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'); + $entity2_init = field_test_create_entity(2, 2, 'test_bundle_2'); $values2 = $this->_generateTestFieldValues($this->field['cardinality']); $entity2_init->{$this->field_name}[$langcode] = $values2; @@ -200,7 +200,7 @@ function testFieldAttachPrepareViewMultiple() { */ function testFieldAttachCache() { // Initialize random values and a test entity. - $entity_init = field_test_create_stub_entity(1, 1, $this->instance['bundle']); + $entity_init = field_test_create_entity(1, 1, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); @@ -265,7 +265,7 @@ function testFieldAttachCache() { $this->assertEqual($cache->data[$this->field_name][$langcode], $values, t('Cached: correct cache entry on load')); // Create a new revision, and check that the cache entry is wiped. - $entity_init = field_test_create_stub_entity(1, 2, $this->instance['bundle']); + $entity_init = field_test_create_entity(1, 2, $this->instance['bundle']); $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity = clone($entity_init); $entity->{$this->field_name}[$langcode] = $values; @@ -292,7 +292,7 @@ function testFieldAttachCache() { */ function testFieldAttachValidate() { $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; // Set up values to generate errors @@ -343,7 +343,7 @@ function testFieldAttachValidate() { */ function testFieldAttachForm() { $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $form = array(); $form_state = form_state_defaults(); @@ -362,7 +362,7 @@ function testFieldAttachForm() { */ function testFieldAttachSubmit() { $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); // Build the form. $form = array(); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index d6b4c18bb3b1311b43f0aadd5a0c563f63d53820..02bc54cf0e4c134011c66be430a882b3c301259a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -42,7 +42,7 @@ function testFieldAttachSaveLoad() { // Preparation: create three revisions and store them in $revision array. for ($revision_id = 0; $revision_id < 3; $revision_id++) { - $revision[$revision_id] = field_test_create_stub_entity(0, $revision_id, $this->instance['bundle']); + $revision[$revision_id] = field_test_create_entity(0, $revision_id, $this->instance['bundle']); // Note: we try to insert one extra value. $values[$revision_id] = $this->_generateTestFieldValues($this->field['cardinality'] + 1); $current_revision = $revision_id; @@ -59,7 +59,7 @@ function testFieldAttachSaveLoad() { } // Confirm current revision loads the correct data. - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $entity)); // Number of values per field loaded equals the field cardinality. $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], t('Current revision: expected number of values')); @@ -72,7 +72,7 @@ function testFieldAttachSaveLoad() { // Confirm each revision loads the correct data. foreach (array_keys($revision) as $revision_id) { - $entity = field_test_create_stub_entity(0, $revision_id, $this->instance['bundle']); + $entity = field_test_create_entity(0, $revision_id, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $entity)); // Number of values per field loaded equals the field cardinality. $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], t('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); @@ -130,7 +130,7 @@ function testFieldAttachLoadMultiple() { // Create one test entity per bundle, with random values. foreach ($bundles as $index => $bundle) { - $entities[$index] = field_test_create_stub_entity($index, $index, $bundle); + $entities[$index] = field_test_create_entity($index, $index, $bundle); $entity = clone($entities[$index]); $instances = field_info_instances('test_entity', $bundle); foreach ($instances as $field_name => $instance) { @@ -153,7 +153,7 @@ function testFieldAttachLoadMultiple() { } // Check that the single-field load option works. - $entity = field_test_create_stub_entity(1, 1, $bundles[1]); + $entity = field_test_create_entity(1, 1, $bundles[1]); field_attach_load($entity_type, array(1 => $entity), FIELD_LOAD_CURRENT, array('field_id' => $field_ids[1])); $this->assertEqual($entity->{$field_names[1]}[$langcode][0]['value'], $values[1][$field_names[1]], t('Entity %index: expected value was found.', array('%index' => 1))); $this->assertEqual($entity->{$field_names[1]}[$langcode][0]['additional_key'], 'additional_value', t('Entity %index: extra information was found', array('%index' => 1))); @@ -193,7 +193,7 @@ function testFieldAttachSaveLoadDifferentStorage() { field_create_instance($instance); } - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); // Create entity and insert random values. $entity = clone($entity_init); @@ -259,7 +259,7 @@ function testFieldStorageDetailsAlter() { */ function testFieldAttachSaveMissingData() { $entity_type = 'test_entity'; - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $langcode = LANGUAGE_NOT_SPECIFIED; // Insert: Field is missing. @@ -341,7 +341,7 @@ function testFieldAttachSaveMissingDataDefaultValue() { field_update_instance($this->instance); $entity_type = 'test_entity'; - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $langcode = LANGUAGE_NOT_SPECIFIED; // Insert: Field is NULL. @@ -370,7 +370,7 @@ function testFieldAttachSaveMissingDataDefaultValue() { function testFieldAttachDelete() { $entity_type = 'test_entity'; $langcode = LANGUAGE_NOT_SPECIFIED; - $rev[0] = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $rev[0] = field_test_create_entity(0, 0, $this->instance['bundle']); // Create revision 0 $values = $this->_generateTestFieldValues($this->field['cardinality']); @@ -378,18 +378,18 @@ function testFieldAttachDelete() { field_attach_insert($entity_type, $rev[0]); // Create revision 1 - $rev[1] = field_test_create_stub_entity(0, 1, $this->instance['bundle']); + $rev[1] = field_test_create_entity(0, 1, $this->instance['bundle']); $rev[1]->{$this->field_name}[$langcode] = $values; field_attach_update($entity_type, $rev[1]); // Create revision 2 - $rev[2] = field_test_create_stub_entity(0, 2, $this->instance['bundle']); + $rev[2] = field_test_create_entity(0, 2, $this->instance['bundle']); $rev[2]->{$this->field_name}[$langcode] = $values; field_attach_update($entity_type, $rev[2]); // Confirm each revision loads foreach (array_keys($rev) as $vid) { - $read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']); + $read = field_test_create_entity(0, $vid, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); } @@ -397,24 +397,24 @@ function testFieldAttachDelete() { // Delete revision 1, confirm the other two still load. field_attach_delete_revision($entity_type, $rev[1]); foreach (array(0, 2) as $vid) { - $read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']); + $read = field_test_create_entity(0, $vid, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); } // Confirm the current revision still loads - $read = field_test_create_stub_entity(0, 2, $this->instance['bundle']); + $read = field_test_create_entity(0, 2, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity current revision has {$this->field['cardinality']} values."); // Delete all field data, confirm nothing loads field_attach_delete($entity_type, $rev[2]); foreach (array(0, 1, 2) as $vid) { - $read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']); + $read = field_test_create_entity(0, $vid, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertIdentical($read->{$this->field_name}, array(), "The test entity revision $vid is deleted."); } - $read = field_test_create_stub_entity(0, 2, $this->instance['bundle']); + $read = field_test_create_entity(0, 2, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $read)); $this->assertIdentical($read->{$this->field_name}, array(), t('The test entity current revision is deleted.')); } @@ -433,7 +433,7 @@ function testFieldAttachCreateRenameBundle() { field_create_instance($this->instance); // Save an entity with data in the field. - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity->{$this->field_name}[$langcode] = $values; @@ -441,7 +441,7 @@ function testFieldAttachCreateRenameBundle() { field_attach_insert($entity_type, $entity); // Verify the field data is present on load. - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $entity)); $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Data is retrieved for the new bundle"); @@ -455,7 +455,7 @@ function testFieldAttachCreateRenameBundle() { $this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance."); // Verify the field data is present on load. - $entity = field_test_create_stub_entity(0, 0, $new_bundle); + $entity = field_test_create_entity(0, 0, $new_bundle); field_attach_load($entity_type, array(0 => $entity)); $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Bundle name has been updated in the field storage"); } @@ -492,7 +492,7 @@ function testFieldAttachDeleteBundle() { field_create_instance($instance); // Save an entity with data for both fields - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity->{$this->field_name}[$langcode] = $values; @@ -500,7 +500,7 @@ function testFieldAttachDeleteBundle() { field_attach_insert('test_entity', $entity); // Verify the fields are present on load - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load('test_entity', array(0 => $entity)); $this->assertEqual(count($entity->{$this->field_name}[$langcode]), 4, 'First field got loaded'); $this->assertEqual(count($entity->{$field_name}[$langcode]), 1, 'Second field got loaded'); @@ -510,7 +510,7 @@ function testFieldAttachDeleteBundle() { field_test_delete_bundle($this->instance['bundle']); // Verify no data gets loaded - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load('test_entity', array(0 => $entity)); $this->assertFalse(isset($entity->{$this->field_name}[$langcode]), 'No data for first field'); $this->assertFalse(isset($entity->{$field_name}[$langcode]), 'No data for second field'); diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 58a4a8f6554e1dddc089030ace62a4516a758869..94919aa6d46e74c994b3459d6e2db6c7dbbb2098 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -337,7 +337,7 @@ function testFieldFormMultipleWidget() { $id = $match[1]; // Check that the values were saved. - $entity_init = field_test_create_stub_entity($id); + $entity_init = field_test_create_entity($id); $this->assertFieldValues($entity_init, $this->field_name, $langcode, array(1, 2, 3)); // Display the form, check that the values are correctly filled in. @@ -384,7 +384,7 @@ function testFieldFormAccess() { // Test that the form structure includes full information for each delta // apart from #access. $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $form = array(); $form_state = form_state_defaults(); @@ -438,13 +438,13 @@ function testNestedFieldForm() { field_create_instance($this->instance); // Create two entities. - $entity_1 = field_test_create_stub_entity(1, 1); + $entity_1 = field_test_create_entity(1, 1); $entity_1->is_new = TRUE; $entity_1->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 0); $entity_1->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 1); field_test_entity_save($entity_1); - $entity_2 = field_test_create_stub_entity(2, 2); + $entity_2 = field_test_create_entity(2, 2); $entity_2->is_new = TRUE; $entity_2->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 10); $entity_2->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 11); @@ -468,8 +468,8 @@ function testNestedFieldForm() { ); $this->drupalPost(NULL, $edit, t('Save')); field_cache_clear(); - $entity_1 = field_test_create_stub_entity(1); - $entity_2 = field_test_create_stub_entity(2); + $entity_1 = field_test_create_entity(1); + $entity_2 = field_test_create_entity(2); $this->assertFieldValues($entity_1, 'field_single', LANGUAGE_NOT_SPECIFIED, array(1)); $this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(2, 3)); $this->assertFieldValues($entity_2, 'field_single', LANGUAGE_NOT_SPECIFIED, array(11)); diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 283d16927a96bf144879d0078a57518d3adfd0f3..44050001dfba32aa6e53ccd1ccb636f80587e460 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -94,7 +94,7 @@ function testFieldInvoke() { field_test_entity_info_translatable('test_entity', TRUE); $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); // Populate some extra languages to check if _field_invoke() correctly uses // the result of field_available_languages(). @@ -139,7 +139,7 @@ function testFieldInvokeMultiple() { $available_langcodes = field_available_languages($this->entity_type, $this->field); for ($id = 1; $id <= $entity_count; ++$id) { - $entity = field_test_create_stub_entity($id, $id, $this->instance['bundle']); + $entity = field_test_create_entity($id, $id, $this->instance['bundle']); $langcodes = $available_langcodes; // Populate some extra languages to check whether _field_invoke() @@ -210,7 +210,7 @@ function testTranslatableFieldSaveLoad() { field_test_entity_info_translatable('test_entity', TRUE); $eid = $evid = 1; $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']); + $entity = field_test_create_entity($eid, $evid, $this->instance['bundle']); $field_translations = array(); $available_langcodes = field_available_languages($entity_type, $this->field); $this->assertTrue(count($available_langcodes) > 1, t('Field is translatable.')); @@ -258,7 +258,7 @@ function testFieldDisplayLanguage() { ); field_create_instance($instance); - $entity = field_test_create_stub_entity(1, 1, $this->instance['bundle']); + $entity = field_test_create_entity(1, 1, $this->instance['bundle']); $instances = field_info_instances($entity_type, $this->instance['bundle']); $enabled_langcodes = field_content_languages(); @@ -337,7 +337,7 @@ function testFieldFormTranslationRevisions() { // Prepare the field translations. field_test_entity_info_translatable($this->entity_type, TRUE); $eid = 1; - $entity = field_test_create_stub_entity($eid, $eid, $this->instance['bundle']); + $entity = field_test_create_entity($eid, $eid, $this->instance['bundle']); $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field)); unset($available_langcodes[LANGUAGE_NOT_SPECIFIED]); $field_name = $this->field['field_name']; diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php index 8dbb577a296c760e937a1db7b7b044080b8d6284..eb30493f6d6757572a761dd050f4801045df69ce 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php @@ -75,7 +75,7 @@ function testFieldAttachLoad() { $query->execute(); // Load the "most current revision" - $entity = field_test_create_stub_entity($eid, 0, $this->instance['bundle']); + $entity = field_test_create_entity($eid, 0, $this->instance['bundle']); field_attach_load($entity_type, array($eid => $entity)); foreach ($values[0] as $delta => $value) { if ($delta < $this->field['cardinality']) { @@ -88,7 +88,7 @@ function testFieldAttachLoad() { // Load every revision for ($evid = 0; $evid < 4; ++$evid) { - $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']); + $entity = field_test_create_entity($eid, $evid, $this->instance['bundle']); field_attach_load_revision($entity_type, array($eid => $entity)); foreach ($values[$evid] as $delta => $value) { if ($delta < $this->field['cardinality']) { @@ -104,7 +104,7 @@ function testFieldAttachLoad() { // loaded. $eid = $evid = 1; $unavailable_langcode = 'xx'; - $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']); + $entity = field_test_create_entity($eid, $evid, $this->instance['bundle']); $values = array($entity_type, $eid, $evid, 0, $unavailable_langcode, mt_rand(1, 127)); db_insert($this->table)->fields($columns)->values($values)->execute(); db_insert($this->revision_table)->fields($columns)->values($values)->execute(); @@ -118,7 +118,7 @@ function testFieldAttachLoad() { */ function testFieldAttachInsertAndUpdate() { $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; // Test insert. @@ -142,7 +142,7 @@ function testFieldAttachInsertAndUpdate() { } // Test update. - $entity = field_test_create_stub_entity(0, 1, $this->instance['bundle']); + $entity = field_test_create_entity(0, 1, $this->instance['bundle']); $values = array(); // Note: we try to update one extra value ('<=' instead of '<'). for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { @@ -199,7 +199,7 @@ function testFieldAttachInsertAndUpdate() { */ function testFieldAttachSaveMissingData() { $entity_type = 'test_entity'; - $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); + $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; // Insert: Field is missing @@ -298,7 +298,7 @@ function testUpdateFieldSchemaWithData() { $field = field_create_field($field); $instance = array('field_name' => 'decimal52', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle'); $instance = field_create_instance($instance); - $entity = field_test_create_stub_entity(0, 0, $instance['bundle']); + $entity = field_test_create_entity(0, 0, $instance['bundle']); $entity->decimal52[LANGUAGE_NOT_SPECIFIED][0]['value'] = '1.235'; field_attach_insert('test_entity', $entity); @@ -358,7 +358,7 @@ function testFieldUpdateIndexesWithData() { } // Add data so the table cannot be dropped. - $entity = field_test_create_stub_entity(0, 0, $instance['bundle']); + $entity = field_test_create_entity(0, 0, $instance['bundle']); $entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'] = 'field data'; field_attach_insert('test_entity', $entity); @@ -378,7 +378,7 @@ function testFieldUpdateIndexesWithData() { } // Verify that the tables were not dropped. - $entity = field_test_create_stub_entity(0, 0, $instance['bundle']); + $entity = field_test_create_entity(0, 0, $instance['bundle']); field_attach_load('test_entity', array(0 => $entity)); $this->assertEqual($entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'], 'field data', t("Index changes performed without dropping the tables")); } diff --git a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php index e6b630faae0db239f7ebbe5989deb066b7ed35a2..3bd77b6fdc7f8a4bf6cb34dddad55bdc118be721 100644 --- a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php +++ b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php @@ -45,6 +45,6 @@ function setUp() { 'bundle' => 'test_bundle', 'label' => $this->randomName(), ); - $this->entity = call_user_func_array('field_test_create_stub_entity', $this->test); + $this->entity = call_user_func_array('field_test_create_entity', $this->test); } } diff --git a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 5a7d64c3d6038c53e224f2ee31d1d326c8ea209d..047daca7b07ab2f1ed0430ae08131687c45cae67 100644 --- a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -54,7 +54,7 @@ function testUpdateAllowedValues() { $langcode = LANGUAGE_NOT_SPECIFIED; // All three options appear. - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $form = drupal_get_form('field_test_entity_form', $entity); $this->assertTrue(!empty($form[$this->field_name][$langcode][1]), t('Option 1 exists')); $this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists')); @@ -62,7 +62,7 @@ function testUpdateAllowedValues() { // Use one of the values in an actual entity, and check that this value // cannot be removed from the list. - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $entity->{$this->field_name}[$langcode][0] = array('value' => 1); field_test_entity_save($entity); $this->field['settings']['allowed_values'] = array(2 => 'Two'); @@ -80,7 +80,7 @@ function testUpdateAllowedValues() { // Removed options do not appear. $this->field['settings']['allowed_values'] = array(2 => 'Two'); field_update_field($this->field); - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $form = drupal_get_form('field_test_entity_form', $entity); $this->assertTrue(empty($form[$this->field_name][$langcode][1]), t('Option 1 does not exist')); $this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists')); @@ -110,7 +110,7 @@ function testUpdateAllowedValues() { ), ); $this->instance = field_create_instance($this->instance); - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $form = drupal_get_form('field_test_entity_form', $entity); $this->assertTrue(!empty($form[$this->field_name][$langcode][1]), t('Option 1 exists')); $this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists')); diff --git a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 92a92af311709142a7b5f9a7716391ee8bfaad84..c2821666ed31b801340ab08ca34d9ba63faf0bbe 100644 --- a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -82,7 +82,7 @@ function testRadioButtons() { $langcode = LANGUAGE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $entity = clone $entity_init; $entity->is_new = TRUE; field_test_entity_save($entity); @@ -136,7 +136,7 @@ function testCheckBoxes() { $langcode = LANGUAGE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $entity = clone $entity_init; $entity->is_new = TRUE; field_test_entity_save($entity); @@ -224,7 +224,7 @@ function testSelectListSingle() { $langcode = LANGUAGE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $entity = clone $entity_init; $entity->is_new = TRUE; field_test_entity_save($entity); @@ -320,7 +320,7 @@ function testSelectListMultiple() { $langcode = LANGUAGE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $entity = clone $entity_init; $entity->is_new = TRUE; field_test_entity_save($entity); @@ -437,7 +437,7 @@ function testOnOffCheckbox() { $langcode = LANGUAGE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_stub_entity(); + $entity_init = field_test_create_entity(); $entity = clone $entity_init; $entity->is_new = TRUE; field_test_entity_save($entity); diff --git a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index fbbd3228c793d6ec60c0adc4e699095e4af54118..c90abd67dfd0a1e0b78373e27f284317a666ae6a 100644 --- a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -65,7 +65,7 @@ function testTextFieldValidation() { ); field_create_instance($this->instance); // Test valid and invalid values with field_attach_validate(). - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $langcode = LANGUAGE_NOT_SPECIFIED; for ($i = 0; $i <= $max_length + 2; $i++) { $entity->{$this->field['field_name']}[$langcode][0]['value'] = str_repeat('x', $i); diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index 456fe996163fa9b7f0ba764aec30f1a92cea6353..ae5cdf32bc63dbfb81b521700cae4e7af401b4fb 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -210,8 +210,8 @@ function field_test_delete_bundle($bundle) { /** * Creates a basic test_entity entity. */ -function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') { - $entity = new stdClass(); +function field_test_create_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') { + $entity = entity_create('test_entity', array()); // Only set id and vid properties if they don't come as NULL (creation form). if (isset($id)) { $entity->ftid = $id; diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 6821c97deca17d4d53f1efbafc572b1b18536201..b7c94dd4d32d4d3e648d5c910bcee8dc1c7fdfa2 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -199,7 +199,7 @@ function field_test_dummy_field_storage_query(EntityFieldQuery $query) { // Return dummy values that will be checked by the test. return array( 'user' => array( - 1 => entity_create_stub_entity('user', array(1, NULL, NULL)), + 1 => (object) array('entity_id' => 1, 'revision_id' => NULL, 'bundle' => NULL), ), ); } diff --git a/core/modules/field/tests/modules/field_test/field_test.storage.inc b/core/modules/field/tests/modules/field_test/field_test.storage.inc index eaa0851bc900691a67b77366786641da8b8ddf77..b4b98ea9749d13d1df79efe67d97690b77c07150 100644 --- a/core/modules/field/tests/modules/field_test/field_test.storage.inc +++ b/core/modules/field/tests/modules/field_test/field_test.storage.inc @@ -325,7 +325,7 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor $id = ($load_current || empty($entity_type['entity keys']['revision'])) ? $row->entity_id : $row->revision_id; if (!isset($return[$row->type][$id])) { - $return[$row->type][$id] = entity_create_stub_entity($row->type, array($row->entity_id, $row->revision_id, $row->bundle)); + $return[$row->type][$id] = (object) array('entity_id' => $row->entity_id, 'revision_id' => $row->revision_id, 'bundle' => $row->bundle); $entity_count++; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index 477de5c1e9b9e4880c01c691a30236cc75748648..442e2038505739423b183f27e298949a1a0e1b95 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -25,10 +25,11 @@ class TermStorageController extends DatabaseStorageController { public function create(array $values) { $entity = parent::create($values); // Ensure the vocabulary machine name is initialized as it is used as the - // bundle key. + // bundle key. Only attempt to do this if a vocabulary ID is available, + // which might not be the case when creating partial entity structures. // @todo Move to Term::bundle() once field API has been converted // to make use of it. - if (!isset($entity->vocabulary_machine_name)) { + if (!isset($entity->vocabulary_machine_name) && isset($entity->vid)) { $vocabulary = taxonomy_vocabulary_load($entity->vid); $entity->vocabulary_machine_name = $vocabulary->machine_name; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php index 32e3f041b031252b3a79154aa8ac5f1eb2d6e716..8fb20d00c9f33ac0527169ff3d236b04711c1b8d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php @@ -44,6 +44,10 @@ function testTaxonomyEfq() { asort($result); $this->assertEqual(array_keys($terms), array_keys($result), 'Taxonomy terms were retrieved by EntityFieldQuery.'); + $first_result = reset($result); + $term = _field_create_entity_from_ids($first_result); + $this->assertEqual($term->tid, $first_result->entity_id, 'Taxonomy term can be created based on the IDs'); + // Create a second vocabulary and five more terms. $vocabulary2 = $this->createVocabulary(); $terms2 = array(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 37661b9525e6da8104f9c054a0926487c0e508e6..4e1a1c41070162b447598724addbab48a1f72a5c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -69,7 +69,7 @@ function setUp() { function testTaxonomyTermFieldValidation() { // Test valid and invalid values with field_attach_validate(). $langcode = LANGUAGE_NOT_SPECIFIED; - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $term = $this->createTerm($this->vocabulary); $entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid; try { @@ -80,7 +80,7 @@ function testTaxonomyTermFieldValidation() { $this->fail('Correct term does not cause validation error.'); } - $entity = field_test_create_stub_entity(); + $entity = field_test_create_entity(); $bad_term = $this->createTerm($this->createVocabulary()); $entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->tid; try {