diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 095c28d..4731bbf 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -1644,7 +1644,7 @@ function hook_field_storage_create_field($field) { /** * Act on deletion of a field. * - * This hook is invoked from field_delete_field() to ask the field storage + * This hook is invoked from deletion of field entity to ask the field storage * module to mark all information stored in the field for deletion. * * @param $field @@ -1671,7 +1671,7 @@ function hook_field_storage_delete_field($field) { /** * Act on deletion of a field instance. * - * This hook is invoked from field_delete_instance() to ask the field storage + * This hook is invoked from deletion of field instance to ask the field storage * module to mark all information stored for the field instance for deletion. * * @param $instance @@ -1968,7 +1968,7 @@ function hook_field_update_field($field, $prior_field, $has_data) { /** * Act on a field being deleted. * - * This hook is invoked just after a field is deleted by field_delete_field(). + * This hook is invoked just after a field entity is deleted. * * @param $field * The field just deleted. @@ -1995,8 +1995,7 @@ function hook_field_update_instance($instance, $prior_instance) { /** * Act on a field instance being deleted. * - * This hook is invoked from field_delete_instance() after the instance is - * deleted. + * This hook is invoked after the instance is deleted. * * @param $instance * The instance just deleted. diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 9b24d94..d5149e2 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -1567,7 +1567,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' => 1)); foreach ($instances as $instance) { - field_delete_instance($instance); + $instance->delete(); } // Clear the cache. diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index 3138b00..51fab70 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -25,84 +25,6 @@ */ /** - * Creates a field. - * - * This function does not bind the field to any bundle; use - * field_create_instance() for that. - * - * @param array $field - * A field definition. The field_name and type properties are required. - * Other properties, if omitted, will be given the following default values: - * - cardinality: 1 - * - locked: FALSE - * - indexes: the field-type indexes, specified by the field type's - * hook_field_schema(). The indexes specified in $field are added - * to those default indexes. It is possible to override the - * definition of a field-type index by providing an index with the - * same name, or to remove it by redefining it as an empty array - * of columns. Overriding field-type indexes should be done - * carefully, for it might seriously affect the site's performance. - * - settings: each omitted setting is given the default value defined in - * hook_field_info(). - * - storage: - * - type: the storage backend specified in the 'field_storage_default' - * system variable. - * - settings: each omitted setting is given the default value specified in - * hook_field_storage_info(). - * - * @return \Drupal\field\Plugin\Core\Entity\Field - * The field entity. - * - * @throws Drupal\field\FieldException - * - * See: @link field Field API data structures @endlink. - */ -function field_create_field(array $field) { - $field = entity_create('field_entity', $field); - $field->save(); - return $field; -} - -/** - * Updates a field. - * - * Any module may forbid any update for any reason. For example, the - * field's storage module might forbid an update if it would change - * the storage schema while data for the field exists. A field type - * module might forbid an update if it would change existing data's - * semantics, or if there are external dependencies on field settings - * that cannot be updated. - * - * @param mixed $field - * Either the \Drupal\field\Plugin\Core\Entity\Field object to update, or a - * field array structure. If the latter, $field['field_name'] must provided; - * it identifies the field that will be updated to match this structure. Any - * other properties of the field that are not specified in $field will be left - * unchanged, so it is not necessary to pass in a fully populated $field - * structure. - * - * @throws Drupal\field\FieldException - * - * @see field_create_field() - */ -function field_update_field($field) { - // Module developers can still pass in an array of properties. - if (is_array($field)) { - $field_loaded = entity_load('field_entity', $field['field_name']); - if (empty($field_loaded)) { - throw new FieldException('Attempt to update a non-existent field.'); - } - // Merge incoming values. - foreach ($field as $key => $value) { - $field_loaded[$key] = $value; - } - $field = $field_loaded; - } - - $field->save(); -} - -/** * Reads a single field record directly from the database. * * Generally, you should use the field_info_field() instead. @@ -210,84 +132,6 @@ function field_read_fields($conditions = array(), $include_additional = array()) } /** - * Marks a field and its instances and data for deletion. - * - * @param $field_name - * The field name to delete. - */ -function field_delete_field($field_name) { - if ($field = field_info_field($field_name)) { - $field->delete(); - } -} - -/** - * Creates an instance of a field, binding it to a bundle. - * - * @param array $instance - * A field instance definition array. The field_name, entity_type and - * bundle properties are required. Other properties, if omitted, - * will be given the following default values: - * - label: the field name - * - description: empty string - * - required: FALSE - * - default_value_function: empty string - * - settings: each omitted setting is given the default value specified in - * hook_field_info(). - * - widget: - * - type: the default widget specified in hook_field_info(). - * - settings: each omitted setting is given the default value specified in - * hook_field_widget_info(). - * - * @return \Drupal\field\Plugin\Core\Entity\FieldInstance - * The field instance entity. - * - * @throws Drupal\field\FieldException - * - * See: @link field Field API data structures @endlink. - */ -function field_create_instance(array $instance) { - $instance = entity_create('field_instance', $instance); - $instance->save(); - return $instance; -} - -/** - * Updates an instance of a field. - * - * @param mixed $instance - * Either the \Drupal\field\Plugin\Core\Entity\FieldInstance to update, or an - * associative array representing an instance structure. If the latter, the - * required keys and values are: - * - entity_type: The type of the entity the field is attached to. - * - bundle: The bundle this field belongs to. - * - field_name: The name of an existing field. - * Read-only ID properties are assigned automatically. Any other properties - * properties specified in $instance overwrite the existing values for - * the instance. - * - * @throws Drupal\field\FieldException - * - * @see field_create_instance() - */ -function field_update_instance($instance) { - // Module developers can still pass in an array of properties. - if (is_array($instance)) { - $instance_loaded = entity_load('field_instance', $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name']); - if (empty($instance_loaded)) { - throw new FieldException('Attempt to update a non-existent instance.'); - } - // Merge incoming values. - foreach ($instance as $key => $value) { - $instance_loaded[$key] = $value; - } - $instance = $instance_loaded; - } - - $instance->save(); -} - -/** * Reads a single instance record from the database. * * Generally, you should use field_info_instance() instead, as it provides @@ -418,20 +262,6 @@ function field_read_instances($conditions = array(), $include_additional = array } /** - * Marks a field instance and its data for deletion. - * - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance - * The field instance. - * @param $field_cleanup - * If TRUE, the field will be deleted as well if its last instance is being - * deleted. If FALSE, it is the caller's responsibility to handle the case of - * fields left without instances. Defaults to TRUE. - */ -function field_delete_instance(FieldInstance $instance, $field_cleanup = TRUE) { - $instance->delete($field_cleanup); -} - -/** * @} End of "defgroup field_crud". */ diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 1e31484..3e8cce6 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -73,8 +73,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 9b03174..b862210 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -102,10 +102,12 @@ 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); + $field = entity_create('field_entity', array('field_name' => 'bf_1', 'type' => 'test_field', 'cardinality' => 1)); + $field->save(); + $this->fields[] = $field; + $field = entity_create('field_entity', array('field_name' => 'bf_2', 'type' => 'test_field', 'cardinality' => 4)); + $field->save(); + $this->fields[] = $field; // For each bundle, create an instance of each field, and 10 // entities with values for each field. @@ -113,15 +115,16 @@ function setUp() { $this->entity_type = 'test_entity'; foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { - $instance = array( + $instance = entity_create('field_instance', array( 'field_name' => $field['field_name'], 'entity_type' => $this->entity_type, 'bundle' => $bundle, 'widget' => array( 'type' => 'test_field_widget', - ) - ); - $this->instances[] = field_create_instance($instance); + ), + )); + $instance->save(); + $this->instances[] = $instance; } for ($i = 0; $i < 10; $i++) { @@ -145,9 +148,8 @@ 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); @@ -163,7 +165,7 @@ function testDeleteFieldInstance() { // Delete the instance. $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance->delete(); // The instance still exists, deleted. $instances = field_read_instances(array('field_id' => $field['uuid'], 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); @@ -213,7 +215,7 @@ function testPurgeInstance() { // Delete the instance. $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance->delete(); // No field hooks were called. $mem = field_test_memorize(); @@ -277,7 +279,7 @@ 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->delete(); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); @@ -308,7 +310,7 @@ function testPurgeField() { // Delete the second instance. $bundle = next($this->bundles); $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance->delete(); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index a0afa3f..923776d 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( @@ -288,15 +289,15 @@ function testDeleteField() { 'type' => 'test_field_widget', ), ); - 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. @@ -319,13 +320,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']); @@ -349,12 +350,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) { @@ -370,16 +372,18 @@ 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. @@ -401,7 +405,7 @@ function testUpdateField() { } // Increase $cardinality and set the field cardinality to the new value. $field['cardinality'] = ++$cardinality; - field_update_field($field); + $field->save(); } while ($cardinality < 6); } @@ -410,10 +414,11 @@ function testUpdateField() { */ function testUpdateFieldForbid() { $field = array('field_name' => 'forbidden', 'type' => 'test_field', 'settings' => array('changeable' => 0, 'unchangeable' => 0)); - $field = field_create_field($field); + $field = entity_create('field_entity', $field); + $field->save(); $field['settings']['changeable']++; try { - field_update_field($field); + $field->save(); $this->pass(t("A changeable setting can be updated.")); } catch (FieldException $e) { @@ -421,7 +426,7 @@ function testUpdateFieldForbid() { } $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 6f7d159..0d28bc0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -52,8 +52,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 86f1f34..b374e5e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -41,7 +41,7 @@ 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', @@ -50,7 +50,7 @@ function setUp() { 'type' => 'text_textfield', ), ); - 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 1ec87cf..1f70f74 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -191,9 +191,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( @@ -267,9 +268,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 38499c8..88ac7f0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -14,6 +14,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)', @@ -37,7 +45,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_NOT_SPECIFIED; $entity_type = 'test_entity'; @@ -115,11 +123,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], @@ -128,8 +136,7 @@ function testFieldAttachLoadMultiple() { // (see field_test_field_load() in field_test.module). 'test_hook_field_load' => TRUE, ), - ); - field_create_instance($instance); + ))->save(); } } @@ -189,13 +196,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(); @@ -224,22 +231,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.'); @@ -343,7 +347,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'; @@ -442,8 +446,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']); @@ -481,13 +485,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', @@ -500,7 +504,7 @@ function testEntityDeleteBundle() { 'type' => 'test_field_widget', 'settings' => array( 'size' => mt_rand(0, 255)))); - 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 0ae1dc0..e8e58cb 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'], 1, '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', @@ -83,15 +83,19 @@ function testFieldInfo() { 'widget' => array( 'type' => 'test_field_widget', 'settings' => array( - 'test_setting' => 999))); - field_create_instance($instance); + 'test_setting' => 999, + ), + ), + ); + $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'); @@ -131,7 +135,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 @@ -157,13 +162,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, @@ -199,13 +205,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')); @@ -234,7 +240,7 @@ function testFieldMap() { ), ); foreach ($fields as $field) { - field_create_field($field); + entity_create('field_entity', $field)->save(); } // Create a couple instances. @@ -261,7 +267,7 @@ function testFieldMap() { ), ); foreach ($instances as $instance) { - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); } $expected = array( @@ -318,11 +324,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 2455a31..e5d4847 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']); $widget_type = field_info_widget_types($field_type['default_widget']); // Check that default values are set. @@ -69,7 +89,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) { @@ -79,7 +99,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) { @@ -87,20 +107,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) { @@ -111,8 +132,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) { @@ -126,7 +147,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']); @@ -139,7 +160,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']); @@ -149,7 +170,7 @@ function testUpdateFieldInstance() { $instance['settings']['test_instance_setting'] = $this->randomName(); $instance['widget']['settings']['test_widget_setting'] =$this->randomName(); $instance['widget']['weight']++; - 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'); @@ -161,7 +182,7 @@ function testUpdateFieldInstance() { // Check that changing the widget type updates the default settings. $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $instance['widget']['type'] = 'test_field_widget_multiple'; - 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['widget']['type'], $instance_new['widget']['type'] , 'Widget type change is saved.'); @@ -181,15 +202,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. @@ -201,11 +222,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 3e1bf38..577847f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -55,12 +55,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', @@ -78,7 +79,8 @@ function createFieldWithInstance($suffix = '') { ) ) ); - field_create_instance($this->$instance); + $this->$instance = entity_create('field_instance', $this->$instance_definition); + $this->$instance->save(); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index b0a830d..496c3bb 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -57,8 +57,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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display creation form. @@ -123,8 +123,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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display creation form. @@ -147,8 +147,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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Submit with missing required value. @@ -177,16 +177,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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display creation form -> 1 widget. @@ -265,18 +265,18 @@ 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(); $langcode = LANGUAGE_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', @@ -286,7 +286,7 @@ function testFieldFormMultivalueWithRequiredRadio() { 'type' => 'options_buttons', ), ); - field_create_instance($instance); + entity_create('field_instance', $instance)->save(); // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -307,8 +307,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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display creation form -> 1 widget. @@ -367,8 +367,8 @@ function testFieldFormMultipleWidget() { $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; $this->instance['widget']['type'] = 'test_field_widget_multiple'; - field_create_field($this->field); - field_create_instance($this->instance); + entity_create('field_entity', $this->field)->save(); + entity_create('field_instance', $this->instance)->save(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display creation form. @@ -406,8 +406,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(); // Create a field with no edit access - see field_test_field_access(). $field_no_access = array( @@ -421,8 +421,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(); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -474,14 +474,14 @@ 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(); $this->instance['field_name'] = 'field_unlimited'; $this->instance['label'] = 'Unlimited field'; - field_create_instance($this->instance); + entity_create('field_instance', $this->instance)->save(); // Create two entities. $entity_1 = field_test_create_entity(1, 1); @@ -587,8 +587,9 @@ function testFieldFormHiddenWidget() { $this->instance['field_name'] = $this->field_name; $this->instance['widget']['type'] = 'hidden'; $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(); $langcode = LANGUAGE_NOT_SPECIFIED; // Display the entity creation form. @@ -608,7 +609,7 @@ function testFieldFormHiddenWidget() { // default widget. $this->instance['default_value'] = NULL; $this->instance['widget']['type'] = 'test_field_widget'; - field_update_instance($this->instance); + $this->instance->save(); // Display edit form. $this->drupalGet('test-entity/manage/' . $id . '/edit'); @@ -625,7 +626,7 @@ function testFieldFormHiddenWidget() { // Update the instance and switch to the Hidden widget again. $this->instance['widget']['type'] = 'hidden'; - field_update_instance($this->instance); + $this->instance->save(); // Create a new revision. $edit = array('revision' => TRUE); diff --git a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php index 2628256..19744f4 100644 --- a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php @@ -38,7 +38,7 @@ 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', @@ -47,7 +47,7 @@ public function setUp() { 'type' => 'test_field_widget', ), ); - 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 198be2a..08007bf 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php @@ -38,7 +38,7 @@ 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', @@ -47,7 +47,7 @@ public function setUp() { 'type' => 'test_field_widget', ), ); - 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 83be37d..1f13724 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_NOT_SPECIFIED, 'For untranslatable fields only LANGUAGE_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 40447f1..693cee5 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'); for ($i = 0; $i < 3; ++$i) { 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 54404b6..c6920c7 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 6d1975e..87df01c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -46,9 +46,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();