diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index b022efb..ba79656 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -10,7 +10,7 @@ */ function comment_uninstall() { // Delete comment_body field. - field_delete_field('comment_body'); + field_info_field('comment_body')->delete(); // Remove variables. variable_del('comment_block_count'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index a29db8c..4a63b23 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -41,7 +41,7 @@ function testCommentDefaultFields() { $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name))); // Delete the instance along the way. - field_delete_instance($instances['comment_node_' . $type_name]['comment_body']); + $instances['comment_node_' . $type_name]['comment_body']->delete(); } // Check that the 'comment_body' field is deleted. 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 87bd6bb..3d4a1ef 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..d229bd3 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -55,6 +55,9 @@ * * @throws Drupal\field\FieldException * + * @deprecated as of Drupal 8.0. Use + * entity_create('field_entity', $field)->save(). + * * See: @link field Field API data structures @endlink. */ function field_create_field(array $field) { @@ -83,6 +86,9 @@ function field_create_field(array $field) { * * @throws Drupal\field\FieldException * + * @deprecated as of Drupal 8.0. Use + * $field->save(). + * * @see field_create_field() */ function field_update_field($field) { @@ -214,6 +220,9 @@ function field_read_fields($conditions = array(), $include_additional = array()) * * @param $field_name * The field name to delete. + * + * @deprecated as of Drupal 8.0. Use + * $field->delete(). */ function field_delete_field($field_name) { if ($field = field_info_field($field_name)) { @@ -244,6 +253,9 @@ function field_delete_field($field_name) { * * @throws Drupal\field\FieldException * + * @deprecated as of Drupal 8.0. Use + * entity_create('field_instance', $instance)->save(). + * * See: @link field Field API data structures @endlink. */ function field_create_instance(array $instance) { @@ -268,6 +280,9 @@ function field_create_instance(array $instance) { * * @throws Drupal\field\FieldException * + * @deprecated as of Drupal 8.0. Use + * $instance->save(). + * * @see field_create_instance() */ function field_update_instance($instance) { @@ -426,6 +441,9 @@ function field_read_instances($conditions = array(), $include_additional = array * 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. + * + * @deprecated as of Drupal 8.0. Use + * $instance->delete($field_cleanup). */ function field_delete_instance(FieldInstance $instance, $field_cleanup = TRUE) { $instance->delete($field_cleanup); 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/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 9b03174..55f39e3 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -145,9 +145,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 +162,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 +212,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 +276,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 +307,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/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..69488bc 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -58,7 +58,8 @@ function createFieldWithInstance($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', $this->$field); + $this->$field->save(); $this->$field_id = $this->{$field}['uuid']; $this->$instance = array( 'field_name' => $this->$field_name, @@ -78,7 +79,7 @@ function createFieldWithInstance($suffix = '') { ) ) ); - field_create_instance($this->$instance); + entity_create('field_instance', $this->$instance); } /** diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index d73ffac..ceb6996 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -756,11 +756,11 @@ function field_ui_field_delete_form_submit($form, &$form_state) { $bundle_label = $bundles[$entity_type][$bundle]['label']; if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) { - field_delete_instance($instance); - drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label))); + $instance->delete(); + drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $instance->label(), '%type' => $bundle_label))); } else { - drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label)), 'error'); + drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $instance->label(), '%type' => $bundle_label)), 'error'); } $admin_path = field_ui_bundle_admin_path($entity_type, $bundle); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php index 4ca882b..18d57fa 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php @@ -207,7 +207,7 @@ function testNoFieldsDisplayOverview() { $this->drupalCreateContentType(array('type' => 'no_fields', 'name' => 'No fields')); // Remove the 'body' field. - field_delete_instance(field_info_instance('node', 'body', 'no_fields')); + field_info_instance('node', 'body', 'no_fields')->delete(); $this->drupalGet('admin/structure/types/manage/no_fields/display'); $this->assertRaw(t('There are no fields yet added. You can add new fields on the Manage fields page.', array('@link' => url('admin/structure/types/manage/no_fields/fields')))); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 81e87d0..d50ecb6 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -35,8 +35,6 @@ function testNodeDisplay() { ); $widget_settings = array(); $this->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); // Create a new node *without* the file field set, and check that the field // is not shown for each node display. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index d963b89..0a6fdcd 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -25,7 +25,7 @@ public static function getInfo() { function testUploadPath() { $field_name = strtolower($this->randomName()); $type_name = 'article'; - $field = $this->createFileField($field_name, $type_name); + $this->createFileField($field_name, $type_name); $test_file = $this->getTestFile('text'); // Create a new node. @@ -37,7 +37,7 @@ function testUploadPath() { $this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri))); // Change the path to contain multiple subdirectories. - $field = $this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz')); + $this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz')); // Upload a new file into the subdirectories. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); @@ -49,7 +49,7 @@ function testUploadPath() { // Check the path when used with tokens. // Change the path to contain multiple token directories. - $field = $this->updateFileField($field_name, $type_name, array('file_directory' => '[current-user:uid]/[current-user:name]')); + $this->updateFileField($field_name, $type_name, array('file_directory' => '[current-user:uid]/[current-user:name]')); // Upload a new file into the token subdirectories. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php index 1124e18..a66fd8d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php @@ -42,8 +42,6 @@ function testFileFieldRSSContent() { ); $widget_settings = array(); $this->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); // RSS display must be added manually. $this->drupalGet("admin/structure/types/manage/$type_name/display"); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index 47d19d1..3f2003a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -34,8 +34,6 @@ function testRevisions() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, $type_name); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); // Attach the same fields to users. $this->attachFileField($field_name, 'user', 'user'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index c2d922d..94eaf39 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -72,9 +72,10 @@ function createFileField($name, $type_name, $field_settings = array(), $instance 'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1, ); $field['settings'] = array_merge($field['settings'], $field_settings); - field_create_field($field); + $field = field_create_field($field); $this->attachFileField($name, 'node', $type_name, $instance_settings, $widget_settings); + return $field; } /** diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 7a40a1c..ce360c2 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -28,8 +28,7 @@ public static function getInfo() { function testRequired() { $type_name = 'article'; $field_name = strtolower($this->randomName()); - $this->createFileField($field_name, $type_name, array(), array('required' => '1')); - $field = field_info_field($field_name); + $field = $this->createFileField($field_name, $type_name, array(), array('required' => '1')); $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); @@ -51,7 +50,7 @@ function testRequired() { $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required field.')); // Try again with a multiple value field. - field_delete_field($field_name); + $field->delete(); $this->createFileField($field_name, $type_name, array('cardinality' => FIELD_CARDINALITY_UNLIMITED), array('required' => '1')); // Try to post a new node without uploading a file in the multivalue field. @@ -65,9 +64,6 @@ function testRequired() { $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading to the required multiple value field.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required multipel value field.')); - - // Remove our file field. - field_delete_field($field_name); } /** @@ -77,8 +73,6 @@ function testFileMaxSize() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, $type_name, array(), array('required' => '1')); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); $small_file = $this->getTestFile('text', 131072); // 128KB. $large_file = $this->getTestFile('text', 1310720); // 1.2MB @@ -93,7 +87,6 @@ function testFileMaxSize() { foreach ($sizes as $max_filesize => $file_limit) { // Set the max file upload size. $this->updateFileField($field_name, $type_name, array('max_filesize' => $max_filesize)); - $instance = field_info_instance('node', $field_name, $type_name); // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); @@ -117,9 +110,6 @@ function testFileMaxSize() { $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); - - // Remove our file field. - field_delete_field($field_name); } /** @@ -129,8 +119,6 @@ function testFileExtension() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, $type_name); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('image'); list(, $test_file_extension) = explode('.', $test_file->filename); @@ -162,8 +150,5 @@ function testFileExtension() { $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.')); - - // Remove our file field. - field_delete_field($field_name); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 352ce4b..0ea1337 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -34,8 +34,6 @@ function testSingleValuedWidget() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, $type_name); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); @@ -99,12 +97,6 @@ function testMultiValuedWidget() { $this->createFileField($field_name, $type_name, array('cardinality' => 3)); $this->createFileField($field_name2, $type_name, array('cardinality' => 3)); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); - - $field2 = field_info_field($field_name2); - $instance2 = field_info_instance('node', $field_name2, $type_name); - $test_file = $this->getTestFile('text'); foreach (array('nojs', 'js') as $type) { @@ -213,8 +205,6 @@ function testPrivateFileSetting() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, $type_name); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 4d56b7b..d4a9958 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -33,8 +33,6 @@ function testFileTokenReplacement() { $type_name = 'article'; $field_name = 'field_' . strtolower($this->randomName()); $this->createFileField($field_name, $type_name); - $field = field_info_field($field_name); - $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); // Coping a file to test uploads with non-latin filenames. diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 1bc6915..a534792 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -120,7 +120,7 @@ function forum_uninstall() { variable_del('node_options_forum'); - field_delete_field('taxonomy_forums'); + field_info_field('taxonomy_forums')->delete(); // Purge field data now to allow taxonomy module to be uninstalled // if this is the only field remaining. field_purge_batch(10); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 3632867..cceee63 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -169,7 +169,7 @@ function testFieldTranslationForm() { $this->assertRaw('Not translated'); // Delete the only translatable field. - field_delete_field('field_test_et_ui_test'); + field_info_field('field_test_et_ui_test')->delete(); // Visit translation page. $this->drupalGet('node/' . $article->nid . '/translations'); diff --git a/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module b/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module index 3d67454..3579719 100644 --- a/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module +++ b/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module @@ -75,5 +75,5 @@ function node_access_test_language_enable() { * Implements hook_disable(). */ function node_access_test_language_disable() { - field_delete_instance(field_read_instance('node', 'field_private', 'page')); + field_read_instance('node', 'field_private', 'page')->delete(); } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 11ab663..fc7b8f8 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -77,7 +77,7 @@ function testUpdateAllowedValues() { $entity->save(); $this->field['settings']['allowed_values'] = array(2 => 'Two'); try { - field_update_field($this->field); + $this->field->save(); $this->fail(t('Cannot update a list field to not include keys with existing data.')); } catch (FieldException $e) { @@ -89,7 +89,7 @@ function testUpdateAllowedValues() { // Removed options do not appear. $this->field['settings']['allowed_values'] = array(2 => 'Two'); - field_update_field($this->field); + $this->field->save(); $entity = entity_create('entity_test', array()); $form = entity_get_form($entity); $this->assertTrue(empty($form[$this->field_name][$langcode][1]), 'Option 1 does not exist'); @@ -98,7 +98,7 @@ function testUpdateAllowedValues() { // Completely new options appear. $this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); - field_update_field($this->field); + $this->field->save(); $form = entity_get_form($entity); $this->assertTrue(empty($form[$this->field_name][$langcode][1]), 'Option 1 does not exist'); $this->assertTrue(empty($form[$this->field_name][$langcode][2]), 'Option 2 does not exist'); @@ -107,8 +107,7 @@ function testUpdateAllowedValues() { $this->assertTrue(!empty($form[$this->field_name][$langcode][20]), 'Option 20 exists'); // Options are reset when a new field with the same name is created. - field_delete_field($this->field_name); - unset($this->field['id']); + $this->field->delete(); field_create_field($this->field_definition); $this->instance = array( 'field_name' => $this->field_name, diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php index dcda5e8..80401e1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -36,7 +36,7 @@ protected function postSave(EntityInterface $entity, $update) { } } if ($update_field) { - field_update_field($field); + $field->save(); } } } @@ -82,11 +82,11 @@ protected function postDelete($entities) { } if ($modified_field) { if (empty($taxonomy_field['settings']['allowed_values'])) { - field_delete_field($field_name); + $taxonomy_field->delete(); } else { // Update the field definition with the new allowed values. - field_update_field($taxonomy_field); + $taxonomy_field->save(); } } }