diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index baa7ff4..6fd3e36 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -1610,7 +1610,7 @@ function field_entity_bundle_delete($entity_type, $bundle) { // entity types or bundles. $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle), array('include_inactive' => TRUE)); foreach ($instances as $instance) { - field_delete_instance($instance); + $instance->delete(); } // Clear the cache. diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 798d604..bc90be4 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -74,8 +74,7 @@ * field_sql_storage.module, stores field data in the local SQL database. * * - @link field_purge Field API bulk data deletion @endlink: Cleans up after - * bulk deletion operations such as field_delete_field() and - * field_delete_instance(). + * bulk deletion operations such as deletion of field or field_instance. * * - @link field_language Field language API @endlink: Provides native * multilingual support for the Field API. diff --git a/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php b/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php index c555dc8..c74d426 100644 --- a/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php @@ -37,7 +37,7 @@ function testActive() { 'type' => 'field_sql_storage', ), ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); // Test disabling and enabling: // - the field type module, diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index d27bd7d..88b7798 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -104,10 +104,18 @@ function setUp() { } // Create two fields. - $field = array('field_name' => 'bf_1', 'type' => 'test_field', 'cardinality' => 1); - $this->fields[] = field_create_field($field); - $field = array('field_name' => 'bf_2', 'type' => 'test_field', 'cardinality' => 4); - $this->fields[] = field_create_field($field); + $this->fields[] = $field = entity_create('field_entity', array( + 'field_name' => 'bf_1', + 'type' => 'test_field', + 'cardinality' => 1 + )); + $field->save(); + $this->fields[] = $field = entity_create('field_entity', array( + 'field_name' => 'bf_2', + 'type' => 'test_field', + 'cardinality' => 4 + )); + $field->save(); // For each bundle, create an instance of each field, and 10 // entities with values for each field. @@ -115,18 +123,18 @@ function setUp() { $this->entity_type = 'test_entity'; foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { - $instance = array( - 'field_name' => $field['field_name'], + $this->instances[] = $instance = entity_create('field_instance', array( + 'field_name' => $field->id(), 'entity_type' => $this->entity_type, 'bundle' => $bundle, - ); - $this->instances[] = field_create_instance($instance); + )); + $instance->save(); } for ($i = 0; $i < 10; $i++) { $entity = field_test_create_entity($id, $id, $bundle); foreach ($this->fields as $field) { - $entity->{$field['field_name']}[Language::LANGCODE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']); + $entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field->cardinality); } $entity->save(); $id++; @@ -144,14 +152,13 @@ function setUp() { * the database and that the appropriate Field API functions can * operate on the deleted data and instance. * - * This tests how EntityFieldQuery interacts with - * field_delete_instance() and could be moved to FieldCrudTestCase, - * but depends on this class's setUp(). + * This tests how EntityFieldQuery interacts with field instance deletion and + * could be moved to FieldCrudTestCase, but depends on this class's setUp(). */ function testDeleteFieldInstance() { $bundle = reset($this->bundles); $field = reset($this->fields); - $field_name = $field['field_name']; + $field_name = $field->id(); $factory = \Drupal::service('entity.query'); // There are 10 entities of this bundle. @@ -161,11 +168,11 @@ function testDeleteFieldInstance() { $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->id(), $bundle); + $instance->delete(); // The instance still exists, deleted. - $instances = field_read_instances(array('field_id' => $field['uuid'], 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); + $instances = field_read_instances(array('field_id' => $field->id(), 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); $this->assertEqual($instances[0]['bundle'], $bundle, 'The deleted instance is for the correct bundle'); @@ -192,10 +199,10 @@ function testDeleteFieldInstance() { $ids->entity_id = $entity_id; $entities[$entity_id] = _field_create_entity_from_ids($ids); } - field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['uuid'], 'deleted' => TRUE)); + field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field->uuid, 'deleted' => TRUE)); $this->assertEqual(count($found), 10, 'Correct number of entities found after deleting'); foreach ($entities as $id => $entity) { - $this->assertEqual($this->entities[$id]->{$field['field_name']}, $entity->{$field['field_name']}, "Entity $id with deleted data loaded correctly"); + $this->assertEqual($this->entities[$id]->{$field->id()}, $entity->{$field->id()}, "Entity $id with deleted data loaded correctly"); } } @@ -211,8 +218,8 @@ function testPurgeInstance() { $field = reset($this->fields); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->id(), $bundle); + $instance->delete(); // No field hooks were called. $mem = field_test_memorize(); @@ -226,7 +233,7 @@ function testPurgeInstance() { // There are $count deleted entities left. $found = \Drupal::entityQuery('test_entity') ->condition('fttype', $bundle) - ->condition($field['field_name'] . '.deleted', 1) + ->condition($field->id() . '.deleted', 1) ->execute(); $this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2'); } @@ -238,7 +245,7 @@ function testPurgeInstance() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id()); foreach (array_chunk($entities, $batch_size, TRUE) as $chunk_entity) { $hooks['field_test_field_load'][] = $chunk_entity; } @@ -248,19 +255,19 @@ function testPurgeInstance() { $this->checkHooksInvocations($hooks, $actual_hooks); // The instance still exists, deleted. - $instances = field_read_instances(array('field_id' => $field['uuid'], 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); + $instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); // Purge the instance. field_purge_batch($batch_size); // The instance is gone. - $instances = field_read_instances(array('field_id' => $field['uuid'], 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); + $instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); $this->assertEqual(count($instances), 0, 'The instance is gone'); // The field still exists, not deleted, because it has a second instance. - $fields = field_read_fields(array('uuid' => $field['uuid']), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); - $this->assertTrue(isset($fields[$field['uuid']]), 'The field exists and is not deleted'); + $fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); + $this->assertTrue(isset($fields[$field->uuid]), 'The field exists and is not deleted'); } /** @@ -275,8 +282,8 @@ function testPurgeField() { // Delete the first instance. $bundle = reset($this->bundles); - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->id(), $bundle); + $instance->delete(); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); @@ -292,7 +299,7 @@ function testPurgeField() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id()); $hooks['field_test_field_load'][] = $entities; $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); @@ -301,13 +308,13 @@ function testPurgeField() { field_purge_batch(0); // The field still exists, not deleted. - $fields = field_read_fields(array('uuid' => $field['uuid']), array('include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$field['uuid']]) && !$fields[$field['uuid']]->deleted, 'The field exists and is not deleted'); + $fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); + $this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted'); // Delete the second instance. $bundle = next($this->bundles); - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->id(), $bundle); + $instance->delete(); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); @@ -319,20 +326,20 @@ 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['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id()); $hooks['field_test_field_load'][] = $entities; $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. - $fields = field_read_fields(array('uuid' => $field['uuid']), array('include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$field['uuid']]) && $fields[$field['uuid']]->deleted, 'The field exists and is deleted'); + $fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE)); + $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. field_purge_batch(0); // The field is gone. - $fields = field_read_fields(array('uuid' => $field['uuid']), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); + $fields = field_read_fields(array('uuid' => $field->uuid), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); $this->assertEqual(count($fields), 0, 'The field is purged.'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index 7960f82..bdd71ca 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -41,7 +41,8 @@ function testCreateField() { 'type' => 'test_field', ); field_test_memorize(); - $field = field_create_field($field_definition); + $field = entity_create('field_entity', $field_definition); + $field->save(); $mem = field_test_memorize(); $this->assertIdentical($mem['field_test_field_create_field'][0][0]['field_name'], $field_definition['field_name'], 'hook_field_create_field() called with correct arguments.'); $this->assertIdentical($mem['field_test_field_create_field'][0][0]['type'], $field_definition['type'], 'hook_field_create_field() called with correct arguments.'); @@ -67,7 +68,7 @@ function testCreateField() { // Guarantee that the name is unique. try { - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create two fields with the same name.')); } catch (FieldException $e) { @@ -79,7 +80,7 @@ function testCreateField() { $field_definition = array( 'field_name' => 'field_1', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create a field with no type.')); } catch (FieldException $e) { @@ -91,7 +92,7 @@ function testCreateField() { $field_definition = array( 'type' => 'test_field' ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create an unnamed field.')); } catch (FieldException $e) { @@ -104,7 +105,7 @@ function testCreateField() { 'field_name' => '2field_2', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create a field with a name starting with a digit.')); } catch (FieldException $e) { @@ -117,7 +118,7 @@ function testCreateField() { 'field_name' => 'field#_3', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create a field with a name containing an illegal character.')); } catch (FieldException $e) { @@ -130,7 +131,7 @@ function testCreateField() { 'field_name' => '_12345678901234567890123456789012', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create a field with a name longer than 32 characters.')); } catch (FieldException $e) { @@ -144,7 +145,7 @@ function testCreateField() { 'type' => 'test_field', 'field_name' => 'ftvid', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->fail(t('Cannot create a field bearing the name of an entity key.')); } catch (FieldException $e) { @@ -165,7 +166,7 @@ function testCreateFieldFail() { // Try to create the field. try { - $field = field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $this->assertTrue(FALSE, 'Field creation (correctly) fails.'); } catch (\Exception $e) { @@ -185,7 +186,7 @@ function testReadField() { 'field_name' => 'field_1', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); // Read the field back. $field = field_read_field($field_definition['field_name']); @@ -200,7 +201,7 @@ function testReadFields() { 'field_name' => 'field_1', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); // Check that 'single column' criteria works. $fields = field_read_fields(array('field_name' => $field_definition['field_name'])); @@ -218,7 +219,7 @@ function testReadFields() { 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', ); - field_create_instance($instance_definition); + entity_create('field_instance', $instance_definition)->save(); } /** @@ -230,7 +231,7 @@ function testFieldIndexes() { 'field_name' => 'field_1', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value')); @@ -245,7 +246,7 @@ function testFieldIndexes() { 'value' => array(), ), ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array()); @@ -260,7 +261,7 @@ function testFieldIndexes() { 'value_2' => array('value'), ), ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); @@ -275,9 +276,9 @@ function testDeleteField() { // Create two fields (so we can test that only one is deleted). $this->field = array('field_name' => 'field_1', 'type' => 'test_field'); - field_create_field($this->field); + entity_create('field_entity', $this->field)->save(); $this->another_field = array('field_name' => 'field_2', 'type' => 'test_field'); - field_create_field($this->another_field); + entity_create('field_entity', $this->another_field)->save(); // Create instances for each. $this->instance_definition = array( @@ -285,15 +286,15 @@ function testDeleteField() { 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', ); - field_create_instance($this->instance_definition); - $this->another_instance_definition = $this->instance_definition; - $this->another_instance_definition['field_name'] = $this->another_field['field_name']; - field_create_instance($this->another_instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); + $another_instance_definition = $this->instance_definition; + $another_instance_definition['field_name'] = $this->another_field['field_name']; + entity_create('field_instance', $another_instance_definition)->save(); // Test that the first field is not deleted, and then delete it. $field = field_read_field($this->field['field_name'], array('include_deleted' => TRUE)); $this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field is not marked for deletion.'); - field_delete_field($this->field['field_name']); + field_info_field($this->field['field_name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. @@ -316,13 +317,13 @@ function testDeleteField() { // 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', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']); + $another_instance = field_read_instance('test_entity', $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 // write data into it. - field_create_field($this->field); - field_create_instance($this->instance_definition); + entity_create('field_entity', $this->field)->save(); + 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']); @@ -346,12 +347,13 @@ function testDeleteField() { } function testUpdateFieldType() { - $field = array('field_name' => 'field_type', 'type' => 'number_decimal'); - $field = field_create_field($field); + $field_definition = array('field_name' => 'field_type', 'type' => 'number_decimal'); + $field = entity_create('field_entity', $field_definition); + $field->save(); - $test_field = array('field_name' => 'field_type', 'type' => 'number_integer'); try { - field_update_field($test_field); + $field->type = 'number_integer'; + $field->save(); $this->fail(t('Cannot update a field to a different type.')); } catch (FieldException $e) { @@ -367,21 +369,23 @@ function testUpdateField() { // respected. Since cardinality enforcement is consistent across database // systems, it makes a good test case. $cardinality = 4; - $field = field_create_field(array( + $field = entity_create('field_entity', array( 'field_name' => 'field_update', 'type' => 'test_field', 'cardinality' => $cardinality, )); - $instance = field_create_instance(array( + $field->save(); + $instance = entity_create('field_instance', array( 'field_name' => 'field_update', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', )); + $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 = 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::LANGCODE_NOT_SPECIFIED][$i]['value'] = $i; @@ -389,16 +393,16 @@ function testUpdateField() { // 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']); + $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'); + $this->assertEqual(count($entity->field_update[Language::LANGCODE_NOT_SPECIFIED]), $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'); } // Increase $cardinality and set the field cardinality to the new value. - $field['cardinality'] = ++$cardinality; - field_update_field($field); + $field->cardinality = ++$cardinality; + $field->save(); } while ($cardinality < 6); } @@ -406,19 +410,25 @@ function testUpdateField() { * Test field type modules forbidding an update. */ function testUpdateFieldForbid() { - $field = array('field_name' => 'forbidden', 'type' => 'test_field', 'settings' => array('changeable' => 0, 'unchangeable' => 0)); - $field = field_create_field($field); - $field['settings']['changeable']++; + $field = entity_create('field_entity', array( + 'field_name' => 'forbidden', + 'type' => 'test_field', + 'settings' => array( + 'changeable' => 0, + 'unchangeable' => 0 + )); + $field->save(); + $field->settings['changeable']++; try { - field_update_field($field); + $field->save(); $this->pass(t("A changeable setting can be updated.")); } catch (FieldException $e) { $this->fail(t("An unchangeable setting cannot be updated.")); } - $field['settings']['unchangeable']++; + $field->settings['unchangeable']++; try { - field_update_field($field); + $field->save(); $this->fail(t("An unchangeable setting can be updated.")); } catch (FieldException $e) { diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 9ca988e..aaec563 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -54,8 +54,8 @@ function setUp() { ), ); - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); // Create a display for the default view mode. entity_get_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name, $this->display_options['default']) diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php index b63d48d..3416f31 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -41,13 +41,13 @@ function setUp() { 'field_name' => 'test_view_field', 'type' => 'text', ); - field_create_field($this->field); + entity_create('field_entity', $this->field)->save(); $this->instance = array( 'field_name' => $this->field['field_name'], 'entity_type' => 'node', 'bundle' => $this->content_type, ); - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); // Assign display properties for the 'default' and 'teaser' view modes. foreach (array('default', 'teaser') as $view_mode) { diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index d16b25a..e795a5a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -192,9 +192,10 @@ function testFieldAttachPrepareViewMultiple() { // hook_field_formatter_prepare_view(). field_test_create_bundle('test_bundle_2'); $formatter_setting = $this->randomName(); - $this->instance2 = $this->instance; - $this->instance2['bundle'] = 'test_bundle_2'; - field_create_instance($this->instance2); + $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') ->setComponent($this->field['field_name'], array( @@ -268,9 +269,9 @@ function testFieldAttachCache() { 'fttype' => $this->instance['bundle'], )); $cid = "field:$entity_type:{$entity_init->ftid}"; - $instance = $this->instance; - $instance['entity_type'] = $entity_type; - field_create_instance($instance); + $instance_definition = $this->instance_definition; + $instance_definition['entity_type'] = $entity_type; + entity_create('field_instance', $instance_definition)->save(); // Check that no initial cache entry is present. $this->assertFalse(cache('field')->get($cid), 'Cached: no initial cache entry'); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 7192067..0e46e15 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -16,6 +16,14 @@ * all hook_field_attach_pre_{load,insert,update}() hooks. */ class FieldAttachStorageTest extends FieldUnitTestBase { + + /** + * The field instance. + * + * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + */ + protected $instance; + public static function getInfo() { return array( 'name' => 'Field attach tests (storage-related)', @@ -39,7 +47,7 @@ function testFieldAttachSaveLoad() { // Configure the instance so that we test hook_field_load() (see // field_test_field_load() in field_test.module). $this->instance['settings']['test_hook_field_load'] = TRUE; - field_update_instance($this->instance); + $this->instance->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; $entity_type = 'test_entity'; @@ -117,11 +125,11 @@ function testFieldAttachLoadMultiple() { ); for ($i = 1; $i <= 3; $i++) { $field_names[$i] = 'field_' . $i; - $field = array('field_name' => $field_names[$i], 'type' => 'test_field'); - $field = field_create_field($field); + $field = entity_create('field_entity', array('field_name' => $field_names[$i], 'type' => 'test_field')); + $field->save(); $field_ids[$i] = $field['uuid']; foreach ($field_bundles_map[$i] as $bundle) { - $instance = array( + entity_create('field_instance', array( 'field_name' => $field_names[$i], 'entity_type' => 'test_entity', 'bundle' => $bundles[$bundle], @@ -130,8 +138,7 @@ function testFieldAttachLoadMultiple() { // (see field_test_field_load() in field_test.module). 'test_hook_field_load' => TRUE, ), - ); - field_create_instance($instance); + ))->save(); } } @@ -191,13 +198,13 @@ function testFieldAttachSaveLoadDifferentStorage() { ), ); foreach ($fields as $field) { - field_create_field($field); + entity_create('field_entity', $field)->save(); $instance = array( 'field_name' => $field['field_name'], 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); } $entity_init = field_test_create_entity(); @@ -226,22 +233,19 @@ function testFieldAttachSaveLoadDifferentStorage() { */ function testFieldStorageDetailsAlter() { $field_name = 'field_test_change_my_details'; - $field = array( + $field = entity_create('field_entity', array( 'field_name' => $field_name, 'type' => 'test_field', 'cardinality' => 4, 'storage' => array('type' => 'field_test_storage'), - ); - $field = field_create_field($field); - $instance = array( + )); + $field->save(); + $instance = entity_create('field_instance', array( 'field_name' => $field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', - ); - field_create_instance($instance); - - $field = field_info_field($instance['field_name']); - $instance = field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']); + )); + $instance->save(); // The storage details are indexed by a storage engine type. $this->assertTrue(array_key_exists('drupal_variables', $field['storage_details']), 'The storage type is Drupal variables.'); @@ -345,7 +349,7 @@ function testFieldAttachSaveMissingData() { function testFieldAttachSaveMissingDataDefaultValue() { // Add a default value function. $this->instance['default_value_function'] = 'field_test_default_value'; - field_update_instance($this->instance); + $this->instance->save(); // Verify that fields are populated with default values. $entity_type = 'test_entity'; @@ -444,8 +448,8 @@ function testEntityCreateRenameBundle() { field_test_create_bundle($new_bundle); // Add an instance to that bundle. - $this->instance['bundle'] = $new_bundle; - field_create_instance($this->instance); + $this->instance_definition['bundle'] = $new_bundle; + entity_create('field_instance', $this->instance_definition)->save(); // Save an entity with data in the field. $entity = field_test_create_entity(0, 0, $this->instance['bundle']); @@ -483,13 +487,13 @@ function testEntityDeleteBundle() { field_test_create_bundle($new_bundle); // Add an instance to that bundle. - $this->instance['bundle'] = $new_bundle; - field_create_instance($this->instance); + $this->instance_definition['bundle'] = $new_bundle; + entity_create('field_instance', $this->instance_definition)->save(); // Create a second field for the test bundle $field_name = drupal_strtolower($this->randomName() . '_field_name'); $field = array('field_name' => $field_name, 'type' => 'test_field', 'cardinality' => 1); - field_create_field($field); + entity_create('field_entity', $field)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => 'test_entity', @@ -498,7 +502,7 @@ function testEntityDeleteBundle() { 'description' => $this->randomName() . '_description', 'weight' => mt_rand(0, 127), ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // Save an entity with data for both fields $entity = field_test_create_entity(0, 0, $this->instance['bundle']); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index dad0e54..dde8d57 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\field\Tests\FieldInfoTest. + * Contains \Drupal\field\Tests\FieldInfoTest. */ namespace Drupal\field\Tests; @@ -54,11 +54,11 @@ function testFieldInfo() { // Create a field, verify it shows up. $core_fields = field_info_fields(); - $field = array( + $field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', - ); - field_create_field($field); + )); + $field->save(); $fields = field_info_fields(); $this->assertEqual(count($fields), count($core_fields) + 1, 'One new field exists'); $this->assertEqual($fields[$field['field_name']]['field_name'], $field['field_name'], 'info fields contains field name'); @@ -72,7 +72,7 @@ function testFieldInfo() { $this->assertEqual($fields[$field['field_name']]['active'], TRUE, 'info fields contains active 1'); // Create an instance, verify that it shows up - $instance = array( + $instance_definition = array( 'field_name' => $field['field_name'], 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', @@ -80,14 +80,15 @@ function testFieldInfo() { 'description' => $this->randomName(), 'weight' => mt_rand(0, 127), ); - field_create_instance($instance); + $instance = entity_create('field_instance', $instance_definition); + $instance->save(); $info = entity_get_info('test_entity'); $instances = field_info_instances('test_entity', $instance['bundle']); $this->assertEqual(count($instances), 1, format_string('One instance shows up in info when attached to a bundle on a @label.', array( '@label' => $info['label'] ))); - $this->assertTrue($instance < $instances[$instance['field_name']], 'Instance appears in info correctly'); + $this->assertTrue($instance_definition < $instances[$instance['field_name']], 'Instance appears in info correctly'); // Test a valid entity type but an invalid bundle. $instances = field_info_instances('test_entity', 'invalid_bundle'); @@ -127,7 +128,8 @@ function testFieldPrepare() { 'field_name' => 'field', 'type' => 'test_field', ); - $field = field_create_field($field_definition); + $field = entity_create('field_entity', $field_definition); + $field->save(); // Simulate a stored field definition missing a field setting (e.g. a // third-party module adding a new field setting has been enabled, and @@ -153,13 +155,14 @@ function testInstancePrepare() { 'field_name' => 'field', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $instance_definition = array( 'field_name' => $field_definition['field_name'], 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', ); - $instance = field_create_instance($instance_definition); + $instance = entity_create('field_instance', $instance_definition); + $instance->save(); // Simulate a stored instance definition missing various settings (e.g. a // third-party module adding instance or widget settings has been enabled, @@ -189,13 +192,13 @@ function testInstanceDisabledEntityType() { 'field_name' => 'field', 'type' => 'test_field', ); - field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $instance_definition = array( 'field_name' => 'field', 'entity_type' => 'comment', 'bundle' => 'comment_node_article', ); - field_create_instance($instance_definition); + entity_create('field_instance', $instance_definition)->save(); // Disable coment module. This clears field_info cache. module_disable(array('comment')); @@ -224,7 +227,7 @@ function testFieldMap() { ), ); foreach ($fields as $field) { - field_create_field($field); + entity_create('field_entity', $field)->save(); } // Create a couple instances. @@ -251,7 +254,7 @@ function testFieldMap() { ), ); foreach ($instances as $instance) { - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); } $expected = array( @@ -308,11 +311,11 @@ function testFieldInfoCache() { // Create a test field and ensure it's in the array returned by // field_info_fields(). $field_name = drupal_strtolower($this->randomName()); - $field = array( + $field = entity_create('field_entity', array( 'field_name' => $field_name, 'type' => 'test_field', - ); - field_create_field($field); + )); + $field->save(); $fields = field_info_fields(); $this->assertTrue(isset($fields[$field_name]), 'The test field is initially found in the array returned by field_info_fields().'); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 5f9578a..4e8fff1 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -2,18 +2,36 @@ /** * @file - * Definition of Drupal\field\Tests\FieldInstanceCrudTest. + * Contains \Drupal\field\Tests\FieldInstanceCrudTest. */ namespace Drupal\field\Tests; use Drupal\field\FieldException; -use Drupal\field\Plugin\Core\Entity\FieldInstance; class FieldInstanceCrudTest extends FieldUnitTestBase { + /** + * The field entity. + * + * @var \Drupal\field\Plugin\Core\Entity\Field + */ protected $field; + /** + * The field entity definition. + * + * @var array + */ + protected $field_definition; + + /** + * The field instance entity definition. + * + * @var array + */ + protected $instance_definition; + public static function getInfo() { return array( 'name' => 'Field instance CRUD tests', @@ -25,11 +43,12 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->field = array( + $this->field_definition = array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', ); - field_create_field($this->field); + $this->field = entity_create('field_entity', $this->field_definition); + $this->field->save(); $this->instance_definition = array( 'field_name' => $this->field['field_name'], 'entity_type' => 'test_entity', @@ -47,14 +66,15 @@ function setUp() { * Test the creation of a field instance. */ function testCreateFieldInstance() { - $instance = field_create_instance($this->instance_definition); + $instance = entity_create('field_instance', $this->instance_definition); + $instance->save(); // Read the configuration. Check against raw configuration data rather than // the loaded ConfigEntity, to be sure we check that the defaults are // applied on write. $config = \Drupal::config('field.instance.' . $instance->id())->get(); - $field_type = field_info_field_types($this->field['type']); + $field_type = field_info_field_types($this->field_definition['type']); // Check that default values are set. $this->assertEqual($config['required'], FALSE, 'Required defaults to false.'); @@ -66,7 +86,7 @@ function testCreateFieldInstance() { // Guarantee that the field/bundle combination is unique. try { - field_create_instance($this->instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); $this->fail(t('Cannot create two instances with the same field / bundle combination.')); } catch (FieldException $e) { @@ -76,7 +96,7 @@ function testCreateFieldInstance() { // Check that the specified field exists. try { $this->instance_definition['field_name'] = $this->randomName(); - field_create_instance($this->instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); $this->fail(t('Cannot create an instance of a non-existing field.')); } catch (FieldException $e) { @@ -84,20 +104,21 @@ function testCreateFieldInstance() { } // Create a field restricted to a specific entity type. - $field_restricted = array( + $field_restricted_definition = array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', 'entity_types' => array('test_cacheable_entity'), ); - field_create_field($field_restricted); + $field_restricted = entity_create('field_entity', $field_restricted_definition); + $field_restricted->save(); // Check that an instance can be added to an entity type allowed // by the field. try { $instance = $this->instance_definition; - $instance['field_name'] = $field_restricted['field_name']; + $instance['field_name'] = $field_restricted_definition['field_name']; $instance['entity_type'] = 'test_cacheable_entity'; - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); $this->pass(t('Can create an instance on an entity type allowed by the field.')); } catch (FieldException $e) { @@ -108,8 +129,8 @@ function testCreateFieldInstance() { // forbidden by the field. try { $instance = $this->instance_definition; - $instance['field_name'] = $field_restricted['field_name']; - field_create_instance($instance); + $instance['field_name'] = $field_restricted_definition['field_name']; + entity_create('field_instance', $instance)->save(); $this->fail(t('Cannot create an instance on an entity type forbidden by the field.')); } catch (FieldException $e) { @@ -123,7 +144,7 @@ function testCreateFieldInstance() { * Test reading back an instance definition. */ function testReadFieldInstance() { - field_create_instance($this->instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); // Read the instance back. $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -136,7 +157,7 @@ function testReadFieldInstance() { * Test the update of a field instance. */ function testUpdateFieldInstance() { - field_create_instance($this->instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); // Check that basic changes are saved. $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -144,7 +165,7 @@ function testUpdateFieldInstance() { $instance['label'] = $this->randomName(); $instance['description'] = $this->randomName(); $instance['settings']['test_instance_setting'] = $this->randomName(); - field_update_instance($instance); + $instance->save(); $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $this->assertEqual($instance['required'], $instance_new['required'], '"required" change is saved'); @@ -164,15 +185,15 @@ function testDeleteFieldInstance() { // Create two instances for the same field so we can test that only one // is deleted. - field_create_instance($this->instance_definition); - $this->another_instance_definition = $this->instance_definition; - $this->another_instance_definition['bundle'] .= '_another_bundle'; - $instance = field_create_instance($this->another_instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); + $another_instance_definition = $this->instance_definition; + $another_instance_definition['bundle'] .= '_another_bundle'; + entity_create('field_instance', $another_instance_definition)->save(); // Test that the first instance is not deleted, and then delete it. $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); $this->assertTrue(!empty($instance) && empty($instance['deleted']), 'A new field instance is not marked for deletion.'); - field_delete_instance($instance); + $instance->delete(); // Make sure the instance is marked as deleted when the instance is // specifically loaded. @@ -184,11 +205,11 @@ function testDeleteFieldInstance() { $this->assertTrue(empty($instance), 'A deleted field instance is not loaded by default.'); // Make sure the other field instance is not deleted. - $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']); + $another_instance = field_read_instance('test_entity', $another_instance_definition['field_name'], $another_instance_definition['bundle']); $this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), 'A non-deleted field instance is not marked for deletion.'); // Make sure the field is deleted when its last instance is deleted. - field_delete_instance($another_instance); + $another_instance->delete(); $deleted_fields = \Drupal::state()->get('field.field.deleted'); $this->assertTrue(isset($deleted_fields[$another_instance['field_id']]), 'A deleted field is marked for deletion.'); $field = field_read_field($another_instance['field_name']); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index ed3c151..1199d2c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -54,12 +54,13 @@ function createFieldWithInstance($suffix = '') { $field = 'field' . $suffix; $field_id = 'field_id' . $suffix; $instance = 'instance' . $suffix; + $instance_definition = 'instance_definition' . $suffix; $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix); - $this->$field = array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4); - $this->$field = field_create_field($this->$field); + $this->$field = entity_create('field_entity', array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4)); + $this->$field->save(); $this->$field_id = $this->{$field}['uuid']; - $this->$instance = array( + $this->$instance_definition = array( 'field_name' => $this->$field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', @@ -70,7 +71,8 @@ function createFieldWithInstance($suffix = '') { 'test_instance_setting' => $this->randomName(), ), ); - field_create_instance($this->$instance); + $this->$instance = entity_create('field_instance', $this->$instance_definition); + $this->$instance->save(); entity_get_form_display('test_entity', 'test_bundle', 'default') ->setComponent($this->$field_name, array( diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 6e20523..1947c16 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -53,8 +53,8 @@ function testFieldFormSingle() { $this->field = $this->field_single; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); @@ -122,8 +122,8 @@ function testFieldFormDefaultValue() { $this->instance['field_name'] = $this->field_name; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); @@ -149,8 +149,8 @@ function testFieldFormSingleRequired() { $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; $this->instance['required'] = TRUE; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); @@ -182,16 +182,16 @@ function testFieldFormSingleRequired() { // $this->field = $this->field_multiple; // $this->field_name = $this->field['field_name']; // $this->instance['field_name'] = $this->field_name; -// field_create_field($this->field); -// field_create_instance($this->instance); +// entity_create('field_entity', $this->field)->save(); +// entity_create('field_instance', $this->instance)->save(); // } function testFieldFormUnlimited() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); @@ -273,28 +273,28 @@ function testFieldFormMultivalueWithRequiredRadio() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; // Add a required radio field. - field_create_field(array( + entity_create('field_entity', array( 'field_name' => 'required_radio_test', 'type' => 'list_text', 'settings' => array( 'allowed_values' => array('yes' => 'yes', 'no' => 'no'), ), - )); + ))->save(); $instance = array( 'field_name' => 'required_radio_test', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'required' => TRUE, ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') ->setComponent($instance['field_name'], array( 'type' => 'options_buttons', @@ -320,8 +320,8 @@ function testFieldFormJSAddMore() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name) ->save(); @@ -382,8 +382,8 @@ function testFieldFormMultipleWidget() { $this->field = $this->field_multiple; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->field_name, array( 'type' => 'test_field_widget_multiple', @@ -426,8 +426,8 @@ function testFieldFormAccess() { $field_name = $field['field_name']; $instance = $this->instance; $instance['field_name'] = $field_name; - field_create_field($field); - field_create_instance($instance); + entity_create('field_entity', $field)->save(); + entity_create('field_instance', $instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -444,8 +444,8 @@ function testFieldFormAccess() { 'bundle' => 'test_bundle', 'default_value' => array(0 => array('value' => 99)), ); - field_create_field($field_no_access); - field_create_instance($instance_no_access); + entity_create('field_entity', $field_no_access)->save(); + entity_create('field_instance', $instance_no_access)->save(); entity_get_form_display($instance_no_access['entity_type'], $instance_no_access['bundle'], 'default') ->setComponent($field_name_no_access) ->save(); @@ -501,17 +501,17 @@ function testFieldFormAccess() { */ function testNestedFieldForm() { // Add two instances on the 'test_bundle' - field_create_field($this->field_single); - field_create_field($this->field_unlimited); + entity_create('field_entity', $this->field_single)->save(); + entity_create('field_entity', $this->field_unlimited)->save(); $this->instance['field_name'] = 'field_single'; $this->instance['label'] = 'Single field'; - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); $this->instance['field_name'] = 'field_unlimited'; $this->instance['label'] = 'Unlimited field'; - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); @@ -619,8 +619,9 @@ function testFieldFormHiddenWidget() { $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; $this->instance['default_value'] = array(0 => array('value' => 99)); - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + $this->instance = entity_create('field_instance', $this->instance); + $this->instance->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name'], array( 'type' => 'hidden', @@ -644,7 +645,7 @@ function testFieldFormHiddenWidget() { // Update the instance to remove the default value and switch to the // default widget. $this->instance['default_value'] = NULL; - field_update_instance($this->instance); + $this->instance->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name'], array( 'type' => 'test_field_widget', diff --git a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php index 4e92d7e..3437924 100644 --- a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php @@ -38,13 +38,13 @@ public function setUp() { 'field_name' => 'field_shape', 'type' => 'shape', ); - field_create_field($this->field); + entity_create('field_entity', $this->field)->save(); $this->instance = array( 'entity_type' => 'entity_test', 'field_name' => 'field_shape', 'bundle' => 'entity_test', ); - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php index c8ff8fa..063dca4 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php @@ -38,13 +38,13 @@ public function setUp() { 'field_name' => 'field_test', 'type' => 'test_field', ); - field_create_field($this->field); + entity_create('field_entity', $this->field)->save(); $this->instance = array( 'entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', ); - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index ae52f2e..37787a8 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -49,7 +49,7 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - field_create_field($this->field_definition); + entity_create('field_entity', $this->field_definition)->save(); $this->field = field_read_field($this->field_name); $this->instance_definition = array( @@ -57,7 +57,7 @@ function setUp() { 'entity_type' => $this->entity_type, 'bundle' => 'test_bundle', ); - field_create_instance($this->instance_definition); + entity_create('field_instance', $this->instance_definition)->save(); $this->instance = field_read_instance('test_entity', $this->field_name, 'test_bundle'); for ($i = 0; $i < 3; ++$i) { @@ -95,7 +95,7 @@ function testFieldAvailableLanguages() { // Test field_available_languages() behavior for untranslatable fields. $this->field['translatable'] = FALSE; - field_update_field($this->field); + $this->field->save(); $available_langcodes = field_available_languages($this->entity_type, $this->field); $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === Language::LANGCODE_NOT_SPECIFIED, 'For untranslatable fields only Language::LANGCODE_NOT_SPECIFIED is available.'); } @@ -251,12 +251,13 @@ function testTranslatableFieldSaveLoad() { $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); $field_definition = $this->field_definition; $field_definition['field_name'] = $field_name_default; - $field = field_create_field($field_definition); + entity_create('field_entity', $field_definition)->save(); $instance_definition = $this->instance_definition; $instance_definition['field_name'] = $field_name_default; $instance_definition['default_value'] = array(array('value' => rand(1, 127))); - $instance = field_create_instance($instance_definition); + $instance = entity_create('field_instance', $instance_definition); + $instance->save(); $translation_langcodes = array_slice($available_langcodes, 0, 2); asort($translation_langcodes); @@ -310,14 +311,14 @@ function testFieldDisplayLanguage() { 'cardinality' => 2, 'translatable' => TRUE, ); - field_create_field($field); + entity_create('field_entity', $field)->save(); $instance = array( 'field_name' => $field['field_name'], 'entity_type' => $entity_type, 'bundle' => 'test_bundle', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); $entity = field_test_create_entity(1, 1, $this->instance['bundle']); $instances = field_info_instances($entity_type, $this->instance['bundle']); diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index 786f1b4..102c69c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -42,7 +42,7 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - field_create_field($field); + entity_create('field_entity', $field)->save(); $this->field = field_read_field($this->field_name); $instance = array( @@ -50,7 +50,7 @@ function setUp() { 'entity_type' => $this->entity_type, 'bundle' => 'test_bundle', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); $this->instance = field_read_instance('test_entity', $this->field_name, 'test_bundle'); entity_get_form_display($this->entity_type, 'test_bundle', 'default') diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php index f187422..386e35d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php @@ -36,7 +36,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => 'page', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // The second one will be attached to users only. $instance = array( @@ -44,7 +44,7 @@ function setUp() { 'entity_type' => 'user', 'bundle' => 'user', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // The third will be attached to both nodes and users. $instance = array( @@ -52,13 +52,13 @@ function setUp() { 'entity_type' => 'node', 'bundle' => 'page', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); $instance = array( 'field_name' => $field_names[2], 'entity_type' => 'user', 'bundle' => 'user', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // Now create some example nodes/users for the view result. for ($i = 0; $i < 5; $i++) { diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php index c0f500b..dcc43ae 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php @@ -58,7 +58,8 @@ function setUpFields($amount = 3) { $field_names[$i] = 'field_name_' . $i; $field = array('field_name' => $field_names[$i], 'type' => 'text'); - $this->fields[$i] = $field = field_create_field($field); + $this->fields[$i] = $field = entity_create('field_entity', $field); + $field->save(); } return $field_names; } @@ -70,7 +71,8 @@ function setUpInstances($bundle = 'page') { 'entity_type' => 'node', 'bundle' => 'page', ); - $this->instances[$key] = field_create_instance($instance); + $this->instances[$key] = entity_create('field_instance', $instance); + $this->instances[$key]->save(); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index b494a5a..4512089 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -47,9 +47,11 @@ protected function setUp() { $this->setUpFields(3); // Setup a field with cardinality > 1. - $this->fields[3] = $field = field_create_field(array('field_name' => 'field_name_3', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $this->fields[3] = $field = entity_create('field_entity', array('field_name' => 'field_name_3', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $field->save(); // Setup a field that will have no value. - $this->fields[4] = $field = field_create_field(array('field_name' => 'field_name_4', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $this->fields[4] = $field = entity_create('field_entity', array('field_name' => 'field_name_4', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $field->save(); $this->setUpInstances(); 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 c2070f2..7b963be 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -147,7 +147,7 @@ function field_test_field_language_alter(&$display_langcode, $context) { * field_test_memorize(); * * // call some Field API functions that invoke field_test hooks - * $field = field_create_field(...); + * entity_create('field_entity', $field_definition)->save(); * * // retrieve and reset the memorized hook call data * $mem = field_test_memorize(); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php index e9526d8..f35b254 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php @@ -49,8 +49,8 @@ function setUp() { // Make the body field translatable. // The parent class has already created the article and page content types. $field = field_info_field('body'); - $field['translatable'] = TRUE; - field_update_field($field); + $field->translatable = TRUE; + $field->save(); // Create a few page nodes with multilingual body values. $default_format = filter_default_format(); diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php index dfbb7ba..48d0293 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php @@ -34,22 +34,20 @@ protected function setUp() { parent::setUp(); // Create the test field. - $field = array( + entity_create('field_entity', array( 'settings' => array( 'target_type' => 'entity_test_mulrev', ), 'field_name' => 'field_test_entity_reference', 'type' => 'entity_reference', - ); - field_create_field($field); + ))->save(); // Create the test field instance. - $instance = array( + entity_create('field_instance', array( 'entity_type' => 'entity_test_mulrev', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test_mulrev', - ); - field_create_instance($instance); + ))->save(); } /** diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php index 1d9bff6..74fa8d9 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php @@ -26,13 +26,13 @@ protected function setUp() { $this->installConfig(array('field')); // Auto-create a field for testing. - field_create_field(array( + entity_create('field_entity', array( 'field_name' => 'field_test_text', 'type' => 'text', 'cardinality' => 1, 'translatable' => FALSE, - )); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test_mulrev', 'field_name' => 'field_test_text', 'bundle' => 'entity_test_mulrev', @@ -41,7 +41,7 @@ protected function setUp() { 'type' => 'text_textfield', 'weight' => 0, ), - ); - field_create_instance($instance); + ))->save(); } + } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php index b2eed63..4615b39 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php @@ -231,17 +231,16 @@ function testEnableModulesFixedList() { 'bundle' => 'entity_test', 'mode' => 'default', )); - $field = array( + $field = entity_create('field_entity', array( 'field_name' => 'test_field', 'type' => 'test_field' - ); - field_create_field($field); - $instance = array( - 'field_name' => $field['field_name'], + )); + $field->save(); + entity_create('field_instance', array( + 'field_name' => $field->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - field_create_instance($instance); + ))->save(); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php index d3ba0b7..f15f382 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php @@ -34,18 +34,16 @@ function setUp() { // Create a multi-valued field for 'page' nodes to use for Ajax testing. $field_name = 'field_ajax_test'; - $field = array( + entity_create('field_entity', array( 'field_name' => $field_name, 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, - ); - field_create_field($field); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page', - ); - field_create_instance($instance); + ))->save(); entity_get_form_display('node', 'page', 'default') ->setComponent($field_name, array('type' => 'text_default')) ->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 93fc552..4d24a51 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -598,8 +598,8 @@ public function testComputedProperties() { protected function assertComputedProperties($entity_type) { // Make the test text field processed. $instance = field_info_instance($entity_type, 'field_test_text', $entity_type); - $instance['settings']['text_processing'] = 1; - field_update_instance($instance); + $instance->settings['text_processing'] = 1; + $instance->save(); $entity = $this->createTestEntity($entity_type); $entity->field_test_text->value = "The text text to filter."; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php index 54c6934..faa7090 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php @@ -60,18 +60,17 @@ public function setUp() { // Add some fieldapi fields to be used in the test. for ($i = 1; $i <= 2; $i++) { - $field = array( - 'field_name' => 'field_test_' . $i, + $field_name = 'field_test_' . $i; + entity_create('field_entity', array( + 'field_name' => $field_name, 'type' => 'number_integer', 'cardinality' => 2, - ); - field_create_field($field); - $instance = array( - 'field_name' => $field['field_name'], + ))->save(); + entity_create('field_instance', array( + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - field_create_instance($instance); + ))->save(); } $entity = $this->entityStorageController->create(array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php index f36fca7..7a40d9b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php @@ -85,14 +85,13 @@ public function setUp() { 'type' => 'taxonomy_term_reference', ); $field['settings']['allowed_values']['vocabulary'] = $vocabulary->id(); - field_create_field($field); + entity_create('field_entity', $field)->save(); // Third, create the instance. - $instance = array( + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test', - ); - field_create_instance($instance); + ))->save(); // Create two terms and also two accounts. for ($i = 0; $i <= 1; $i++) { $term = entity_create('taxonomy_term', array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index 8b5b19b..b172572 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -61,13 +61,13 @@ function setUp() { $figures = drupal_strtolower($this->randomName()); $greetings = drupal_strtolower($this->randomName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { - $field = array( + $fields[] = $field = entity_create('field_enitty', array( 'field_name' => $field_name, 'type' => $field_type, 'cardinality' => 2, 'translatable' => TRUE, - ); - $fields[] = field_create_field($field); + )); + $field->save(); } $bundles = array(); for ($i = 0; $i < 2; $i++) { @@ -78,12 +78,11 @@ function setUp() { } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle)); entity_test_create_bundle($bundle); foreach ($fields as $field) { - $instance = array( - 'field_name' => $field['field_name'], + entity_create('field_instance', array( + 'field_name' => $field->id(), 'entity_type' => 'entity_test_mulrev', 'bundle' => $bundle, - ); - field_create_instance($instance); + ))->save(); } $bundles[] = $bundle; } @@ -410,12 +409,11 @@ protected function testCount() { // can test whether cross entity type fields produce the correct query. $field_name = $this->figures; $bundle = $this->randomName(); - $instance = array( + entity_create('field_entity', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => $bundle, - ); - field_create_instance($instance); + ))->save(); $entity = entity_create('entity_test', array( 'id' => 1, diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index 2a6e833..6623d3f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -105,8 +105,8 @@ function testEntityFormLanguage() { // Make body translatable. $field = field_info_field('body'); - $field['translatable'] = TRUE; - field_update_field($field); + $field->translatable = TRUE; + $field->save(); $field = field_info_field('body'); $this->assertTrue($field['translatable'], 'Field body is translatable.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index 919565c..a235add 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -50,23 +50,21 @@ function setUp() { // Create a translatable test field. $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); - $field = array( + entity_create('field_entity', array( 'field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4, 'translatable' => TRUE, - ); - field_create_field($field); + ))->save(); $this->field = field_read_field($this->field_name); // Create instance in all entity variations. foreach (entity_test_entity_types() as $entity_type) { - $instance = array( + entity_create('field_instance', array( 'field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, - ); - field_create_instance($instance); + ))->save(); $this->instance[$entity_type] = field_read_instance($entity_type, $this->field_name, $entity_type); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php index f049ac8..ff1bad3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php @@ -33,15 +33,13 @@ function setUp() { parent::setUp(); // Auto-create a field for testing. - $field = array( + entity_create('field_entity', array( 'field_name' => 'test_multiple', 'type' => 'text', 'cardinality' => -1, 'translatable' => FALSE, - ); - field_create_field($field); - - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'user', 'field_name' => 'test_multiple', 'bundle' => 'user', @@ -49,8 +47,7 @@ function setUp() { 'settings' => array( 'user_register_form' => TRUE, ), - ); - field_create_instance($instance); + ))->save(); entity_get_form_display('user', 'user', 'default') ->setComponent('test_multiple', array( 'type' => 'text_textfield', diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php index 8e9f649..c580e88 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php @@ -76,13 +76,13 @@ function testPreserveFormActionAfterAJAX() { 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, ); - field_create_field($field); + entity_create('field_entity', $field)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page', ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); entity_get_form_display('node', 'page', 'default') ->setComponent($field_name, array('type' => 'text_test')) ->save(); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.install b/core/modules/system/tests/modules/entity_test/entity_test.install index f7b8726..d6f1b34 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.install +++ b/core/modules/system/tests/modules/entity_test/entity_test.install @@ -10,13 +10,12 @@ */ function entity_test_install() { // Auto-create a field for testing. - $field = array( + entity_create('field_entity', array( 'field_name' => 'field_test_text', 'type' => 'text', 'cardinality' => 1, 'translatable' => FALSE, - ); - field_create_field($field); + ))->save(); $entity_types = array( 'entity_test', @@ -25,13 +24,12 @@ function entity_test_install() { 'entity_test_mulrev', ); foreach ($entity_types as $entity_type) { - $instance = array( + entity_create('field_instance', array( 'entity_type' => $entity_type, 'field_name' => 'field_test_text', 'bundle' => $entity_type, 'label' => 'Test text-field', - ); - field_create_instance($instance); + ))->save(); entity_get_form_display($entity_type, $entity_type, 'default') ->setComponent('field_test_text', array('type' => 'text_text')) diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 8da2c2b..a0fe1ff 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -195,34 +195,34 @@ function testRegistrationDefaultValues() { */ function testRegistrationWithUserFields() { // Create a field, and an instance on 'user' entity type. - $field = array( + $field = entity_create('field_entity', array( 'type' => 'test_field', 'field_name' => 'test_user_field', 'cardinality' => 1, - ); - field_create_field($field); - $instance = array( + )); + $field->save(); + $instance = entity_create('field_instance', array( 'field_name' => 'test_user_field', 'entity_type' => 'user', 'label' => 'Some user field', 'bundle' => 'user', 'required' => TRUE, 'settings' => array('user_register_form' => FALSE), - ); - field_create_instance($instance); + )); + $instance->save(); entity_get_form_display('user', 'user', 'default') ->setComponent('test_user_field', array('type' => 'test_field_widget')) ->save(); // Check that the field does not appear on the registration form. $this->drupalGet('user/register'); - $this->assertNoText($instance['label'], 'The field does not appear on user registration form'); + $this->assertNoText($instance->id(), 'The field does not appear on user registration form'); // Have the field appear on the registration form. - $instance['settings']['user_register_form'] = TRUE; - field_update_instance($instance); + $instance->settings['user_register_form'] = TRUE; + $instance->save(); $this->drupalGet('user/register'); - $this->assertText($instance['label'], 'The field appears on user registration form'); + $this->assertText($instance->id(), 'The field appears on user registration form'); // Check that validation errors are correctly reported. $edit = array(); @@ -231,11 +231,11 @@ function testRegistrationWithUserFields() { // Missing input in required field. $edit['test_user_field[und][0][value]'] = ''; $this->drupalPost(NULL, $edit, t('Create new account')); - $this->assertRaw(t('@name field is required.', array('@name' => $instance['label'])), 'Field validation error was correctly reported.'); + $this->assertRaw(t('@name field is required.', array('@name' => $instance->id()), 'Field validation error was correctly reported.'); // Invalid input. $edit['test_user_field[und][0][value]'] = '-1'; $this->drupalPost(NULL, $edit, t('Create new account')); - $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance['label'])), 'Field validation error was correctly reported.'); + $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance->id())), 'Field validation error was correctly reported.'); // Submit with valid data. $value = rand(1, 255); @@ -247,8 +247,8 @@ function testRegistrationWithUserFields() { $this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.'); // Check that the 'add more' button works. - $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED; - field_update_field($field); + $field->cardinality = FIELD_CARDINALITY_UNLIMITED; + $field->save(); foreach (array('js', 'nojs') as $js) { $this->drupalGet('user/register'); // Add two inputs. diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 69d96b6..d445d41 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -317,7 +317,7 @@ function user_install_picture_field() { 'default_image' => FALSE, ), ); - $field = field_create_field($field); + entity_create('field_entity', $field)->save(); $instance = array( 'field_name' => 'user_picture', @@ -337,7 +337,7 @@ function user_install_picture_field() { 'default_image' => 0, ), ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // Assign form display settings for the 'default' view mode. entity_get_form_display('user', 'user', 'default') diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index d5b51d8..acc24e6 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -61,7 +61,7 @@ protected function setUp() { // Setup a field and instance. $this->field_name = drupal_strtolower($this->randomName()); - $this->field = array( + entity_create('field_entity', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -72,14 +72,12 @@ protected function setUp() { ), ), ) - ); - field_create_field($this->field); - $this->instance = array( + ))->save(); + entity_create('field_instance', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page', - ); - field_create_instance($this->instance); + ))->save(); // Create a time in the past for the archive. $time = time() - 3600; diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index bb52895..2f870d8 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -55,7 +55,7 @@ function setUp() { $this->tag_vocabulary->save(); // Create the tag field itself. - $this->tag_field = array( + $this->tag_field = entity_create('field_entity', array( 'field_name' => 'field_views_testing_tags', 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -67,8 +67,8 @@ function setUp() { ), ), ), - ); - field_create_field($this->tag_field); + )); + $this->tag_field->save(); // Create an instance of the tag field on one of the content types, and // configure it to display an autocomplete widget. @@ -77,7 +77,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => $this->node_type_with_tags->type, ); - field_create_instance($this->tag_instance); + entity_create('field_instance', $this->tag_instance)->save(); entity_get_form_display('node', $this->node_type_with_tags->type, 'default') ->setComponent('field_views_testing_tags', array( @@ -108,7 +108,7 @@ function testTaggedWith() { $node_add_path = 'node/add/' . $this->node_type_with_tags->type; // Create three nodes, with different tags. - $tag_field = $this->tag_field['field_name'] . '[' . Language::LANGCODE_NOT_SPECIFIED . ']'; + $tag_field = $this->tag_field->id() . '[' . Language::LANGCODE_NOT_SPECIFIED . ']'; $edit = array(); $edit['title'] = $node_tag1_title = $this->randomName(); $edit[$tag_field] = 'tag1'; @@ -189,7 +189,7 @@ function testTaggedWithByNodeType() { // "tagged with" form element should not appear for it too. $instance = $this->tag_instance; $instance['bundle'] = $this->node_type_without_tags->type; - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); entity_get_form_display('node', $this->node_type_without_tags->type, 'default') ->setComponent('field_views_testing_tags', array( 'type' => 'taxonomy_autocomplete',