diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module
index 1bcf414..ef32e3c 100644
--- a/core/modules/block/custom_block/custom_block.module
+++ b/core/modules/block/custom_block/custom_block.module
@@ -220,23 +220,23 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') {
$field = field_info_field('block_body');
$instance = field_info_instance('custom_block', 'block_body', $block_type_id);
if (empty($field)) {
- $field = array(
+ $field = entity_create('field_entity', array(
'field_name' => 'block_body',
'type' => 'text_with_summary',
'entity_types' => array('custom_block'),
- );
- $field = field_create_field($field);
+ ));
+ $field->save();
}
if (empty($instance)) {
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => 'block_body',
'entity_type' => 'custom_block',
'bundle' => $block_type_id,
'label' => $label,
'widget' => array('type' => 'text_textarea_with_summary'),
'settings' => array('display_summary' => FALSE),
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
// Assign display settings for 'default' view mode.
entity_get_display('custom_block', $block_type_id, 'default')
diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
index 8d49349..e96f5c6 100644
--- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
+++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
@@ -64,13 +64,13 @@ public function testBlockFields() {
$this->blockType = $this->createCustomBlockType('link');
// Create a field with settings to validate.
- $this->field = array(
+ $this->field = entity_create('field_entity', array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'link',
'cardinality' => 2,
- );
- field_create_field($this->field);
- $this->instance = array(
+ ));
+ $this->field->save();
+ $this->instance = entity_create('field_instance', array(
'field_name' => $this->field['field_name'],
'entity_type' => 'custom_block',
'bundle' => 'link',
@@ -80,12 +80,12 @@ public function testBlockFields() {
'widget' => array(
'type' => 'link_default',
),
- );
+ ));
+ $this->instance->save();
$display_options = array(
'type' => 'link',
'label' => 'hidden',
);
- field_create_instance($this->instance);
entity_get_display('custom_block', 'link', 'default')
->setComponent($this->field['field_name'], $display_options)
->save();
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/comment.module b/core/modules/comment/comment.module
index 8466ce2..5bfdb0b 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -361,26 +361,26 @@ function comment_node_type_delete($info) {
function _comment_body_field_create($info) {
// Create the field if needed.
if (!field_read_field('comment_body', array('include_inactive' => TRUE))) {
- $field = array(
+ $field = entity_create('field_entity', array(
'field_name' => 'comment_body',
'type' => 'text_long',
'entity_types' => array('comment'),
- );
- field_create_field($field);
+ ));
+ $field->save();
}
// Create the instance if needed.
if (!field_read_instance('comment', 'comment_body', 'comment_node_' . $info->type, array('include_inactive' => TRUE))) {
entity_invoke_bundle_hook('create', 'comment', 'comment_node_' . $info->type);
// Attaches the body field by default.
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => 'comment_body',
'label' => 'Comment',
'entity_type' => 'comment',
'bundle' => 'comment_node_' . $info->type,
'settings' => array('text_processing' => 1),
'required' => TRUE,
- );
- field_create_instance($instance);
+ ));
+ $instance->save();
entity_get_display('comment', 'comment_node_' . $info->type, 'default')
->setComponent('comment_body', array(
'label' => 'hidden',
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php
index c92d2ab..ecd464a 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/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php
index 35a935e..85430f0 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php
@@ -72,7 +72,7 @@ function setUp() {
// Make comment body translatable.
$field = field_info_field('comment_body');
$field['translatable'] = TRUE;
- field_update_field($field);
+ $field->save();
$this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.');
}
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
index 100e02f..2a14791 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
@@ -65,7 +65,7 @@ function setupTestFields() {
parent::setupTestFields();
$field = field_info_field('comment_body');
$field['translatable'] = TRUE;
- field_update_field($field);
+ $field->save();
}
/**
diff --git a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php
index 0ce0071..2263ea0 100644
--- a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php
+++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php
@@ -39,19 +39,17 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
- $field = array(
+ $this->field = entity_create('field_entity', array(
'field_name' => strtolower($this->randomName()),
'type' => 'text'
- );
-
- $this->field = field_create_field($field);
+ ));
+ $this->field->save();
- $instance = array(
- 'field_name' => $field['field_name'],
+ entity_create('field_instance', array(
+ 'field_name' => $this->field['field_name'],
'entity_type' => 'contact_message',
'bundle' => 'contact_message',
- );
- field_create_instance($instance);
+ ))->save();
$this->container->get('views.views_data')->clear();
}
diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
index bb3bddf..ce162ec 100644
--- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
+++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
@@ -48,12 +48,13 @@ function setUp() {
$this->drupalLogin($web_user);
// Create a field with settings to validate.
- $this->field = field_create_field(array(
+ $this->field = entity_create('field_entity', array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'datetime',
'settings' => array('datetime_type' => 'date'),
));
- $this->instance = field_create_instance(array(
+ $this->field->save();
+ $this->instance = entity_create('field_instance', array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@@ -64,6 +65,7 @@ function setUp() {
'default_value' => 'blank',
),
));
+ $this->instance->save();
$this->display_options = array(
'type' => 'datetime_default',
@@ -147,7 +149,7 @@ function testDatetimeField() {
// Change the field to a datetime field.
$this->field['settings']['datetime_type'] = 'datetime';
- field_update_field($this->field);
+ $this->field->save();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
@@ -214,7 +216,7 @@ function testDatelistWidget() {
// Change the field to a datetime field.
$this->field['settings']['datetime_type'] = 'datetime';
- field_update_field($this->field);
+ $this->field->save();
// Change the widget to a datelist widget.
$increment = 1;
@@ -227,7 +229,7 @@ function testDatelistWidget() {
'date_order' => $date_order,
'time_type' => $time_type,
);
- field_update_instance($this->instance);
+ $this->instance->save();
field_cache_clear();
// Display creation form.
@@ -280,12 +282,12 @@ function testDefaultValue() {
// Change the field to a datetime field.
$this->field['settings']['datetime_type'] = 'datetime';
- field_update_field($this->field);
+ $this->field->save();
// Set the default value to 'now'.
$this->instance['settings']['default_value'] = 'now';
$this->instance['default_value_function'] = 'datetime_default_value';
- field_update_instance($this->instance);
+ $this->instance->save();
// Display creation form.
$date = new DrupalDateTime();
@@ -303,7 +305,7 @@ function testDefaultValue() {
// Set the default value to 'blank'.
$this->instance['settings']['default_value'] = 'blank';
$this->instance['default_value_function'] = 'datetime_default_value';
- field_update_instance($this->instance);
+ $this->instance->save();
// Display creation form.
$date = new DrupalDateTime();
@@ -321,7 +323,7 @@ function testInvalidField() {
// Change the field to a datetime field.
$this->field['settings']['datetime_type'] = 'datetime';
- field_update_field($this->field);
+ $this->field->save();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
index d3737bb..8863e47 100644
--- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
+++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
@@ -59,10 +59,11 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst
'type' => $type,
'cardinality' => $cardinality,
);
- $this->$field = field_create_field($this->field);
+ $this->$field = entity_create('field_entity', $this->field);
+ $this->$field->save();
$instance = $field_name . '_instance';
- $this->$instance = array(
+ $this->$instance = entity_create('field_instance', array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
@@ -75,8 +76,8 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst
'label' => $label,
'settings' => $widget_settings,
),
- );
- field_create_instance($this->$instance);
+ ));
+ $this->$instance->save();
entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
index 26ec6c0..c3844e2 100644
--- a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
+++ b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
@@ -80,23 +80,23 @@ function testText() {
// Editor selection with text processing, cardinality 1.
$this->field_text_instance['settings']['text_processing'] = 1;
- field_update_instance($this->field_text_instance);
+ $this->field_text_instance->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With text processing, cardinality 1, the 'form' editor is selected.");
// Editor selection without text processing, cardinality 1 (again).
$this->field_text_instance['settings']['text_processing'] = 0;
- field_update_instance($this->field_text_instance);
+ $this->field_text_instance->save();
$this->assertEqual('direct', $this->getSelectedEditor($items, $field_name), "Without text processing again, cardinality 1, the 'direct' editor is selected.");
// Editor selection without text processing, cardinality >1
$this->field_text_field['cardinality'] = 2;
- field_update_field($this->field_text_field);
+ $this->field_text_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "Without text processing, cardinality >1, the 'form' editor is selected.");
// Editor selection with text processing, cardinality >1
$this->field_text_instance['settings']['text_processing'] = 1;
- field_update_instance($this->field_text_instance);
+ $this->field_text_instance->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With text processing, cardinality >1, the 'form' editor is selected.");
}
@@ -135,7 +135,7 @@ function testTextWysiwyg() {
// Editor selection with text processing, cardinality >1
$this->field_textarea_field['cardinality'] = 2;
- field_update_field($this->field_textarea_field);
+ $this->field_textarea_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
@@ -165,7 +165,7 @@ function testNumber() {
// Editor selection with cardinality >1.
$this->field_nr_field['cardinality'] = 2;
- field_update_field($this->field_nr_field);
+ $this->field_nr_field->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, the 'form' editor is selected.");
}
diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
index 1dcadc8..8441b01 100644
--- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
+++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
@@ -137,7 +137,7 @@ function testEditorSelection() {
// Editor selection with text processing, cardinality >1
$this->field_textarea_field['cardinality'] = 2;
- field_update_field($this->field_textarea_field);
+ $this->field_textarea_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
index c719c97..6895c42 100644
--- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
+++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
@@ -49,7 +49,7 @@ function testEmailField() {
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'email',
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -61,7 +61,7 @@ function testEmailField() {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
// Create a display for the full view mode.
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field['field_name'], array(
diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
index def99f1..74cf029 100644
--- a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
+++ b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
@@ -39,7 +39,7 @@ public function setUp() {
'field_name' => 'field_email',
'type' => 'email',
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_email',
@@ -48,7 +48,7 @@ public function setUp() {
'type' => 'email_default',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
}
/**
diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
index 11f6da7..67d1735 100644
--- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
+++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
@@ -144,13 +144,13 @@ public function testFieldComponent() {
'field_name' => 'test_field',
'type' => 'test_field'
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Check that providing no options results in default values being used.
$display->setComponent($field['field_name']);
diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module
index 3c68c46..2e47c31 100644
--- a/core/modules/entity_reference/entity_reference.module
+++ b/core/modules/entity_reference/entity_reference.module
@@ -218,7 +218,7 @@ function entity_reference_field_update_field($field, $prior_field, $has_data) {
foreach ($bundles as $bundle) {
$instance = field_info_instance($entity_type, $field_name, $bundle);
$instance['settings']['handler_settings'] = array();
- field_update_instance($instance);
+ $instance->save();
}
}
}
@@ -453,7 +453,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
'target_type' => $target_entity_type,
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
}
if (empty($instance)) {
@@ -467,6 +467,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
'handler_settings' => $selection_handler_settings,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
}
+
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
index 99ebe15..0d97a6f 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
@@ -45,7 +45,7 @@ function setUp() {
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'label' => 'Entity reference field',
@@ -65,7 +65,7 @@ function setUp() {
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
index d3245e0..253249d 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
@@ -41,7 +41,7 @@ public function testSort() {
'type' => 'text',
'entity_types' => array('node'),
);
- field_create_field($field_info);
+ entity_create('field_entity', $field_info)->save();
$instance_info = array(
'label' => 'Text Field',
@@ -51,7 +51,7 @@ public function testSort() {
'settings' => array(),
'required' => FALSE,
);
- field_create_instance($instance_info);
+ entity_create('field_instance', $instance_info)->save();
// Build a fake field instance.
diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc
index cde15f4..8479b95 100644
--- a/core/modules/field/field.attach.inc
+++ b/core/modules/field/field.attach.inc
@@ -1568,7 +1568,7 @@ function field_entity_bundle_delete($entity_type, $bundle) {
// entity types or bundles.
$instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle), array('include_inactive' => TRUE));
foreach ($instances as $instance) {
- field_delete_instance($instance);
+ $instance->delete();
}
// Clear the cache.
diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc
index ec2daa3..b0d124a 100644
--- a/core/modules/field/field.crud.inc
+++ b/core/modules/field/field.crud.inc
@@ -25,89 +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.settings.default_storage' configuration.
- * - 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
- *
- * @deprecated as of Drupal 8.0. Use
- * entity_create('field_entity', $definition)->save().
- *
- * 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
- *
- * @deprecated as of Drupal 8.0. Use $field->save().
- *
- * @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.
@@ -215,103 +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.
- *
- * @deprecated as of Drupal 8.0. Use $field->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
- *
- * @deprecated as of Drupal 8.0. Use
- * entity_create('field_instance', $definition)->save().
- *
- * 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.
- * The other array elements represent properties of the instance, and all
- * properties must be specified or their default values will be used (except
- * internal-use properties, which are assigned automatically). To avoid losing
- * the previously stored properties of the instance when making a change,
- * first load the instance with field_info_instance(), then override the
- * values you want to override, and finally save using this function. Example:
- * @code
- * // Fetch an instance info array.
- * $instance_info = field_info_instance($entity_type, $field_name, $bundle_name);
- * // Change a single property in the instance definition.
- * $instance_info['definition']['required'] = TRUE;
- * // Write the changed definition back.
- * field_update_instance($instance_info['definition']);
- * @endcode
- *
- * @throws Drupal\field\FieldException
- *
- * @deprecated as of Drupal 8.0. Use $instance->save().
- *
- * @see field_info_instance()
- * @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
@@ -439,22 +259,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.
- *
- * @deprecated as of Drupal 8.0. Use $instance->delete().
- */
-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 8f459a3..4a08e4f 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 ca414bc..1ebacbc 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' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE));
@@ -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 9ee6019..7c93bd2 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 122d14c..e4ab9f7 100644
--- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Definition of Drupal\field\Tests\FieldInfoTest.
+ * Contains \Drupal\field\Tests\FieldInfoTest.
*/
namespace Drupal\field\Tests;
@@ -54,11 +54,11 @@ function testFieldInfo() {
// Create a field, verify it shows up.
$core_fields = field_info_fields();
- $field = array(
+ $field = entity_create('field_entity', array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'test_field',
- );
- field_create_field($field);
+ ));
+ $field->save();
$fields = field_info_fields();
$this->assertEqual(count($fields), count($core_fields) + 1, 'One new field exists');
$this->assertEqual($fields[$field['field_name']]['field_name'], $field['field_name'], 'info fields contains field name');
@@ -72,7 +72,7 @@ function testFieldInfo() {
$this->assertEqual($fields[$field['field_name']]['active'], TRUE, 'info fields contains active 1');
// Create an instance, verify that it shows up
- $instance = array(
+ $instance_definition = array(
'field_name' => $field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@@ -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 223e0ac..d609569 100644
--- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php
+++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php
@@ -54,12 +54,13 @@ function createFieldWithInstance($suffix = '') {
$field = 'field' . $suffix;
$field_id = 'field_id' . $suffix;
$instance = 'instance' . $suffix;
+ $instance_definition = 'instance_definition' . $suffix;
$this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix);
- $this->$field = array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4);
- $this->$field = field_create_field($this->$field);
+ $this->$field = entity_create('field_entity', array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4));
+ $this->$field->save();
$this->$field_id = $this->{$field}['uuid'];
- $this->$instance = array(
+ $this->$instance_definition = array(
'field_name' => $this->$field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@@ -77,7 +78,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 24b7063..0636e96 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();
diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module
index 4ecd1a9..134db4d 100644
--- a/core/modules/field/tests/modules/field_test/field_test.module
+++ b/core/modules/field/tests/modules/field_test/field_test.module
@@ -147,7 +147,7 @@ function field_test_field_language_alter(&$display_langcode, $context) {
* field_test_memorize();
*
* // call some Field API functions that invoke field_test hooks
- * $field = field_create_field(...);
+ * entity_create('field_entity', $field_definition)->save();
*
* // retrieve and reset the memorized hook call data
* $mem = field_test_memorize();
diff --git a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php
index 5263787..3548fc2 100644
--- a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php
+++ b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php
@@ -41,14 +41,18 @@ function setUp() {
$this->installSchema('field_test', array('test_entity', 'test_entity_revision', 'test_entity_bundle'));
$this->field_name = strtolower($this->randomName());
- $this->field = array('field_name' => $this->field_name, 'type' => 'test_field', 'cardinality' => 4);
- $this->field = field_create_field($this->field);
- $this->instance = array(
+ $this->field = entity_create('field_entity', array(
+ 'field_name' => $this->field_name,
+ 'type' => 'test_field',
+ 'cardinality' => 4,
+ ));
+ $this->field->save();
+ $this->instance = entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle'
- );
- $this->instance = field_create_instance($this->instance);
+ ));
+ $this->instance->save();
$this->table = _field_sql_storage_tablename($this->field);
$this->revision_table = _field_sql_storage_revision_tablename($this->field);
@@ -305,10 +309,18 @@ function testFieldAttachSaveMissingData() {
*/
function testUpdateFieldSchemaWithData() {
// Create a decimal 5.2 field and add some data.
- $field = array('field_name' => 'decimal52', 'type' => 'number_decimal', 'settings' => array('precision' => 5, 'scale' => 2));
- $field = field_create_field($field);
- $instance = array('field_name' => 'decimal52', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle');
- $instance = field_create_instance($instance);
+ $field = entity_create('field_entity', array(
+ 'field_name' => 'decimal52',
+ 'type' => 'number_decimal',
+ 'settings' => array('precision' => 5, 'scale' => 2),
+ ));
+ $field->save();
+ $instance = entity_create('field_instance', array(
+ 'field_name' => 'decimal52',
+ 'entity_type' => 'test_entity',
+ 'bundle' => 'test_bundle',
+ ));
+ $instance->save();
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$entity->decimal52[LANGUAGE_NOT_SPECIFIED][0]['value'] = '1.235';
$entity->save();
@@ -316,7 +328,7 @@ function testUpdateFieldSchemaWithData() {
// Attempt to update the field in a way that would work without data.
$field['settings']['scale'] = 3;
try {
- field_update_field($field);
+ $field->save();
$this->fail(t('Cannot update field schema with data.'));
}
catch (FieldException $e) {
@@ -329,14 +341,18 @@ function testUpdateFieldSchemaWithData() {
*/
function testFieldUpdateFailure() {
// Create a text field.
- $field = array('field_name' => 'test_text', 'type' => 'text', 'settings' => array('max_length' => 255));
- $field = field_create_field($field);
+ $field = entity_create('field_entity', array(
+ 'field_name' => 'test_text',
+ 'type' => 'text',
+ 'settings' => array('max_length' => 255),
+ ));
+ $field->save();
// Attempt to update the field in a way that would break the storage.
$prior_field = $field;
$field['settings']['max_length'] = -1;
try {
- field_update_field($field);
+ $field->save();
$this->fail(t('Update succeeded.'));
}
catch (Exception $e) {
@@ -356,10 +372,14 @@ function testFieldUpdateIndexesWithData() {
// Create a decimal field.
$field_name = 'testfield';
- $field = array('field_name' => $field_name, 'type' => 'text');
- $field = field_create_field($field);
- $instance = array('field_name' => $field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle');
- $instance = field_create_instance($instance);
+ $field = entity_create('field_entity', array('field_name' => $field_name, 'type' => 'text'));
+ $field->save();
+ $instance = entity_create('field_instance', array(
+ 'field_name' => $field_name,
+ 'entity_type' => 'test_entity',
+ 'bundle' => 'test_bundle',
+ ));
+ $instance->save();
$tables = array(_field_sql_storage_tablename($field), _field_sql_storage_revision_tablename($field));
// Verify the indexes we will create do not exist yet.
@@ -373,16 +393,16 @@ function testFieldUpdateIndexesWithData() {
$entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'] = 'field data';
$entity->save();
- // Add an index
- $field = array('field_name' => $field_name, 'indexes' => array('value' => array(array('value', 255))));
- field_update_field($field);
+ // Add an index.
+ $field['indexes'] = array('value' => array(array('value', 255)));
+ $field->save();
foreach ($tables as $table) {
$this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value created in $table"));
}
// Add a different index, removing the existing custom one.
- $field = array('field_name' => $field_name, 'indexes' => array('value_format' => array(array('value', 127), array('format', 127))));
- field_update_field($field);
+ $field['indexes'] = array('value_format' => array(array('value', 127), array('format', 127)));
+ $field->save();
foreach ($tables as $table) {
$this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in $table"));
$this->assertFalse(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value removed in $table"));
@@ -430,18 +450,21 @@ function testFieldSqlStorageForeignKeys() {
// field_test_field_schema()).
$field_name = 'testfield';
$foreign_key_name = 'shape';
- $field = array('field_name' => $field_name, 'type' => 'shape', 'settings' => array('foreign_key_name' => $foreign_key_name));
- field_create_field($field);
+ $field = entity_create('field_entity', array(
+ 'field_name' => $field_name,
+ 'type' => 'shape',
+ 'settings' => array('foreign_key_name' => $foreign_key_name),
+ ));
+ $field->save();
// Retrieve the field definition and check that the foreign key is in place.
- $field = field_info_field($field_name);
$this->assertEqual($field['foreign keys'][$foreign_key_name]['table'], $foreign_key_name, 'Foreign key table name preserved through CRUD');
$this->assertEqual($field['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', 'Foreign key column name preserved through CRUD');
// Update the field settings, it should update the foreign key definition too.
$foreign_key_name = 'color';
$field['settings']['foreign_key_name'] = $foreign_key_name;
- field_update_field($field);
+ $field->save();
// Retrieve the field definition and check that the foreign key is in place.
$field = field_info_field($field_name);
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
index 1ed9894..a22593b 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
@@ -529,7 +529,7 @@ public function submitForm(array &$form, array &$form_state) {
if (in_array($key, $form['#fields'])) {
$instance = field_read_instance($this->entity_type, $key, $this->bundle);
$instance['widget']['weight'] = $values['weight'];
- field_update_instance($instance);
+ $instance->save();
}
elseif (in_array($key, $form['#extra'])) {
$bundle_settings['extra_fields']['form'][$key]['weight'] = $values['weight'];
@@ -541,7 +541,6 @@ public function submitForm(array &$form, array &$form_state) {
$destinations = array();
// Create new field.
- $field = array();
if (!empty($form_values['_add_new_field']['field_name'])) {
$values = $form_values['_add_new_field'];
@@ -583,7 +582,7 @@ public function submitForm(array &$form, array &$form_state) {
$form_state['fields_added']['_add_new_field'] = $field['field_name'];
}
catch (Exception $e) {
- drupal_set_message(t('There was a problem creating field %label: !message', array('%label' => $instance['label'], '!message' => $e->getMessage())), 'error');
+ drupal_set_message(t('There was a problem creating field %label: !message', array('%label' => $values['label'], '!message' => $e->getMessage())), 'error');
}
}
@@ -622,7 +621,7 @@ public function submitForm(array &$form, array &$form_state) {
$form_state['fields_added']['_add_existing_field'] = $instance['field_name'];
}
catch (Exception $e) {
- drupal_set_message(t('There was a problem creating field instance %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())), 'error');
+ drupal_set_message(t('There was a problem creating field instance %label: @message.', array('%label' => $values['label'], '@message' => $e->getMessage())), 'error');
}
}
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php
index 1c688fb..25d81eb 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php
@@ -50,11 +50,11 @@ function setUp() {
*/
function testDefaultWidgetPropertiesAlter() {
// Create the alter_test_text field and an instance on article nodes.
- field_create_field(array(
+ entity_create('field_entity', array(
'field_name' => 'alter_test_text',
'type' => 'text',
- ));
- $instance = array(
+ ))->save();
+ entity_create('field_instance', array(
'field_name' => 'alter_test_text',
'entity_type' => 'node',
'bundle' => 'article',
@@ -62,8 +62,7 @@ function testDefaultWidgetPropertiesAlter() {
'type' => 'text_textfield',
'size' => 60,
),
- );
- field_create_instance($instance);
+ ))->save();
// Test that field_test_field_widget_properties_alter() sets the size to
// 42 and that field_test_field_widget_form_alter() reports the correct
@@ -75,29 +74,27 @@ function testDefaultWidgetPropertiesAlter() {
$this->assertText('From hook_field_widget_form_alter(): Default form is true.', 'Default value form detected in hook_field_widget_form_alter().');
// Create the alter_test_options field.
- field_create_field(array(
+ entity_create('field_entity', array(
'field_name' => 'alter_test_options',
'type' => 'list_text'
- ));
+ ))->save();
// Create instances on users and page nodes.
- $instance = array(
+ entity_create('field_instance', array(
'field_name' => 'alter_test_options',
'entity_type' => 'user',
'bundle' => 'user',
'widget' => array(
'type' => 'options_select',
)
- );
- field_create_instance($instance);
- $instance = array(
+ ))->save();
+ entity_create('field_instance', array(
'field_name' => 'alter_test_options',
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_select',
)
- );
- field_create_instance($instance);
+ ))->save();
// Test that field_test_field_widget_properties_user_alter() replaces
// the widget and that field_test_field_widget_form_alter() reports the
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/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
index 3fcabf2..9f9499b 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
@@ -43,7 +43,7 @@ function setUp() {
'field_name' => 'field_' . $vocabulary->id(),
'type' => 'taxonomy_term_reference',
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => 'field_' . $vocabulary->id(),
@@ -51,7 +51,7 @@ function setUp() {
'label' => 'Tags',
'bundle' => 'article',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
@@ -244,17 +244,16 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string'
function testDefaultValue() {
// Create a test field and instance.
$field_name = 'test';
- $field = array(
+ entity_create('field_entity', array(
'field_name' => $field_name,
'type' => 'test_field'
- );
- field_create_field($field);
- $instance = array(
+ ))->save();
+ $instance = entity_create('field_instance', array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $this->type,
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/' . $instance->id();
@@ -289,7 +288,7 @@ function testDefaultValue() {
// Change the widget to TestFieldWidgetNoDefault.
$instance['widget']['type'] = 'test_field_widget_no_default';
- field_update_instance($instance);
+ $instance->save();
$this->drupalGet($admin_path);
$this->assertNoFieldById($element_id, '', t('No default value was possible for widget that disables default value.'));
@@ -353,7 +352,7 @@ function testHiddenFields() {
// Create a field and an instance programmatically.
$field_name = 'hidden_test_field';
- field_create_field(array('field_name' => $field_name, 'type' => $field_name));
+ entity_create('field_entity', array('field_name' => $field_name, 'type' => $field_name))->save();
$instance = array(
'field_name' => $field_name,
'bundle' => $this->type,
@@ -361,7 +360,7 @@ function testHiddenFields() {
'label' => t('Hidden field'),
'widget' => array('type' => 'test_field_widget'),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$this->assertTrue(field_read_instance('node', $field_name, $this->type), format_string('An instance of the field %field was created programmatically.', array('%field' => $field_name)));
// Check that the newly added instance appears on the 'Manage Fields'
diff --git a/core/modules/file/file.install b/core/modules/file/file.install
index 3ca855e..8927e26 100644
--- a/core/modules/file/file.install
+++ b/core/modules/file/file.install
@@ -273,7 +273,7 @@ function file_update_8002() {
else {
$field['settings']['default_image'] = array();
}
- field_update_field($field);
+ $field->save();
$instances = field_read_instances(array('field_name' => $field['field_name']));
foreach ($instances as $instance) {
@@ -283,7 +283,7 @@ function file_update_8002() {
else {
$instance['settings']['default_image'] = array();
}
- field_update_instance($instance);
+ $instance->save();
}
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
index 8cff731..ed29cba 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
@@ -65,14 +65,15 @@ function getLastFileId() {
* A list of widget settings that will be added to the widget defaults.
*/
function createFileField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
- $field = array(
+ $field_definition = array(
'field_name' => $name,
'type' => 'file',
'settings' => array(),
'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
);
- $field['settings'] = array_merge($field['settings'], $field_settings);
- $field = field_create_field($field);
+ $field_definition['settings'] = array_merge($field_definition['settings'], $field_settings);
+ $field = entity_create('field_entity', $field_definition);
+ $field->save();
$this->attachFileField($name, 'node', $type_name, $instance_settings, $widget_settings);
return $field;
@@ -109,7 +110,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra
);
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
$instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
@@ -120,7 +121,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
$instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
- field_update_instance($instance);
+ $instance->save();
}
/**
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
index faceb99..37633e1 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
@@ -50,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.
@@ -151,4 +151,5 @@ function testFileExtension() {
$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.'));
}
+
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
index 2ec9dfa..674553c 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
@@ -49,13 +49,13 @@ public function setUp() {
'type' => 'file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'file_test',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
file_put_contents('public://example.txt', $this->randomName());
$this->file = entity_create('file', array(
'uri' => 'public://example.txt',
diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install
index 1bc6915..9f9b44b 100644
--- a/core/modules/forum/forum.install
+++ b/core/modules/forum/forum.install
@@ -65,7 +65,7 @@ function forum_enable() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
// Create a default forum so forum posts can be created.
$term = entity_create('taxonomy_term', array(
@@ -88,7 +88,7 @@ function forum_enable() {
'type' => 'options_select',
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Assign display settings for the 'default' and 'teaser' view modes.
entity_get_display('node', 'forum', 'default')
@@ -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/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php
index b40bffa..e26641e 100644
--- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php
+++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php
@@ -83,13 +83,13 @@ function setUp() {
'type' => 'text',
'translatable' => FALSE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_text',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Create the test translatable field.
$field = array(
@@ -97,13 +97,13 @@ function setUp() {
'type' => 'text',
'translatable' => TRUE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_translatable_text',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Create the test entity reference field.
$field = array(
@@ -114,13 +114,13 @@ function setUp() {
'field_name' => 'field_test_entity_reference',
'type' => 'entity_reference',
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Set up the mock serializer.
$normalizers = array(
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php b/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php
index 4bbbbde..f2a96ab 100644
--- a/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php
+++ b/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php
@@ -94,7 +94,7 @@ protected function replaceImageStyle(ImageStyle $style) {
}
if ($instance['widget']['settings']['preview_image_style'] == $style->getOriginalID()) {
$instance['widget']['settings']['preview_image_style'] = $style->id();
- field_update_instance($instance);
+ $instance->save();
}
}
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
index c8570c1..c481ec3 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
@@ -51,9 +51,8 @@ function testDefaultImages() {
$widget_settings = array(
'preview_image_style' => 'medium',
);
- $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings);
+ $instance = $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
- $instance = field_info_instance('node', $field_name, 'article');
// Add another instance with another default image to the page content type.
$instance2 = array(
@@ -67,8 +66,7 @@ function testDefaultImages() {
),
'widget' => $instance['widget'],
);
- field_create_instance($instance2);
- $instance2 = field_info_instance('node', $field_name, 'page');
+ entity_create('field_instance', $instance2)->save();
entity_get_display('node', 'page', 'default')
->setComponent($field['field_name'])
->save();
@@ -141,7 +139,7 @@ function testDefaultImages() {
// Upload a new default for the field.
$field['settings']['default_image'] = array($default_images['field_new']->fid);
- field_update_field($field);
+ $field->save();
// Confirm that the new default is used on the article field settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field-settings");
@@ -176,7 +174,7 @@ function testDefaultImages() {
// Upload a new default for the article's field instance.
$instance['settings']['default_image'] = array($default_images['instance_new']->fid);
- field_update_instance($instance);
+ $instance->save();
// Confirm the new field instance default is used on the article field
// admin form.
@@ -215,7 +213,7 @@ function testDefaultImages() {
// Remove the instance default from articles.
$instance['settings']['default_image'] = NULL;
- field_update_instance($instance);
+ $instance->save();
// Confirm the article field instance default has been removed.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
@@ -247,4 +245,5 @@ function testDefaultImages() {
)
);
}
+
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php
index 5a4e20e..c125792 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php
@@ -75,7 +75,7 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc
'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
);
$field['settings'] = array_merge($field['settings'], $field_settings);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field['field_name'],
@@ -93,7 +93,8 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
$instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
- $field_instance = field_create_instance($instance);
+ $field_instance = entity_create('field_instance', $instance);
+ $field_instance->save();
entity_get_display('node', $type_name, 'default')
->setComponent($field['field_name'])
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
index 7f863cf..86d1cd8 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
@@ -48,7 +48,7 @@ public function setUp() {
'type' => 'image',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'image_test',
@@ -57,7 +57,7 @@ public function setUp() {
'type' => 'image_image',
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array(
'uri' => 'public://example.jpg',
diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
index f28bcc2..94fdfdc 100644
--- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
+++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
@@ -48,7 +48,7 @@ function testURLValidation() {
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'link',
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -63,7 +63,7 @@ function testURLValidation() {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field['field_name'], array(
'type' => 'link',
@@ -116,8 +116,8 @@ function testLinkTitle() {
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'link',
);
- field_create_field($this->field);
- $this->instance = array(
+ entity_create('field_entity', $this->field)->save();
+ $this->instance = entity_create('field_instance', array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@@ -132,8 +132,8 @@ function testLinkTitle() {
'placeholder_title' => 'Enter a title for this link',
),
),
- );
- field_create_instance($this->instance);
+ ));
+ $this->instance->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field['field_name'], array(
'type' => 'link',
@@ -147,7 +147,7 @@ function testLinkTitle() {
foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) {
// Update the title field setting.
$this->instance['settings']['title'] = $title_setting;
- field_update_instance($this->instance);
+ $this->instance->save();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
@@ -229,7 +229,7 @@ function testLinkFormatter() {
'type' => 'link',
'cardinality' => 2,
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -246,7 +246,7 @@ function testLinkFormatter() {
'type' => 'link',
'label' => 'hidden',
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field['field_name'], $display_options)
->save();
@@ -368,7 +368,7 @@ function testLinkSeparateFormatter() {
'type' => 'link',
'cardinality' => 2,
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -384,7 +384,7 @@ function testLinkSeparateFormatter() {
'type' => 'link_separate',
'label' => 'hidden',
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field['field_name'], $display_options)
->save();
diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php
index e59e403..3968e5f 100644
--- a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php
+++ b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php
@@ -35,20 +35,20 @@ public function setUp() {
parent::setUp();
// Create an link field and instance for validation.
- $this->field = array(
+ $this->field = entity_create('field_entity', array(
'field_name' => 'field_test',
'type' => 'link',
- );
- field_create_field($this->field);
- $this->instance = array(
+ ));
+ $this->field->save();
+ $this->instance = entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
'widget' => array(
'type' => 'link_default',
),
- );
- field_create_instance($this->instance);
+ ));
+ $this->instance->save();
}
/**
diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php
index 7ee1e85..d6c3498 100644
--- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php
@@ -43,7 +43,7 @@ function testMultiStepNodeFormBasicOptions() {
'type' => 'text',
'cardinality' => -1,
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
// Attach an instance of the field to the page content type.
$this->instance = array(
@@ -63,7 +63,7 @@ function testMultiStepNodeFormBasicOptions() {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit = array(
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php
index 452ed93..e493c8c 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php
@@ -38,13 +38,15 @@ public function setUp() {
// Add a custom field to the page content type.
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
- $this->field = field_create_field(array('field_name' => $this->field_name, 'type' => 'text'));
+ $this->field = entity_create('field_entity', array('field_name' => $this->field_name, 'type' => 'text'));
+ $this->field->save();
$instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
);
- $this->instance = field_create_instance($instance);
+ $this->instance = entity_create('field_instance', $instance);
+ $this->instance->save();
entity_get_display('node', 'page', 'default')
->setComponent($this->field_name)
->save();
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php
index 930bdf3..3d1b617 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php
@@ -61,7 +61,7 @@ function setUp() {
// Make node body translatable.
$field = field_info_field('body');
$field['translatable'] = TRUE;
- field_update_field($field);
+ $field->save();
}
/**
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/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
index 28b04cd..5badf96 100644
--- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
@@ -71,7 +71,7 @@ function setUp() {
)
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
@@ -89,7 +89,7 @@ function setUp() {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
}
/**
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index f2d0ae9..d35caf0 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -569,7 +569,8 @@ function node_add_body_field($type, $label = 'Body') {
'type' => 'text_with_summary',
'entity_types' => array('node'),
);
- $field = field_create_field($field);
+ $field = entity_create('field_entity', $field);
+ $field->save();
}
if (empty($instance)) {
$instance = array(
@@ -580,7 +581,8 @@ function node_add_body_field($type, $label = 'Body') {
'widget' => array('type' => 'text_textarea_with_summary'),
'settings' => array('display_summary' => TRUE),
);
- $instance = field_create_instance($instance);
+ $instance = entity_create('field_instance', $instance);
+ $instance->save();
// Assign display settings for the 'default' and 'teaser' view modes.
entity_get_display('node', $type->type, 'default')
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..b3db641 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
@@ -58,7 +58,8 @@ function node_access_test_language_enable() {
'allowed_values' => array(0 => 'Not private', 1 => 'Private'),
),
);
- $field_private = field_create_field($field_private);
+ $field_private = entity_create('field_entity', $field_private);
+ $field_private->save();
$instance = array(
'field_name' => $field_private['field_name'],
@@ -68,12 +69,13 @@ function node_access_test_language_enable() {
'type' => 'options_buttons',
),
);
- $instance = field_create_instance($instance);
+ $instance = entity_create('field_instance', $instance);
+ $instance->save();
}
/**
* 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/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
index aa6c06e..b3d99b9 100644
--- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
+++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
@@ -52,7 +52,7 @@ function testNumberDecimalField() {
'precision' => 8, 'scale' => 4, 'decimal_separator' => '.',
)
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -64,7 +64,7 @@ function testNumberDecimalField() {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'default')
->setComponent($this->field['field_name'])
->save();
diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php
index a0fc778..fde2223 100644
--- a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php
+++ b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php
@@ -40,7 +40,7 @@ public function setUp() {
'field_name' => 'field_' . $type,
'type' => 'number_' . $type,
);
- field_create_field($this->field[$type]);
+ entity_create('field_entity', $this->field[$type])->save();
$this->instance[$type] = array(
'entity_type' => 'entity_test',
'field_name' => 'field_' . $type,
@@ -49,7 +49,7 @@ public function setUp() {
'type' => 'number',
),
);
- field_create_instance($this->instance[$type]);
+ entity_create('field_instance', $this->instance[$type])->save();
}
}
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php
index 4065b7d..33bd543 100644
--- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php
+++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php
@@ -33,7 +33,8 @@ function setUp() {
'allowed_values_function' => 'options_test_dynamic_values_callback',
),
);
- $this->field = field_create_field($this->field);
+ $this->field = entity_create('field_entity', $this->field);
+ $this->field->save();
$this->instance = array(
'field_name' => $this->field_name,
@@ -44,7 +45,8 @@ function setUp() {
'type' => 'options_select',
),
);
- $this->instance = field_create_instance($this->instance);
+ $this->instance = entity_create('field_instance', $this->instance);
+ $this->instance->save();
$this->test = array(
'id' => mt_rand(1, 10),
// Make sure this does not equal the ID so that
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
index 11ab663..4f84577 100644
--- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
+++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
@@ -44,7 +44,8 @@ function setUp() {
'allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'),
),
);
- $this->field = field_create_field($this->field_definition);
+ $this->field = entity_create('field_entity', $this->field_definition);
+ $this->field->save();
$this->instance = array(
'field_name' => $this->field_name,
@@ -54,7 +55,8 @@ function setUp() {
'type' => 'options_buttons',
),
);
- $this->instance = field_create_instance($this->instance);
+ $this->instance = entity_create('field_instance', $this->instance);
+ $this->instance->save();
}
/**
@@ -77,7 +79,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 +91,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 +100,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,9 +109,8 @@ 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']);
- field_create_field($this->field_definition);
+ $this->field->delete();
+ entity_create('field_entity', $this->field_definition)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test',
@@ -118,7 +119,7 @@ function testUpdateAllowedValues() {
'type' => 'options_buttons',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
$entity = entity_create('entity_test', array());
$form = entity_get_form($entity);
$this->assertTrue(!empty($form[$this->field_name][$langcode][1]), 'Option 1 exists');
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
index c69c414..ae57ea1 100644
--- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
+++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
@@ -258,13 +258,13 @@ protected function createOptionsField($type) {
'field_name' => $this->field_name,
'type' => $type,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => $this->type,
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$this->admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $this->field_name . '/field-settings';
}
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
index 4dfd302..b92add6 100644
--- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
+++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
@@ -33,7 +33,7 @@ function setUp() {
parent::setUp();
// Field with cardinality 1.
- $this->card_1 = array(
+ $this->card_1 = entity_create('field_entity', array(
'field_name' => 'card_1',
'type' => 'list_integer',
'cardinality' => 1,
@@ -41,11 +41,11 @@ function setUp() {
// Make sure that 0 works as an option.
'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some & unescaped markup'),
),
- );
- $this->card_1 = field_create_field($this->card_1);
+ ));
+ $this->card_1->save();
// Field with cardinality 2.
- $this->card_2 = array(
+ $this->card_2 = entity_create('field_entity', array(
'field_name' => 'card_2',
'type' => 'list_integer',
'cardinality' => 2,
@@ -53,19 +53,19 @@ function setUp() {
// Make sure that 0 works as an option.
'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some & unescaped markup'),
),
- );
- $this->card_2 = field_create_field($this->card_2);
+ ));
+ $this->card_2->save();
// Boolean field.
- $this->bool = array(
+ $this->bool = entity_create('field_entity', array(
'field_name' => 'bool',
'type' => 'list_boolean',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(0 => 'Zero', 1 => 'Some & unescaped markup'),
),
- );
- $this->bool = field_create_field($this->bool);
+ ));
+ $this->bool->save();
// Create a web user.
$this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
@@ -77,15 +77,15 @@ function setUp() {
*/
function testRadioButtons() {
// Create an instance of the 'single value' field.
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => $this->card_1['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'widget' => array(
'type' => 'options_buttons',
),
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Create an entity.
@@ -119,9 +119,9 @@ function testRadioButtons() {
// Check that required radios with one option is auto-selected.
$this->card_1['settings']['allowed_values'] = array(99 => 'Only allowed value');
- field_update_field($this->card_1);
+ $this->card_1->save();
$instance['required'] = TRUE;
- field_update_instance($instance);
+ $instance->save();
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
$this->assertFieldChecked("edit-card-1-$langcode-99");
}
@@ -131,15 +131,15 @@ function testRadioButtons() {
*/
function testCheckBoxes() {
// Create an instance of the 'multiple values' field.
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => $this->card_2['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'widget' => array(
'type' => 'options_buttons',
),
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Create an entity.
@@ -206,9 +206,9 @@ function testCheckBoxes() {
// Required checkbox with one option is auto-selected.
$this->card_2['settings']['allowed_values'] = array(99 => 'Only allowed value');
- field_update_field($this->card_2);
+ $this->card_2->save();
$instance['required'] = TRUE;
- field_update_instance($instance);
+ $instance->save();
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
$this->assertFieldChecked("edit-card-2-$langcode-99");
}
@@ -218,7 +218,7 @@ function testCheckBoxes() {
*/
function testSelectListSingle() {
// Create an instance of the 'single value' field.
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => $this->card_1['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@@ -226,8 +226,8 @@ function testSelectListSingle() {
'widget' => array(
'type' => 'options_select',
),
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Create an entity.
@@ -268,7 +268,7 @@ function testSelectListSingle() {
// Make the field non required.
$instance['required'] = FALSE;
- field_update_instance($instance);
+ $instance->save();
// Display form.
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
@@ -283,7 +283,7 @@ function testSelectListSingle() {
$this->card_1['settings']['allowed_values'] = array();
$this->card_1['settings']['allowed_values_function'] = 'options_test_allowed_values_callback';
- field_update_field($this->card_1);
+ $this->card_1->save();
// Display form: with no field data, nothing is selected
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
@@ -315,15 +315,15 @@ function testSelectListSingle() {
*/
function testSelectListMultiple() {
// Create an instance of the 'multiple values' field.
- $instance = array(
+ $instance = entity_create('field_instance', array(
'field_name' => $this->card_2['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'widget' => array(
'type' => 'options_select',
),
- );
- $instance = field_create_instance($instance);
+ ));
+ $instance->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Create an entity.
@@ -386,7 +386,7 @@ function testSelectListMultiple() {
// A required select list does not have an empty key.
$instance['required'] = TRUE;
- field_update_instance($instance);
+ $instance->save();
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', array(':id' => 'edit-card-2-' . $langcode)), 'A required select list does not have an empty key.');
@@ -398,9 +398,9 @@ function testSelectListMultiple() {
// Use a callback function defining optgroups.
$this->card_2['settings']['allowed_values'] = array();
$this->card_2['settings']['allowed_values_function'] = 'options_test_allowed_values_callback';
- field_update_field($this->card_2);
+ $this->card_2->save();
$instance['required'] = FALSE;
- field_update_instance($instance);
+ $instance->save();
// Display form: with no field data, nothing is selected.
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
@@ -432,15 +432,14 @@ function testSelectListMultiple() {
*/
function testOnOffCheckbox() {
// Create an instance of the 'boolean' field.
- $instance = array(
+ entity_create('field_instance', array(
'field_name' => $this->bool['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'widget' => array(
'type' => 'options_onoff',
),
- );
- $instance = field_create_instance($instance);
+ ))->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Create an entity.
@@ -482,8 +481,8 @@ function testOnOffCheckbox() {
// Create a test field instance.
$fieldUpdate = $this->bool;
$fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue');
- field_update_field($fieldUpdate);
- $instance = array(
+ $fieldUpdate->save();
+ entity_create('field_instance', array(
'field_name' => $this->bool['field_name'],
'entity_type' => 'node',
'bundle' => 'page',
@@ -491,8 +490,7 @@ function testOnOffCheckbox() {
'type' => 'options_onoff',
'module' => 'options',
),
- );
- field_create_instance($instance);
+ ))->save();
// Go to the edit page and check if the default settings works as expected
$fieldEditUrl = 'admin/structure/types/manage/page/fields/node.page.bool';
diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
index 6f99dae..21f28df 100644
--- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
+++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
@@ -110,13 +110,13 @@ function testAttributesInMarkupFile() {
'field_name' => $field_name,
'type' => 'file',
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $bundle_name,
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
entity_get_display('node', $bundle_name, 'teaser')
->setComponent($field_name, array(
'type' => 'file_default',
diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php
index e9526d8..b392277 100644
--- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php
+++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php
@@ -50,7 +50,7 @@ function setUp() {
// The parent class has already created the article and page content types.
$field = field_info_field('body');
$field['translatable'] = TRUE;
- field_update_field($field);
+ $field->save();
// Create a few page nodes with multilingual body values.
$default_format = filter_default_format();
diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php
index dfbb7ba..48d0293 100644
--- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php
+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php
@@ -34,22 +34,20 @@ protected function setUp() {
parent::setUp();
// Create the test field.
- $field = array(
+ entity_create('field_entity', array(
'settings' => array(
'target_type' => 'entity_test_mulrev',
),
'field_name' => 'field_test_entity_reference',
'type' => 'entity_reference',
- );
- field_create_field($field);
+ ))->save();
// Create the test field instance.
- $instance = array(
+ entity_create('field_instance', array(
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test_mulrev',
- );
- field_create_instance($instance);
+ ))->save();
}
/**
diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php
index 1d9bff6..74fa8d9 100644
--- a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php
+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php
@@ -26,13 +26,13 @@ protected function setUp() {
$this->installConfig(array('field'));
// Auto-create a field for testing.
- field_create_field(array(
+ entity_create('field_entity', array(
'field_name' => 'field_test_text',
'type' => 'text',
'cardinality' => 1,
'translatable' => FALSE,
- ));
- $instance = array(
+ ))->save();
+ entity_create('field_instance', array(
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_text',
'bundle' => 'entity_test_mulrev',
@@ -41,7 +41,7 @@ protected function setUp() {
'type' => 'text_textfield',
'weight' => 0,
),
- );
- field_create_instance($instance);
+ ))->save();
}
+
}
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
index 2379193..50049ad 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
@@ -235,13 +235,13 @@ function testEnableModulesFixedList() {
'field_name' => 'test_field',
'type' => 'test_field'
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
index c9e7b6d..3d8d92c 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
@@ -39,13 +39,13 @@ function setUp() {
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'page',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Login a user who can create 'page' nodes.
$this->web_user = $this->drupalCreateUser(array('create page content'));
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
index fabbcfe..90c03e9 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
@@ -598,7 +598,7 @@ protected function assertComputedProperties($entity_type) {
// Make the test text field processed.
$instance = field_info_instance($entity_type, 'field_test_text', $entity_type);
$instance['settings']['text_processing'] = 1;
- field_update_instance($instance);
+ $instance->save();
$entity = $this->createTestEntity($entity_type);
$entity->field_test_text->value = "The text text to filter.";
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php
index 54c6934..76cf7bd 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php
@@ -65,13 +65,13 @@ public function setUp() {
'type' => 'number_integer',
'cardinality' => 2,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
$entity = $this->entityStorageController->create(array(
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php
index f36fca7..ee5a226 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php
@@ -85,14 +85,14 @@ public function setUp() {
'type' => 'taxonomy_term_reference',
);
$field['settings']['allowed_values']['vocabulary'] = $vocabulary->id();
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
// Third, create the instance.
$instance = array(
'entity_type' => 'entity_test',
'field_name' => $this->fieldName,
'bundle' => 'entity_test',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Create two terms and also two accounts.
for ($i = 0; $i <= 1; $i++) {
$term = entity_create('taxonomy_term', array(
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
index 958bfb5..25e3339 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
@@ -57,12 +57,13 @@ function setUp() {
$figures = drupal_strtolower($this->randomName());
$greetings = drupal_strtolower($this->randomName());
foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) {
- $field = array(
+ $field = entity_create('field_entity', array(
'field_name' => $field_name,
'type' => $field_type,
'cardinality' => 2,
- );
- $fields[] = field_create_field($field);
+ ));
+ $field->save();
+ $fields[] = $field;
}
$bundles = array();
for ($i = 0; $i < 2; $i++) {
@@ -78,7 +79,7 @@ function setUp() {
'entity_type' => 'test_entity',
'bundle' => $bundle,
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
$bundles[] = $bundle;
}
@@ -393,7 +394,7 @@ protected function testCount() {
'entity_type' => 'test_entity_bundle',
'bundle' => $bundle,
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$entity = entity_create('test_entity_bundle', array(
'ftid' => 1,
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
index 7672fbe..5d93f66 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
@@ -108,7 +108,7 @@ function testEntityFormLanguage() {
// Make body translatable.
$field = field_info_field('body');
$field['translatable'] = TRUE;
- field_update_field($field);
+ $field->save();
$field = field_info_field('body');
$this->assertTrue($field['translatable'], 'Field body is translatable.');
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
index f5c1c52..6730fac 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
@@ -56,7 +56,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);
// Create instance in all entity variations.
@@ -66,7 +66,7 @@ function setUp() {
'entity_type' => $entity_type,
'bundle' => $entity_type,
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$this->instance[$entity_type] = field_read_instance($entity_type, $this->field_name, $entity_type);
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php
index 1604063..9726cfe 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php
@@ -39,7 +39,7 @@ function setUp() {
'cardinality' => -1,
'translatable' => FALSE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'node',
@@ -51,7 +51,7 @@ function setUp() {
'weight' => 0,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php
index 3c0c0c5..571bb55 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php
@@ -76,13 +76,13 @@ function testPreserveFormActionAfterAJAX() {
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'page',
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Log in a user who can create 'page' nodes.
$this->web_user = $this->drupalCreateUser(array('create page content'));
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.install b/core/modules/system/tests/modules/entity_test/entity_test.install
index 3465e8c..6c3041a 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.install
+++ b/core/modules/system/tests/modules/entity_test/entity_test.install
@@ -16,7 +16,7 @@ function entity_test_install() {
'cardinality' => 1,
'translatable' => FALSE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$entity_types = array(
'entity_test',
@@ -35,7 +35,7 @@ function entity_test_install() {
'weight' => 0,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
}
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php
index ca775e9..c6bd4bc 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php
@@ -47,7 +47,7 @@ function setUp() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
@@ -57,7 +57,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
'type' => 'taxonomy_term_reference_link',
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php
index abb5893..3357841 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php
@@ -55,7 +55,7 @@ public function setUp() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_taxonomy',
@@ -64,7 +64,7 @@ public function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$this->term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $vocabulary->id(),
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php
index 4f71f53..3c75edc 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php
@@ -58,7 +58,7 @@ function setUp() {
),
)
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
@@ -67,7 +67,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
index 363d326..da625b0 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
@@ -41,7 +41,7 @@ function setUp() {
// Setup a field and instance.
$this->field_name = drupal_strtolower($this->randomName());
- $this->field = array(
+ $this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'settings' => array(
@@ -52,8 +52,8 @@ function setUp() {
),
),
)
- );
- field_create_field($this->field);
+ ));
+ $this->field->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
@@ -62,7 +62,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
@@ -155,7 +155,7 @@ function testTaxonomyTermFieldChangeMachineName() {
'parent' => '0',
),
);
- field_update_field($this->field);
+ $this->field->save();
// Change the machine name.
$new_name = drupal_strtolower($this->randomName());
$this->vocabulary->vid = $new_name;
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php
index 237f4b4..82ce984 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php
@@ -44,7 +44,7 @@ function setUp() {
),
),
);
- field_create_field($this->field_1);
+ entity_create('field_entity', $this->field_1)->save();
$this->instance_1 = array(
'field_name' => $this->field_name_1,
'bundle' => 'article',
@@ -53,7 +53,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance_1);
+ entity_create('field_instance', $this->instance_1)->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->field_name_1, array(
'type' => 'taxonomy_term_reference_link',
@@ -74,7 +74,7 @@ function setUp() {
),
),
);
- field_create_field($this->field_2);
+ entity_create('field_entity', $this->field_2)->save();
$this->instance_2 = array(
'field_name' => $this->field_name_2,
'bundle' => 'article',
@@ -83,7 +83,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance_2);
+ entity_create('field_instance', $this->instance_2)->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->field_name_2, array(
'type' => 'taxonomy_term_reference_link',
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
index 705ff60..51090ee 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
@@ -39,17 +39,17 @@ function setUp() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
- $this->instance = array(
+ $this->instance = entity_create('field_instance', array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
'bundle' => 'article',
'entity_type' => 'node',
'widget' => array(
'type' => 'options_select',
),
- );
- field_create_instance($this->instance);
+ ));
+ $this->instance->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->instance['field_name'], array(
'type' => 'taxonomy_term_reference_link',
@@ -148,7 +148,7 @@ function testNodeTermCreationAndDeletion() {
'placeholder' => 'Start typing here.',
),
);
- field_update_instance($instance);
+ $instance->save();
$terms = array(
'term1' => $this->randomName(),
'term2' => $this->randomName(),
@@ -507,7 +507,7 @@ function testReSavingTags() {
// Enable tags in the vocabulary.
$instance = $this->instance;
$instance['widget'] = array('type' => 'taxonomy_autocomplete');
- field_update_instance($instance);
+ $instance->save();
// Create a term and a node using it.
$term = $this->createTerm($this->vocabulary);
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php
index 0a45dd2..a984871 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php
@@ -40,7 +40,7 @@ function setUp() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
@@ -50,7 +50,7 @@ function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
'type' => 'taxonomy_term_reference_link',
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
index 6de1b17..2839dfc 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
@@ -94,7 +94,7 @@ protected function mockStandardInstall() {
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => 'field_' . $this->vocabulary->id(),
'entity_type' => 'node',
@@ -105,7 +105,7 @@ protected function mockStandardInstall() {
'weight' => -4,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
entity_get_display('node', 'article', 'default')
->setComponent($instance['field_name'], array(
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php
index e427b4e..ddbfd40 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php
@@ -145,13 +145,13 @@ function testTaxonomyVocabularyChangeMachineName() {
'field_name' => 'field_test',
'type' => 'test_field',
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => 'field_test',
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Change the machine name.
$old_name = $this->vocabulary->id();
@@ -176,14 +176,14 @@ function testUninstallReinstall() {
// removed when the module is uninstalled.
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field_definition = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4);
- field_create_field($this->field_definition);
+ entity_create('field_entity', $this->field_definition)->save();
$this->instance_definition = array(
'field_name' => $this->field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
'label' => $this->randomName() . '_label',
);
- field_create_instance($this->instance_definition);
+ entity_create('field_instance', $this->instance_definition)->save();
module_disable(array('taxonomy'));
require_once DRUPAL_ROOT . '/core/includes/install.inc';
@@ -196,7 +196,7 @@ function testUninstallReinstall() {
// an instance of this field on the same bundle name should be successful.
$this->vocabulary->enforceIsNew();
taxonomy_vocabulary_save($this->vocabulary);
- field_create_field($this->field_definition);
- field_create_instance($this->instance_definition);
+ entity_create('field_entity', $this->field_definition)->save();
+ entity_create('field_instance', $this->instance_definition)->save();
}
}
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();
}
}
}
diff --git a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
index 1bec98f..d3610e3 100644
--- a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
+++ b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
@@ -57,7 +57,7 @@ function testTelephoneField() {
'field_name' => 'field_telephone',
'type' => 'telephone',
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => 'field_telephone',
@@ -71,7 +71,7 @@ function testTelephoneField() {
),
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
entity_get_display('node', 'article', 'default')
->setComponent('field_telephone', array(
diff --git a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php
index 35012b3..47fa600 100644
--- a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php
+++ b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php
@@ -39,7 +39,7 @@ public function setUp() {
'field_name' => 'field_test',
'type' => 'telephone',
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
@@ -48,7 +48,7 @@ public function setUp() {
'type' => 'telephone_default',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
}
/**
diff --git a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
index 7126384..1e8711a 100644
--- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
+++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
@@ -67,14 +67,14 @@ function setUp() {
$this->formatter_type = 'text_plain';
$this->formatter_settings = array();
- $this->field = array(
+ $this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => $this->field_type,
'settings' => $this->field_settings,
- );
- $this->field = field_create_field($this->field);
+ ));
+ $this->field->save();
- $this->instance = array(
+ $this->instance = entity_create('field_instance', array(
'entity_type' => $this->entity_type,
'bundle' => $this->bundle,
'field_name' => $this->field_name,
@@ -84,8 +84,8 @@ function setUp() {
'type' => $this->widget_type,
'settings' => $this->widget_settings,
),
- );
- $this->instance = field_create_instance($this->instance);
+ ));
+ $this->instance->save();
$this->view_mode = 'default';
$this->display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode)
diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
index f8c585b..17487a0 100644
--- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
+++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
@@ -57,7 +57,7 @@ function testTextFieldValidation() {
'max_length' => $max_length,
)
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
@@ -66,7 +66,7 @@ function testTextFieldValidation() {
'type' => 'text_textfield',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'default')
->setComponent($this->field['field_name'])
->save();
@@ -102,7 +102,7 @@ function _testTextfieldWidgets($field_type, $widget_type) {
$entity_type = 'test_entity';
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
@@ -118,7 +118,7 @@ function _testTextfieldWidgets($field_type, $widget_type) {
),
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field_name)
->save();
@@ -165,7 +165,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
$entity_type = 'test_entity';
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
@@ -178,7 +178,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
'type' => $widget_type,
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('test_entity', 'test_bundle', 'full')
->setComponent($this->field_name)
->save();
diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php
index 61f93cf..ecdac68 100644
--- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php
+++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php
@@ -62,7 +62,7 @@ protected function setupTestFields() {
'cardinality' => $this->cardinality,
'translatable' => TRUE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => $this->entityType,
@@ -81,7 +81,7 @@ protected function setupTestFields() {
),
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php
index 13e1f59..06a0994 100644
--- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php
+++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php
@@ -163,7 +163,7 @@ protected function setupTestFields() {
'cardinality' => 1,
'translatable' => TRUE,
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'entity_type' => $this->entityType,
@@ -175,7 +175,7 @@ protected function setupTestFields() {
'weight' => 0,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
/**
diff --git a/core/modules/translation_entity/translation_entity.admin.inc b/core/modules/translation_entity/translation_entity.admin.inc
index 7aa91bf..b7a104f 100644
--- a/core/modules/translation_entity/translation_entity.admin.inc
+++ b/core/modules/translation_entity/translation_entity.admin.inc
@@ -439,7 +439,7 @@ function translation_entity_translatable_switch($translatable, $field_name) {
$field = field_info_field($field_name);
if ($field['translatable'] !== $translatable) {
$field['translatable'] = $translatable;
- field_update_field($field);
+ $field->save();
}
}
diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module
index e4dca3e..e0c8b81 100644
--- a/core/modules/translation_entity/translation_entity.module
+++ b/core/modules/translation_entity/translation_entity.module
@@ -1025,7 +1025,7 @@ function translation_entity_save_settings($settings) {
else {
unset($instance['settings']['translation_sync']);
}
- field_update_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
}
}
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php
index 38ca376..c8612c3 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php
@@ -194,21 +194,21 @@ function testRegistrationDefaultValues() {
*/
function testRegistrationWithUserFields() {
// Create a field, and an instance on 'user' entity type.
- $field = array(
+ $field = entity_create('field_entity', array(
'type' => 'test_field',
'field_name' => 'test_user_field',
'cardinality' => 1,
- );
- field_create_field($field);
- $instance = array(
+ ));
+ $field->save();
+ $instance = entity_create('field_instance', array(
'field_name' => 'test_user_field',
'entity_type' => 'user',
'label' => 'Some user field',
'bundle' => 'user',
'required' => TRUE,
'settings' => array('user_register_form' => FALSE),
- );
- field_create_instance($instance);
+ ));
+ $instance->save();
// Check that the field does not appear on the registration form.
$this->drupalGet('user/register');
@@ -216,7 +216,7 @@ function testRegistrationWithUserFields() {
// Have the field appear on the registration form.
$instance['settings']['user_register_form'] = TRUE;
- field_update_instance($instance);
+ $instance->save();
$this->drupalGet('user/register');
$this->assertText($instance['label'], 'The field appears on user registration form');
@@ -244,7 +244,7 @@ function testRegistrationWithUserFields() {
// Check that the 'add more' button works.
$field['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
- field_update_field($field);
+ $field->save();
foreach (array('js', 'nojs') as $js) {
$this->drupalGet('user/register');
// Add two inputs.
diff --git a/core/modules/user/user.install b/core/modules/user/user.install
index dca417c..616f84d 100644
--- a/core/modules/user/user.install
+++ b/core/modules/user/user.install
@@ -316,7 +316,7 @@ function user_install_picture_field() {
'default_image' => FALSE,
),
);
- $field = field_create_field($field);
+ entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => 'user_picture',
@@ -345,7 +345,7 @@ function user_install_picture_field() {
'weight' => -1,
),
);
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
// Assign display settings for the 'default' and 'compact' view modes.
entity_get_display('user', 'user', 'default')
diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
index 126e62d..78b778b 100644
--- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
@@ -72,7 +72,7 @@ protected function setUp() {
),
)
);
- field_create_field($this->field);
+ entity_create('field_entity', $this->field)->save();
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
@@ -81,7 +81,7 @@ protected function setUp() {
'type' => 'options_select',
),
);
- field_create_instance($this->instance);
+ entity_create('field_instance', $this->instance)->save();
entity_get_display('node', 'page', 'full')
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php
index 7c150dc..10928be 100644
--- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php
@@ -66,7 +66,7 @@ function setUp() {
),
),
);
- field_create_field($this->tag_field);
+ entity_create('field_entity', $this->tag_field)->save();
// Create an instance of the tag field on one of the content types, and
// configure it to display an autocomplete widget.
@@ -78,7 +78,7 @@ function setUp() {
'type' => 'taxonomy_autocomplete',
),
);
- field_create_instance($this->tag_instance);
+ entity_create('field_instance', $this->tag_instance)->save();
entity_get_display('node', $this->node_type_with_tags->type, 'default')
->setComponent('field_views_testing_tags', array(
@@ -184,7 +184,7 @@ function testTaggedWithByNodeType() {
// "tagged with" form element should not appear for it too.
$instance = $this->tag_instance;
$instance['bundle'] = $this->node_type_without_tags->type;
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
$view['show[type]'] = $this->node_type_with_tags->type;
$this->drupalPost('admin/structure/views/add', $view, t('Update "of type" choice'));
$this->assertFieldByXpath($tags_xpath);
diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh
index c171271..a64e22a 100644
--- a/core/scripts/generate-d7-content.sh
+++ b/core/scripts/generate-d7-content.sh
@@ -93,7 +93,7 @@
),
),
);
- field_create_field($field);
+ entity_create('field_entity', $field)->save();
$node_types = $i > 11 ? array('page') : array_keys(node_type_get_types());
foreach ($node_types as $bundle) {
$instance = array(
@@ -132,7 +132,7 @@
'settings' => array(),
);
}
- field_create_instance($instance);
+ entity_create('field_instance', $instance)->save();
}
$parents = array();
// Vocabularies without hierarchy get one term, single parent vocabularies get