diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 36fb318..d39f5fc 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -313,7 +313,7 @@ public function validate(array $form, array &$form_state) { // instantiate NG items objects manually. $definitions = \Drupal::entityManager()->getFieldDefinitions($entity->entityType(), $entity->bundle()); foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $field_name => $instance) { - $langcode = field_is_translatable($entity->entityType(), $instance->getField()) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED; + $langcode = field_is_translatable($entity->entityType(), $instance->getFieldConfig()) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED; // Create the field object. $items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array(); diff --git a/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php index 386d47d..96b4eed 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php @@ -24,16 +24,18 @@ * It is up to the class implementing this interface to manage where the * information comes from. For example, field.module provides an implementation * based on two levels of configuration. It allows the site administrator to add - * custom fields to any entity type and bundle via the "field_entity" and - * "field_instance" configuration entities. The former for storing configuration - * that is independent of which entity type and bundle the field is added to, - * and the latter for storing configuration that is specific to the entity type - * and bundle. The class that implements "field_instance" configuration entities - * also implements this interface, returning information from either itself, or - * from the corresponding "field_entity" configuration, as appropriate. + * custom fields to any entity type and bundle via the "field_config" and + * "field_instance_config" configuration entities. The former for storing + * configuration that is independent of which entity type and bundle the field + * is added to, and the latter for storing configuration that is specific to the + * entity type and bundle. The class that implements "field_instance_config" + * configuration entities also implements this interface, returning information + * from either itself, or from the corresponding "field_config" configuration, + * as appropriate. * * However, entity base fields, such as $node->title, are not managed by - * field.module and its "field_entity"/"field_instance" configuration entities. + * field.module and its "field_config"/"field_instance_config" configuration + * entities. * Therefore, their definitions are provided by different objects that implement * this interface. * @todo That is still in progress: https://drupal.org/node/1949932. Update this diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 2f7156a..a48352e 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -10,7 +10,7 @@ use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\Plugin\DataType\EntityReference; use Drupal\Core\Entity\Query\QueryException; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Adds tables and fields to the SQL entity query. @@ -120,7 +120,7 @@ function addField($field, $type, $langcode) { if ($key < $count) { $next = $specifiers[$key + 1]; // Is this a field column? - if (isset($field['columns'][$next]) || in_array($next, Field::getReservedColumns())) { + if (isset($field['columns'][$next]) || in_array($next, FieldConfig::getReservedColumns())) { // Use it. $column = $next; // Do not process it again. diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 4e55a85..9663c1c 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -179,7 +179,7 @@ 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 = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'block_body', 'type' => 'text_with_summary', 'entity_types' => array('custom_block'), @@ -187,7 +187,7 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { $field->save(); } if (empty($instance)) { - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'block_body', 'entity_type' => 'custom_block', 'bundle' => $block_type_id, 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 da5ac4f..cd57187 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 @@ -25,16 +25,16 @@ class CustomBlockFieldTest extends CustomBlockTestBase { /** * The created field. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $field; /** * The created instance. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * The block type. @@ -64,13 +64,13 @@ public function testBlockFields() { $this->blockType = $this->createCustomBlockType('link'); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', 'cardinality' => 2, )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->field_instance_config = entity_create('field_instance_config', array( 'field_name' => $this->field->id(), 'entity_type' => 'custom_block', 'bundle' => 'link', @@ -78,7 +78,7 @@ public function testBlockFields() { 'title' => DRUPAL_OPTIONAL, ), )); - $this->instance->save(); + $this->field_instance_config->save(); entity_get_form_display('custom_block', 'link', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'link_default', diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8ba44d1..4fcc704 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -323,7 +323,7 @@ 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 = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'comment_body', 'type' => 'text_long', 'entity_types' => array('comment'), @@ -334,7 +334,7 @@ function _comment_body_field_create($info) { 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 = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'comment_body', 'label' => 'Comment', 'entity_type' => 'comment', 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 166a64b..6820b7d 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php @@ -24,7 +24,7 @@ class ContactFieldsTest extends ViewTestBase { /** * Contains the field definition array attached to contact used for this test. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $field; @@ -39,13 +39,13 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => strtolower($this->randomName()), 'type' => 'text' )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field->id(), 'entity_type' => 'contact_message', 'bundle' => 'contact_message', diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 63e71fc..49b6cc6 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -7,28 +7,28 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; -use Drupal\field\Plugin\Core\Entity\Field; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldConfig; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Returns a form element to configure field synchronization. * - * @param \Drupal\field\Plugin\Core\Entity\Field $field + * @param \Drupal\field\Plugin\Core\Entity\FieldConfig $field_config * A field definition array. - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * A field instance definition object. * * @return array * A form element to configure field synchronization. */ -function content_translation_field_sync_widget(Field $field, FieldInstance $instance) { +function content_translation_field_sync_widget(FieldConfig $field_config, FieldInstanceConfig $field_instance_config) { $element = array(); - if (!empty($field['settings']['column_groups']) && count($field['settings']['column_groups']) > 1) { + if (!empty($field_config['settings']['column_groups']) && count($field_config['settings']['column_groups']) > 1) { $options = array(); $default = array(); - foreach ($field['settings']['column_groups'] as $group => $info) { + foreach ($field_config['settings']['column_groups'] as $group => $info) { $options[$group] = $info['label']; $default[$group] = !empty($info['translatable']) ? $group : FALSE; } @@ -39,7 +39,7 @@ function content_translation_field_sync_widget(Field $field, FieldInstance $inst '#type' => 'checkboxes', '#title' => t('Translatable elements'), '#options' => $options, - '#default_value' => !empty($instance['settings']['translation_sync']) ? $instance['settings']['translation_sync'] : $default, + '#default_value' => !empty($field_instance_config['settings']['translation_sync']) ? $field_instance_config['settings']['translation_sync'] : $default, '#attached' => array( 'library' => array( array('content_translation', 'drupal.content_translation.admin'), diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index e09e1cf..7b54ed8 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -839,9 +839,9 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, a } /** - * Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_edit_form'. + * Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_config_edit_form'. */ -function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state, $form_id) { +function content_translation_form_field_ui_field_instance_config_edit_form_alter(array &$form, array &$form_state, $form_id) { if ($form['#field']['translatable']) { module_load_include('inc', 'content_translation', 'content_translation.admin'); $element = content_translation_field_sync_widget($form['#field'], $form['#instance']); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php index 9fd4b0e..897bdbb 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php @@ -62,7 +62,7 @@ public function synchronizeFields(EntityInterface $entity, $sync_langcode, $orig // @todo Use Entity Field API to retrieve field definitions. $instances = field_info_instances($entity_type, $entity->bundle()); foreach ($instances as $field_name => $instance) { - $field = $instance->getField(); + $field = $instance->getFieldConfig(); // Sync when the field is not empty, when the synchronization translations // setting is set, and the field is translatable. diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php index c9bf33d..bb7a52a 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php @@ -56,14 +56,14 @@ protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_image'; $this->cardinality = 3; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->fieldName, 'type' => 'image', 'cardinality' => $this->cardinality, 'translatable' => TRUE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'bundle' => $this->entityType, diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php index b635c45..f6ff839 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php @@ -161,13 +161,13 @@ protected function enableTranslation() { protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_test'; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->fieldName, 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'bundle' => $this->bundle, diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index d2c35db..e0f75e6 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -131,9 +131,9 @@ function datetime_field_settings_form($field, $instance) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function datetime_field_instance_settings_form($field, $instance) { +function datetime_field_instance_config_settings_form($field, $instance) { $settings = $instance['settings']; $form['default_value'] = array( diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php index 267f691..a059c99 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\field\Plugin\PluginSettingsBase; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\DateHelper; @@ -43,7 +43,7 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio // Identify the function used to set the default value. // @todo Make this work for both configurable and nonconfigurable fields: // https://drupal.org/node/1989468. - if ($field_definition instanceof FieldInstanceInterface) { + if ($field_definition instanceof FieldInstanceConfigInterface) { $field_definition->default_value_function = $this->defaultValueFunction(); } parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php index 79f12bc..1793f3a 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\field\Plugin\PluginSettingsBase; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\Core\Datetime\DrupalDateTime; /** @@ -37,7 +37,7 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio // Identify the function used to set the default value. // @todo Make this work for both configurable and nonconfigurable fields: // https://drupal.org/node/1989468. - if ($field_definition instanceof FieldInstanceInterface) { + if ($field_definition instanceof FieldInstanceConfigInterface) { $field_definition->default_value_function = $this->defaultValueFunction(); } parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings); diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php index a0538d7..b69ea11 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php @@ -26,16 +26,16 @@ class DatetimeFieldTest extends WebTestBase { /** * A field to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The instance used in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; public static function getInfo() { return array( @@ -56,24 +56,24 @@ function setUp() { $this->drupalLogin($web_user); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'datetime', 'settings' => array('datetime_type' => 'date'), )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field->id(), + $this->field_config->save(); + $this->field_instance_config = entity_create('field_instance_config', array( + 'field_name' => $this->field_config->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'settings' => array( 'default_value' => 'blank', ), )); - $this->instance->save(); + $this->field_instance_config->save(); - entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') - ->setComponent($this->field->id(), array( + entity_get_form_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'default') + ->setComponent($this->field_config->id(), array( 'type' => 'datetime_default', )) ->save(); @@ -83,8 +83,8 @@ function setUp() { 'label' => 'hidden', 'settings' => array('format_type' => 'medium'), ); - entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($this->field->id(), $this->display_options) + entity_get_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'full') + ->setComponent($this->field_config->id(), $this->display_options) ->save(); } @@ -92,7 +92,7 @@ function setUp() { * Tests date field functionality. */ function testDateField() { - $field_name = $this->field->id(); + $field_name = $this->field_config->id(); // Display creation form. $this->drupalGet('entity_test/add'); @@ -130,7 +130,7 @@ function testDateField() { foreach ($values as $new_value) { // Update the entity display settings. $this->display_options['settings'] = array($setting => $new_value); - entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') + entity_get_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'full') ->setComponent($field_name, $this->display_options) ->save(); @@ -148,7 +148,7 @@ function testDateField() { // Verify that the plain formatter works. $this->display_options['type'] = 'datetime_plain'; - entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') + entity_get_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'full') ->setComponent($field_name, $this->display_options) ->save(); $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT); @@ -160,10 +160,10 @@ function testDateField() { * Tests date and time field. */ function testDatetimeField() { - $field_name = $this->field->id(); + $field_name = $this->field_config->id(); // Change the field to a datetime field. - $this->field['settings']['datetime_type'] = 'datetime'; - $this->field->save(); + $this->field_config['settings']['datetime_type'] = 'datetime'; + $this->field_config->save(); // Display creation form. $this->drupalGet('entity_test/add'); @@ -199,7 +199,7 @@ function testDatetimeField() { foreach ($values as $new_value) { // Update the entity display settings. $this->display_options['settings'] = array($setting => $new_value); - entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') + entity_get_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'full') ->setComponent($field_name, $this->display_options) ->save(); @@ -217,7 +217,7 @@ function testDatetimeField() { // Verify that the plain formatter works. $this->display_options['type'] = 'datetime_plain'; - entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') + entity_get_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'full') ->setComponent($field_name, $this->display_options) ->save(); $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); @@ -229,13 +229,13 @@ function testDatetimeField() { * Tests Date List Widget functionality. */ function testDatelistWidget() { - $field_name = $this->field->id(); + $field_name = $this->field_config->id(); // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); + $this->field_config->settings['datetime_type'] = 'datetime'; + $this->field_config->save(); // Change the widget to a datelist widget. - entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') + entity_get_form_display($this->field_instance_config->entity_type, $this->field_instance_config->bundle, 'default') ->setComponent($field_name, array( 'type' => 'datetime_datelist', 'settings' => array( @@ -297,14 +297,14 @@ function testDatelistWidget() { function testDefaultValue() { // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); - $field_name = $this->field->id(); + $this->field_config->settings['datetime_type'] = 'datetime'; + $this->field_config->save(); + $field_name = $this->field_config->id(); // Set the default value to 'now'. - $this->instance->settings['default_value'] = 'now'; - $this->instance->default_value_function = 'datetime_default_value'; - $this->instance->save(); + $this->field_instance_config->settings['default_value'] = 'now'; + $this->field_instance_config->default_value_function = 'datetime_default_value'; + $this->field_instance_config->save(); // Display creation form. $date = new DrupalDateTime(); @@ -320,9 +320,9 @@ function testDefaultValue() { $this->assertNoFieldByName("{$field_name}[$langcode][0][value][time]", '', 'Time element found.'); // Set the default value to 'blank'. - $this->instance->settings['default_value'] = 'blank'; - $this->instance->default_value_function = 'datetime_default_value'; - $this->instance->save(); + $this->field_instance_config->settings['default_value'] = 'blank'; + $this->field_instance_config->default_value_function = 'datetime_default_value'; + $this->field_instance_config->save(); // Display creation form. $date = new DrupalDateTime(); @@ -339,9 +339,9 @@ function testDefaultValue() { function testInvalidField() { // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); - $field_name = $this->field->id(); + $this->field_config->settings['datetime_type'] = 'datetime'; + $this->field_config->save(); + $field_name = $this->field_config->id(); // Display creation form. $this->drupalGet('entity_test/add'); diff --git a/core/modules/edit/lib/Drupal/edit/EditPluginInterface.php b/core/modules/edit/lib/Drupal/edit/EditPluginInterface.php index a568278..c2858d6 100644 --- a/core/modules/edit/lib/Drupal/edit/EditPluginInterface.php +++ b/core/modules/edit/lib/Drupal/edit/EditPluginInterface.php @@ -8,7 +8,7 @@ namespace Drupal\edit; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines an interface for in-place editors (Create.js PropertyEditor widgets). @@ -21,7 +21,7 @@ /** * Checks whether this editor is compatible with a given field instance. * - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * The field instance of the field being edited. * @param array $items * The field's item values. @@ -29,7 +29,7 @@ * @return bool * TRUE if it is compatible, FALSE otherwise. */ - public function isCompatible(FieldInstance $instance, array $items); + public function isCompatible(FieldInstanceConfig $field_instance_config, array $items); /** * Generates metadata that is needed specifically for this editor. @@ -37,7 +37,7 @@ public function isCompatible(FieldInstance $instance, array $items); * Will only be called by \Drupal\edit\MetadataGeneratorInterface::generate() * when the passed in field instance & item values will use this editor. * - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * The field instance of the field being edited. * @param array $items * The field's item values. @@ -46,7 +46,7 @@ public function isCompatible(FieldInstance $instance, array $items); * A keyed array with metadata. Each key should be prefixed with the plugin * ID of the editor. */ - public function getMetadata(FieldInstance $instance, array $items); + public function getMetadata(FieldInstanceConfig $field_instance_config, array $items); /** * Returns the attachments for this editor. diff --git a/core/modules/edit/lib/Drupal/edit/EditorBase.php b/core/modules/edit/lib/Drupal/edit/EditorBase.php index 39abaee..f56154f 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorBase.php +++ b/core/modules/edit/lib/Drupal/edit/EditorBase.php @@ -9,7 +9,7 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\edit\EditPluginInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines a base editor implementation. @@ -19,7 +19,7 @@ /** * Implements \Drupal\edit\EditPluginInterface::getMetadata(). */ - function getMetadata(FieldInstance $instance, array $items) { + function getMetadata(FieldInstanceConfig $instance, array $items) { return array(); } diff --git a/core/modules/edit/lib/Drupal/edit/EditorSelector.php b/core/modules/edit/lib/Drupal/edit/EditorSelector.php index 232a52f..382cec0 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorSelector.php +++ b/core/modules/edit/lib/Drupal/edit/EditorSelector.php @@ -9,7 +9,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Utility\NestedArray; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Selects an in-place editor (an Editor plugin) for a field. @@ -43,7 +43,7 @@ public function __construct(PluginManagerInterface $editor_manager) { /** * {@inheritdoc} */ - public function getEditor($formatter_type, FieldInstance $instance, array $items) { + public function getEditor($formatter_type, FieldInstanceConfig $instance, array $items) { // Build a static cache of the editors that have registered themselves as // alternatives to a certain editor. if (!isset($this->alternatives)) { diff --git a/core/modules/edit/lib/Drupal/edit/EditorSelectorInterface.php b/core/modules/edit/lib/Drupal/edit/EditorSelectorInterface.php index 990c207..2c07dd2 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorSelectorInterface.php +++ b/core/modules/edit/lib/Drupal/edit/EditorSelectorInterface.php @@ -7,7 +7,7 @@ namespace Drupal\edit; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Interface for selecting an in-place editor (an Editor plugin) for a field. @@ -19,7 +19,7 @@ * * @param string $formatter_type * The field's formatter type name. - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * The field's instance info. * @param array $items * The field's item values. @@ -27,7 +27,7 @@ * @return string|NULL * The editor to use, or NULL to not enable in-place editing. */ - public function getEditor($formatter_type, FieldInstance $instance, array $items); + public function getEditor($formatter_type, FieldInstanceConfig $field_instance_config, array $items); /** * Returns the attachments for all editors. diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php index 8347c00..e565bf3 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\edit\Access\EditEntityFieldAccessCheckInterface; @@ -67,7 +67,7 @@ public function generateEntity(EntityInterface $entity, $langcode) { /** * {@inheritdoc} */ - public function generateField(EntityInterface $entity, FieldInstance $instance, $langcode, $view_mode) { + public function generateField(EntityInterface $entity, FieldInstanceConfig $instance, $langcode, $view_mode) { $field_name = $instance['field_name']; // Early-return if user does not have access. diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php b/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php index 7baaf5b..1acd4db 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php @@ -8,7 +8,7 @@ namespace Drupal\edit; use Drupal\Core\Entity\EntityInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Interface for generating in-place editing metadata. @@ -33,7 +33,7 @@ public function generateEntity(EntityInterface $entity, $langcode); * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity being edited. - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * The field instance of the field being edited. * @param string $langcode * The name of the language for which the field is being edited. @@ -47,6 +47,6 @@ public function generateEntity(EntityInterface $entity, $langcode); * - aria: the ARIA label. * - custom: (optional) any additional metadata that the editor provides. */ - public function generateField(EntityInterface $entity, FieldInstance $instance, $langcode, $view_mode); + public function generateField(EntityInterface $entity, FieldInstanceConfig $field_instance_config, $langcode, $view_mode); } diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/DirectEditor.php b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/DirectEditor.php index 39176d1..ac668a0 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/DirectEditor.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/DirectEditor.php @@ -9,7 +9,7 @@ use Drupal\edit\EditorBase; use Drupal\edit\Annotation\InPlaceEditor; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines the direct editor. @@ -26,7 +26,7 @@ class DirectEditor extends EditorBase { * @todo The processed text logic is too coupled to text fields. Figure out * how to generalize to other textual field types. */ - function isCompatible(FieldInstance $instance, array $items) { + function isCompatible(FieldInstanceConfig $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/FormEditor.php b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/FormEditor.php index ec8d406..bbe2025 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/FormEditor.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditor/FormEditor.php @@ -9,7 +9,7 @@ use Drupal\edit\EditorBase; use Drupal\edit\Annotation\InPlaceEditor; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines the form editor. @@ -23,7 +23,7 @@ class FormEditor extends EditorBase { /** * Implements \Drupal\edit\EditPluginInterface::isCompatible(). */ - function isCompatible(FieldInstance $instance, array $items) { + function isCompatible(FieldInstanceConfig $instance, array $items) { return TRUE; } diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index 649f033..14d2402 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -54,7 +54,7 @@ function setUp() { */ function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) { $field = $field_name . '_field'; - $this->$field = entity_create('field_entity', array( + $this->$field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => $type, 'cardinality' => $cardinality, @@ -62,7 +62,7 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst $this->$field->save(); $instance = $field_name . '_instance'; - $this->$instance = entity_create('field_instance', array( + $this->$instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php index c1982c5..dd0e71b 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php @@ -45,13 +45,13 @@ function setUp() { } /** - * Retrieves the FieldInstance object for the given field and returns the + * Retrieves the FieldInstanceConfig object for the given field and returns the * editor that Edit selects. */ protected function getSelectedEditor($items, $field_name, $view_mode = 'default') { $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name); - $field_instance = field_info_instance('entity_test', $field_name, 'entity_test'); - return $this->editorSelector->getEditor($options['type'], $field_instance, $items); + $field_instance_config = field_info_instance('entity_test', $field_name, 'entity_test'); + return $this->editorSelector->getEditor($options['type'], $field_instance_config, $items); } /** diff --git a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/InPlaceEditor/WysiwygEditor.php b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/InPlaceEditor/WysiwygEditor.php index 59fe895..40d9d14 100644 --- a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/InPlaceEditor/WysiwygEditor.php +++ b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/InPlaceEditor/WysiwygEditor.php @@ -9,7 +9,7 @@ use Drupal\edit\EditorBase; use Drupal\edit\Annotation\InPlaceEditor; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines the wysiwyg editor. @@ -24,7 +24,7 @@ class WysiwygEditor extends EditorBase { /** * Implements \Drupal\edit\EditPluginInterface::isCompatible(). */ - function isCompatible(FieldInstance $instance, array $items) { + function isCompatible(FieldInstanceConfig $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. @@ -46,7 +46,7 @@ function isCompatible(FieldInstance $instance, array $items) { /** * Implements \Drupal\edit\EditPluginInterface::getMetadata(). */ - function getMetadata(FieldInstance $instance, array $items) { + function getMetadata(FieldInstanceConfig $instance, array $items) { $format_id = $items[0]['format']; $metadata['format'] = $format_id; return $metadata; diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php b/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php index 7c281c0..3856e6b 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php @@ -11,7 +11,7 @@ use Drupal\edit\Annotation\InPlaceEditor; use Drupal\Core\Annotation\Translation; use Drupal\edit\EditPluginInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Defines the formatted text editor. @@ -26,7 +26,7 @@ class Editor extends PluginBase implements EditPluginInterface { /** * Implements \Drupal\edit\Plugin\EditPluginInterface::isCompatible(). */ - function isCompatible(FieldInstance $instance, array $items) { + function isCompatible(FieldInstanceConfig $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. @@ -52,7 +52,7 @@ function isCompatible(FieldInstance $instance, array $items) { /** * Implements \Drupal\edit\Plugin\EditPluginInterface::getMetadata(). */ - function getMetadata(FieldInstance $instance, array $items) { + function getMetadata(FieldInstanceConfig $instance, array $items) { $format_id = $items[0]['format']; $metadata['format'] = $format_id; $metadata['formatHasTransformations'] = $this->textFormatHasTransformationFilters($format_id); diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php index d2ec5e6..51d5c17 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php @@ -106,13 +106,13 @@ function setUp() { } /** - * Retrieves the FieldInstance object for the given field and returns the + * Retrieves the FieldInstanceConfig object for the given field and returns the * editor that Edit selects. */ protected function getSelectedEditor($items, $field_name, $view_mode = 'default') { $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name); - $field_instance = field_info_instance('entity_test', $field_name, 'entity_test'); - return $this->editorSelector->getEditor($options['type'], $field_instance, $items); + $field_instance_config = field_info_instance('entity_test', $field_name, 'entity_test'); + return $this->editorSelector->getEditor($options['type'], $field_instance_config, $items); } /** diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index 2d76d76..26e6a02 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -25,16 +25,16 @@ class EmailFieldTest extends WebTestBase { /** * A field to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The instance used in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; public static function getInfo() { return array( @@ -61,17 +61,17 @@ function setUp() { function testEmailField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'email', )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->field_config->save(); + $this->field_instance_config = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); - $this->instance->save(); + $this->field_instance_config->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php index 7e72163..fb120c4 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php @@ -35,11 +35,11 @@ public function setUp() { parent::setUp(); // Create an email field and instance for validation. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_email', 'type' => 'email', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_email', 'bundle' => 'entity_test', diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 6a0ddc5..9b5c42f 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -141,12 +141,12 @@ public function testFieldComponent() { $field_name = 'test_field'; // Create a field and an instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -243,12 +243,12 @@ public function testDeleteFieldInstance() { $field_name = 'test_field'; // Create a field and an instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php index a74c966..b489258 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php @@ -63,12 +63,12 @@ public function testFieldComponent() { // Create a field and an instance. $field_name = 'test_field'; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 5e438e6..d14bb81 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -9,7 +9,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; -use Drupal\field\FieldInterface; +use Drupal\field\FieldConfigInterface; /** * Implements hook_field_info(). @@ -158,29 +158,29 @@ function entity_reference_field_settings_form($field, $instance) { } /** - * Implements hook_ENTITY_TYPE_update() for 'field_entity'. + * Implements hook_ENTITY_TYPE_update() for 'field_config'. * * Reset the instance handler settings, when the target type is changed. */ -function entity_reference_field_entity_update(FieldInterface $field) { - if ($field->type != 'entity_reference') { +function entity_reference_field_config_update(FieldConfigInterface $field_config) { + if ($field_config->type != 'entity_reference') { // Only act on entity reference fields. return; } - if ($field->settings['target_type'] == $field->original->settings['target_type']) { + if ($field_config->settings['target_type'] == $field_config->original->settings['target_type']) { // Target type didn't change. return; } - if (empty($field->bundles)) { + if (empty($field_config->bundles)) { // Field has no instances. return; } - $field_name = $field->id(); + $field_name = $field_config->id(); - foreach ($field->bundles() as $entity_type => $bundles) { + foreach ($field_config->bundles() as $entity_type => $bundles) { foreach ($bundles as $bundle) { $instance = field_info_instance($entity_type, $field_name, $bundle); $instance->settings['handler_settings'] = array(); @@ -190,9 +190,9 @@ function entity_reference_field_entity_update(FieldInterface $field) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function entity_reference_field_instance_settings_form($field, $instance, $form_state) { +function entity_reference_field_instance_config_settings_form($field, $instance, $form_state) { $field = isset($form_state['entity_reference']['field']) ? $form_state['entity_reference']['field'] : $field; $instance = isset($form_state['entity_reference']['instance']) ? $form_state['entity_reference']['instance'] : $instance; @@ -219,9 +219,9 @@ function entity_reference_field_instance_settings_form($field, $instance, $form_ 'css' => array(drupal_get_path('module', 'entity_reference') . '/css/entity_reference.admin.css'), ), '#process' => array( - '_entity_reference_field_instance_settings_ajax_process', + '_entity_reference_field_instance_config_settings_ajax_process', ), - '#element_validate' => array('_entity_reference_field_instance_settings_validate'), + '#element_validate' => array('_entity_reference_field_instance_config_settings_validate'), '#field' => $field, '#instance' => $instance, ); @@ -266,10 +266,10 @@ function entity_reference_field_instance_settings_form($field, $instance, $form_ * Render API callback: Processes the field instance settings form and allows * access to the form state. * - * @see entity_reference_field_instance_settings_form() + * @see entity_reference_field_instance_config_settings_form() */ -function _entity_reference_field_instance_settings_ajax_process($form, $form_state) { - _entity_reference_field_instance_settings_ajax_process_element($form, $form); +function _entity_reference_field_instance_config_settings_ajax_process($form, $form_state) { + _entity_reference_field_instance_config_settings_ajax_process_element($form, $form); return $form; } @@ -277,9 +277,9 @@ function _entity_reference_field_instance_settings_ajax_process($form, $form_sta * Adds entity_reference specific properties to AJAX form elements from the * field instance settings form. * - * @see _entity_reference_field_instance_settings_ajax_process() + * @see _entity_reference_field_instance_config_settings_ajax_process() */ -function _entity_reference_field_instance_settings_ajax_process_element(&$element, $main_form) { +function _entity_reference_field_instance_config_settings_ajax_process_element(&$element, $main_form) { if (!empty($element['#ajax'])) { $element['#ajax'] = array( 'callback' => 'entity_reference_settings_ajax', @@ -289,7 +289,7 @@ function _entity_reference_field_instance_settings_ajax_process_element(&$elemen } foreach (element_children($element) as $key) { - _entity_reference_field_instance_settings_ajax_process_element($element[$key], $main_form); + _entity_reference_field_instance_config_settings_ajax_process_element($element[$key], $main_form); } } @@ -318,9 +318,9 @@ function _entity_reference_element_validate_filter(&$element, &$form_state) { /** * Form element validation handler; Stores the new values in the form state. * - * @see entity_reference_field_instance_settings_form() + * @see entity_reference_field_instance_config_settings_form() */ -function _entity_reference_field_instance_settings_validate($form, &$form_state) { +function _entity_reference_field_instance_config_settings_validate($form, &$form_state) { $instance = $form['#instance']; if (isset($form_state['values']['instance'])) { $instance['settings'] = $form_state['values']['instance']['settings']; @@ -333,7 +333,7 @@ function _entity_reference_field_instance_settings_validate($form, &$form_state) /** * Ajax callback for the handler settings form. * - * @see entity_reference_field_instance_settings_form() + * @see entity_reference_field_instance_config_settings_form() */ function entity_reference_settings_ajax($form, $form_state) { $trigger = $form_state['triggering_element']; @@ -343,7 +343,7 @@ function entity_reference_settings_ajax($form, $form_state) { /** * Submit handler for the non-JS case. * - * @see entity_reference_field_instance_settings_form() + * @see entity_reference_field_instance_config_settings_form() */ function entity_reference_settings_ajax_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; @@ -419,7 +419,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f 'target_type' => $target_entity_type, ), ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); } if (empty($instance)) { @@ -433,7 +433,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f 'handler_settings' => $selection_handler_settings, ), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php index 932f55f..ef1a04c 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php @@ -106,4 +106,5 @@ public function testFieldAdminHandler() { // Check that the field appears in the overview form. $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', 'Test label', 'Field was created and appears in the overview page.'); } + } 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 f5f74d0..8be3f0d 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 @@ -35,7 +35,7 @@ function setUp() { $referenced = $this->drupalCreateContentType(); $this->referenced_type = $referenced->type; - entity_create('field_entity', array( + entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -46,7 +46,7 @@ function setUp() { 'cardinality' => FIELD_CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'label' => 'Entity reference field', 'field_name' => 'test_field', 'entity_type' => 'node', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index 9a611d4..3c8310e 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -60,7 +60,7 @@ protected function assertReferenceable(FieldDefinitionInterface $field_definitio */ public function testNodeHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -71,7 +71,7 @@ public function testNodeHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', @@ -203,7 +203,7 @@ public function testNodeHandler() { */ public function testUserHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -214,7 +214,7 @@ public function testUserHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', @@ -348,7 +348,7 @@ public function testUserHandler() { */ public function testCommentHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -359,7 +359,7 @@ public function testCommentHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 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 f7b8fbc..bf4efdc 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 @@ -36,13 +36,13 @@ function setUp() { */ public function testSort() { // Add text field to entity, to sort by. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_text', 'type' => 'text', 'entity_types' => array('node'), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'label' => 'Text Field', 'field_name' => 'field_text', 'entity_type' => 'node', @@ -53,7 +53,7 @@ public function testSort() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -64,7 +64,7 @@ public function testSort() { 'cardinality' => 1, )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php index 8127682..deea202 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php @@ -40,7 +40,7 @@ public function testSelectionHandler() { } // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -51,7 +51,7 @@ public function testSelectionHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 02fd704..f68d4cc 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -1294,7 +1294,7 @@ function hook_field_purge_field($field) { * The instance being purged. */ function hook_field_purge_instance($instance) { - db_delete('my_module_field_instance_info') + db_delete('my_module_field_instance_config_info') ->condition('id', $instance['id']) ->execute(); } @@ -1324,8 +1324,8 @@ function hook_field_storage_purge_field($field) { * @param $instance * The instance being purged. */ -function hook_field_storage_purge_field_instance($instance) { - db_delete('my_module_field_instance_info') +function hook_field_storage_purge_field_instance_config($instance) { + db_delete('my_module_field_instance_config_info') ->condition('id', $instance['id']) ->execute(); } @@ -1368,7 +1368,7 @@ function hook_field_storage_purge(\Drupal\Core\Entity\EntityInterface $entity, $ * * @param $op * The operation to be performed. Possible values: 'edit', 'view'. - * @param \Drupal\field\FieldInterface $field + * @param \Drupal\field\FieldConfigInterface $field_config * The field on which the operation is to be performed. * @param $entity_type * The type of $entity; for example, 'node' or 'user'. @@ -1377,11 +1377,11 @@ function hook_field_storage_purge(\Drupal\Core\Entity\EntityInterface $entity, $ * @param $account * (optional) The account to check; if not given use currently logged in user. * - * @return - * TRUE if the operation is allowed, and FALSE if the operation is denied. + * @return bool TRUE if the operation is allowed, and FALSE if the operation is + * denied. */ -function hook_field_access($op, \Drupal\field\FieldInterface $field, $entity_type, $entity, $account) { - if ($field['field_name'] == 'field_of_interest' && $op == 'edit') { +function hook_field_access($op, \Drupal\field\FieldConfigInterface $field_config, $entity_type, $entity, $account) { + if ($field_config['field_name'] == 'field_of_interest' && $op == 'edit') { return user_access('edit field of interest', $account); } return TRUE; diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 5ed17ff..4ed2962 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -653,7 +653,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $ } foreach ($instances as $instance) { - $field = $instance->getField(); + $field = $instance->getFieldConfig(); $field_name = $field->id(); if (!isset($queried_entities[$id]->{$field_name})) { $queried_entities[$id]->{$field_name} = array(); @@ -684,7 +684,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $ // values for a deleted field. Instead, generate FieldItem objects // directly, and call their prepareCache() method. foreach ($queried_entities as $entity) { - $field = $options['instance']->getField(); + $field = $options['instance']->getFieldConfig(); $field_name = $field->id(); // Call the prepareCache() method on each item. foreach ($entity->{$field_name} as $langcode => $values) { diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index ed129df..3cbb709 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -6,8 +6,8 @@ */ use Drupal\Core\Entity\EntityInterface; -use Drupal\field\Plugin\Core\Entity\Field; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldConfig; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\field\FieldException; /** @@ -43,7 +43,7 @@ * A field definition array, or FALSE. * * @deprecated as of Drupal 8.0. Use - * entity_load('field_entity', 'field_name'). + * entity_load('field_config', 'field_name'). */ function field_read_field($field_name, $include_additional = array()) { $fields = field_read_fields(array('field_name' => $field_name), $include_additional); @@ -68,7 +68,7 @@ function field_read_field($field_name, $include_additional = array()) { * field ID, otherwise it is keyed by field name. * * @deprecated as of Drupal 8.0. Use - * entity_load_multiple_by_properties('field_entity', $conditions). + * entity_load_multiple_by_properties('field_config', $conditions). */ function field_read_fields($conditions = array(), $include_additional = array()) { // Include inactive fields if specified in the $include_additional parameter. @@ -81,7 +81,7 @@ function field_read_fields($conditions = array(), $include_additional = array()) $conditions['include_inactive'] = $include_inactive; $conditions['include_deleted'] = $include_deleted; - return entity_load_multiple_by_properties('field_entity', $conditions); + return entity_load_multiple_by_properties('field_config', $conditions); } /** @@ -107,7 +107,7 @@ function field_read_fields($conditions = array(), $include_additional = array()) * An instance structure, or FALSE. * * @deprecated as of Drupal 8.0. Use - * entity_load('field_instance', 'field_name'). + * entity_load('field_instance_config', 'field_name'). */ function field_read_instance($entity_type, $field_name, $bundle, $include_additional = array()) { $instances = field_read_instances(array('entity_type' => $entity_type, 'field_name' => $field_name, 'bundle' => $bundle), $include_additional); @@ -131,7 +131,7 @@ function field_read_instance($entity_type, $field_name, $bundle, $include_additi * An array of instances matching the arguments. * * @deprecated as of Drupal 8.0. Use - * entity_load_multiple_by_properties('field_instance', $conditions). + * entity_load_multiple_by_properties('field_instance_config', $conditions). */ function field_read_instances($conditions = array(), $include_additional = array()) { // Include instances of inactive fields if specified in the @@ -145,7 +145,7 @@ function field_read_instances($conditions = array(), $include_additional = array $conditions['include_inactive'] = $include_inactive; $conditions['include_deleted'] = $include_deleted; - return entity_load_multiple_by_properties('field_instance', $conditions); + return entity_load_multiple_by_properties('field_instance_config', $conditions); } /** @@ -290,7 +290,7 @@ function field_purge_batch($batch_size) { // Retrieve all deleted fields. Any that have no instances can be purged. $deleted_fields = Drupal::state()->get('field.field.deleted') ?: array(); foreach ($deleted_fields as $field) { - $field = new Field($field); + $field = new FieldConfig($field); $instances = field_read_instances(array('field_id' => $field['uuid']), array('include_deleted' => 1)); if (empty($instances)) { field_purge_field($field); diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index b6b2a95..3f778ee 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -7,7 +7,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Language\Language; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\field\Field; /** @@ -158,7 +158,7 @@ function field_behaviors_widget($op, $instance) { * @endcode * * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFieldMap(). + * FieldConfig::fieldInfo()->getFieldMap(). */ function field_info_field_map() { return Field::fieldInfo()->getFieldMap(); @@ -298,7 +298,7 @@ function field_info_fields() { * @see field_info_field_by_id() * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getField($field_name). + * FieldConfig::fieldInfo()->getField($field_name). */ function field_info_field($field_name) { return Field::fieldInfo()->getField($field_name); @@ -319,7 +319,7 @@ function field_info_field($field_name) { * @see field_info_field() * * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFieldById($field_id). + * FieldConfig::fieldInfo()->getFieldById($field_id). */ function field_info_field_by_id($field_id) { return Field::fieldInfo()->getFieldById($field_id); @@ -344,7 +344,7 @@ function field_info_field_by_id($field_id) { * @see field_info_field_by_id() * * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFields(). + * FieldConfig::fieldInfo()->getFields(). */ function field_info_field_by_ids() { return Field::fieldInfo()->getFields(); @@ -376,9 +376,9 @@ function field_info_field_by_ids() { * return all instances for that bundle. * * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getInstances(), - * Field::fieldInfo()->getInstances($entity_type) or - * Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name). + * FieldConfig::fieldInfo()->getInstances(), + * FieldConfig::fieldInfo()->getInstances($entity_type) or + * FieldConfig::fieldInfo()->getBundleInstances($entity_type, $bundle_name). */ function field_info_instances($entity_type = NULL, $bundle_name = NULL) { $cache = Field::fieldInfo(); @@ -413,7 +413,7 @@ function field_info_instances($entity_type = NULL, $bundle_name = NULL) { * NULL if the instance does not exist. * * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getBundleInstance($entity_type, $bundle, $field_name). + * FieldConfig::fieldInfo()->getBundleInstance($entity_type, $bundle, $field_name). */ function field_info_instance($entity_type, $field_name, $bundle_name) { return Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name); diff --git a/core/modules/field/field.install b/core/modules/field/field.install index b425169..2eddd63 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -6,7 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Creates a field by writing directly to configuration. @@ -14,16 +14,16 @@ * Upgrades using this function need to use hook_update_dependencies() to ensure * they get executed after field_update_8003(). * - * @param array $field_config + * @param array $field_config_raw * An array of field properties. * * @ingroup update_api */ -function _update_8003_field_create_field(array &$field_config) { +function _update_8003_field_create_field(array &$field_config_raw) { $uuid = new Uuid(); // Merge in default values. - $field_config += array( + $field_config_raw += array( 'uuid' => $uuid->generate(), 'entity_types' => array(), 'cardinality' => 1, @@ -37,7 +37,7 @@ function _update_8003_field_create_field(array &$field_config) { ); // Set the storage. - $field_config['storage'] = array( + $field_config_raw['storage'] = array( 'type' => 'field_sql_storage', 'module' => 'field_sql_storage', 'active' => TRUE, @@ -45,14 +45,14 @@ function _update_8003_field_create_field(array &$field_config) { ); // Save in config. - Drupal::config('field.field.' . $field_config['id']) - ->setData($field_config) + Drupal::config('field.field.' . $field_config_raw['id']) + ->setData($field_config_raw) ->save(); // Create storage for the field. This requires a field entity, but cannot use // the regular entity_create() function here. - $field_entity = new Field($field_config); - field_sql_storage_field_storage_create_field($field_entity); + $field_config = new FieldConfig($field_config_raw); + field_sql_storage_field_storage_create_field($field_config); } /** @@ -61,23 +61,23 @@ function _update_8003_field_create_field(array &$field_config) { * Upgrades using this function need to use hook_update_dependencies() to ensure * they get executed after field_update_8003(). * - * @param array $field_config + * @param array $field_config_raw * An array of field properties. - * @param array $instance_config + * @param array $field_instance_config_raw * An array of field instance properties. * * @ingroup update_api */ -function _update_8003_field_create_instance(array $field_config, array &$instance_config) { +function _update_8003_field_create_instance(array $field_config_raw, array &$field_instance_config_raw) { $uuid = new Uuid(); // Merge in defaults. - $instance_config += array( + $field_instance_config_raw += array( 'description' => '', 'required' => FALSE, 'uuid' => $uuid->generate(), - 'field_uuid' => $field_config['uuid'], - 'field_type' => $field_config['type'], + 'field_uuid' => $field_config_raw['uuid'], + 'field_type' => $field_config_raw['type'], 'default_value' => array(), 'default_value_function' => '', 'settings' => array(), @@ -87,8 +87,8 @@ function _update_8003_field_create_instance(array $field_config, array &$instanc ); // Save in config. - Drupal::config('field.instance.' . $instance_config['id']) - ->setData($instance_config) + Drupal::config('field.instance.' . $field_instance_config_raw['id']) + ->setData($field_instance_config_raw) ->save(); } @@ -294,7 +294,7 @@ function field_update_8003() { // this would belong in an update in field_sql_storage.module, but it is // easier to do it now, when the old numeric ID is available. if ($config['storage']['type'] == 'field_sql_storage') { - $field = new Field($config); + $field = new FieldConfig($config); $tables = array( "field_deleted_data_{$record['id']}" => _field_sql_storage_tablename($field), "field_deleted_revision_{$record['id']}" => _field_sql_storage_revision_tablename($field), @@ -395,14 +395,14 @@ function field_update_8005() { 'content' => array(), ); foreach (config_get_storage_names_with_prefix('field.instance') as $config_id) { - $instance_config = Drupal::config($config_id); - if ($instance_config->get('entity_type') == 'user' && $instance_config->get('settings.user_register_form')) { - list(, , $field_id) = explode('.', $instance_config->get('id')); + $field_instance_config_raw = Drupal::config($config_id); + if ($field_instance_config_raw->get('entity_type') == 'user' && $field_instance_config_raw->get('settings.user_register_form')) { + list(, , $field_id) = explode('.', $field_instance_config_raw->get('id')); $user_register_config_data['content'][$field_id] = $user_default_form_display->get('content.' . $field_id); } - $settings = $instance_config->get('settings'); + $settings = $field_instance_config_raw->get('settings'); unset($settings['user_register_form']); - $instance_config->set('settings', $settings)->save(); + $field_instance_config_raw->set('settings', $settings)->save(); } // Save the new 'register' form display. diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 88f1574..33c1171 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -7,8 +7,8 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; -use Drupal\field\FieldInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\Core\Entity\EntityNG; /* @@ -277,7 +277,7 @@ function field_entity_field_info($entity_type) { $optional = $bundle_name != $entity_type; foreach ($instances as $field_name => $instance) { - $definition = _field_generate_entity_field_definition($instance->getField()); + $definition = _field_generate_entity_field_definition($instance->getFieldConfig()); if ($optional) { $property_info['optional'][$field_name] = $definition; @@ -295,25 +295,25 @@ function field_entity_field_info($entity_type) { /** * Generates an entity field definition for a configurable field. * - * @param \Drupal\field\FieldInterface $field + * @param \Drupal\field\FieldConfigInterface $field_config * The field definition. - * @param \Drupal\field\FieldInstanceInterface $instance + * @param \Drupal\field\FieldInstanceConfigInterface $field_instance_config * (Optional) The field instance definition. * * @return array * The entity field definition. */ -function _field_generate_entity_field_definition(FieldInterface $field, FieldInstanceInterface $instance = NULL) { +function _field_generate_entity_field_definition(FieldConfigInterface $field_config, FieldInstanceConfigInterface $field_instance_config = NULL) { // @todo: Allow for adding field type settings. $definition = array( - 'label' => t('Field !name', array('!name' => $field->id())), - 'type' => 'field_item:' . $field->type, + 'label' => t('Field !name', array('!name' => $field_config->id())), + 'type' => 'field_item:' . $field_config->type, 'list' => TRUE, 'configurable' => TRUE, - 'translatable' => !empty($field->translatable), + 'translatable' => !empty($field_config->translatable), ); - if ($instance) { - $definition['instance'] = $instance; + if ($field_instance_config) { + $definition['instance'] = $field_instance_config; } return $definition; @@ -863,7 +863,7 @@ function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) * The operation to be performed. Possible values: * - edit * - view - * @param \Drupal\field\FieldInterface $field + * @param \Drupal\field\FieldConfigInterface $field_config * The field on which the operation is to be performed. * @param $entity_type * The type of $entity; for example, 'node' or 'user'. @@ -875,7 +875,7 @@ function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) * @return * TRUE if the operation is allowed; FALSE if the operation is denied. */ -function field_access($op, FieldInterface $field, $entity_type, $entity = NULL, $account = NULL) { +function field_access($op, FieldConfigInterface $field_config, $entity_type, $entity = NULL, $account = NULL) { global $user; if (!isset($account)) { @@ -884,7 +884,7 @@ function field_access($op, FieldInterface $field, $entity_type, $entity = NULL, foreach (module_implements('field_access') as $module) { $function = $module . '_field_access'; - $access = $function($op, $field, $entity_type, $entity, $account); + $access = $function($op, $field_config, $entity_type, $entity, $account); if ($access === FALSE) { return FALSE; } diff --git a/core/modules/field/lib/Drupal/field/Field.php b/core/modules/field/lib/Drupal/field/Field.php index 80d356f..37188eb 100644 --- a/core/modules/field/lib/Drupal/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Field.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\Field. + * Contains \Drupal\field\FieldConfig. */ namespace Drupal\field; @@ -10,7 +10,7 @@ use Drupal; /** - * Static service container wrapper for Field. + * Static service container wrapper for FieldConfig. */ class Field { diff --git a/core/modules/field/lib/Drupal/field/FieldConfigInterface.php b/core/modules/field/lib/Drupal/field/FieldConfigInterface.php new file mode 100644 index 0000000..e11fcdd --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldConfigInterface.php @@ -0,0 +1,84 @@ +config->get($config_id)->get(); - if ($field_config['active'] && $field_config['storage']['active']) { - $fields[$field_config['uuid']] = $field_config; + $field_config_raw = $this->config->get($config_id)->get(); + if ($field_config_raw['active'] && $field_config_raw['storage']['active']) { + $fields[$field_config_raw['uuid']] = $field_config_raw; } } // Get field instances. foreach (config_get_storage_names_with_prefix('field.instance.') as $config_id) { - $instance_config = $this->config->get($config_id)->get(); - $field_uuid = $instance_config['field_uuid']; + $field_instance_config_raw = $this->config->get($config_id)->get(); + $field_uuid = $field_instance_config_raw['field_uuid']; // Filter out instances of inactive fields, and instances on unknown // entity types. if (isset($fields[$field_uuid])) { $field = $fields[$field_uuid]; - $map[$field['id']]['bundles'][$instance_config['entity_type']][] = $instance_config['bundle']; + $map[$field['id']]['bundles'][$field_instance_config_raw['entity_type']][] = $field_instance_config_raw['bundle']; $map[$field['id']]['type'] = $field['type']; } } @@ -436,8 +436,8 @@ public function getBundleInstances($entity_type, $bundle) { // Load and prepare the corresponding fields and instances entities. if ($config_ids) { - $loaded_fields = entity_load_multiple('field_entity', array_keys($config_ids)); - $loaded_instances = entity_load_multiple('field_instance', array_values($config_ids)); + $loaded_fields = entity_load_multiple('field_config', array_keys($config_ids)); + $loaded_instances = entity_load_multiple('field_instance_config', array_values($config_ids)); foreach ($loaded_instances as $instance) { $field = $loaded_fields[$instance['field_name']]; diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceConfigInterface.php b/core/modules/field/lib/Drupal/field/FieldInstanceConfigInterface.php new file mode 100644 index 0000000..7e20bfc --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldInstanceConfigInterface.php @@ -0,0 +1,35 @@ +getField(); + $field = $instance->getFieldConfig(); // Only keep the instance if it matches all conditions. foreach ($conditions as $key => $value) { diff --git a/core/modules/field/lib/Drupal/field/FieldInterface.php b/core/modules/field/lib/Drupal/field/FieldInterface.php deleted file mode 100644 index 132bc39..0000000 --- a/core/modules/field/lib/Drupal/field/FieldInterface.php +++ /dev/null @@ -1,84 +0,0 @@ -$field_id}. The maximum length is - * Field:ID_MAX_LENGTH. - * - * Example: body, field_main_image. - * - * @var string - */ - public $id; - - /** - * The field UUID. - * - * This is assigned automatically when the field is created. - * - * @var string - */ - public $uuid; - - /** - * The field type. - * - * Example: text, number_integer. - * - * @var string - */ - public $type; - - /** - * The name of the module that provides the field type. - * - * @var string - */ - public $module; - - /** - * Flag indicating whether the field type module is enabled. - * - * @var bool - */ - public $active; - - /** - * Field-type specific settings. - * - * An array of key/value pairs, The keys and default values are defined by the - * field type. - * - * @var array - */ - public $settings = array(); - - /** - * The field cardinality. - * - * The maximum number of values the field can hold. Possible values are - * positive integers or FIELD_CARDINALITY_UNLIMITED. Defaults to 1. - * - * @var integer - */ - public $cardinality = 1; - - /** - * Flag indicating whether the field is translatable. - * - * Defaults to FALSE. - * - * @var bool - */ - public $translatable = FALSE; - - /** - * The entity types on which the field is allowed to have instances. - * - * If empty or not specified, the field is allowed to have instances in any - * entity type. - * - * @var array - */ - public $entity_types = array(); - - /** - * Flag indicating whether the field is available for editing. - * - * If TRUE, some actions not available though the UI (but are still possible - * through direct API manipulation): - * - field settings cannot be changed, - * - new instances cannot be created - * - existing instances cannot be deleted. - * Defaults to FALSE. - * - * @var bool - */ - public $locked = FALSE; - - /** - * The field storage definition. - * - * An array of key/value pairs identifying the storage backend to use for the - * field: - * - type: (string) The storage backend used by the field. Storage backends - * are defined by modules that implement hook_field_storage_info(). - * - settings: (array) A sub-array of key/value pairs of settings. The keys - * and default values are defined by the storage backend in the 'settings' - * entry of hook_field_storage_info(). - * - module: (string, read-only) The name of the module that implements the - * storage backend. - * - active: (integer, read-only) TRUE if the module that implements the - * storage backend is currently enabled, FALSE otherwise. - * - * @var array - */ - public $storage = array(); - - /** - * The custom storage indexes for the field data storage. - * - * This set of indexes is merged with the "default" indexes specified by the - * field type in hook_field_schema() to determine the actual set of indexes - * that get created. - * - * The indexes are defined using the same definition format as Schema API - * index specifications. Only columns that are part of the field schema, as - * defined by the field type in hook_field_schema(), are allowed. - * - * Some storage backends might not support indexes, and discard that - * information. - * - * @var array - */ - public $indexes = array(); - - /** - * Flag indicating whether the field is deleted. - * - * The delete() method marks the field as "deleted" and removes the - * corresponding entry from the config storage, but keeps its definition in - * the state storage while field data is purged by a separate - * garbage-collection process. - * - * Deleted fields stay out of the regular entity lifecycle (notably, their - * values are not populated in loaded entities, and are not saved back). - * - * @var bool - */ - public $deleted = FALSE; - - /** - * The field schema. - * - * @var array - */ - protected $schema; - - /** - * The storage information for the field. - * - * @var array - */ - protected $storageDetails; - - /** - * The original field. - * - * @var \Drupal\field\Plugin\Core\Entity\Field - */ - public $original = NULL; - - /** - * Constructs a Field object. - * - * @param array $values - * An array of field properties, keyed by property name. Most array - * elements will be used to set the corresponding properties on the class; - * see the class property documentation for details. Some array elements - * have special meanings and a few are required. Special elements are: - * - id: required. As a temporary Backwards Compatibility layer right now, - * a 'field_name' property can be accepted in place of 'id'. - * - type: required. - * - * In most cases, Field entities are created via - * entity_create('field_entity', $values)), where $values is the same - * parameter as in this constructor. - * - * @see entity_create() - * - * @ingroup field_crud - */ - public function __construct(array $values, $entity_type = 'field_entity') { - // Check required properties. - if (empty($values['type'])) { - throw new FieldException('Attempt to create a field with no type.'); - } - // Temporary BC layer: accept both 'id' and 'field_name'. - // @todo $field_name and the handling for it will be removed in - // http://drupal.org/node/1953408. - if (empty($values['field_name']) && empty($values['id'])) { - throw new FieldException('Attempt to create an unnamed field.'); - } - if (empty($values['id'])) { - $values['id'] = $values['field_name']; - unset($values['field_name']); - } - if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['id'])) { - throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character'); - } - - parent::__construct($values, $entity_type); - } - - /** - * {@inheritdoc} - */ - public function getExportProperties() { - $names = array( - 'id', - 'uuid', - 'status', - 'langcode', - 'type', - 'settings', - 'module', - 'active', - 'entity_types', - 'storage', - 'locked', - 'cardinality', - 'translatable', - 'indexes', - ); - $properties = array(); - foreach ($names as $name) { - $properties[$name] = $this->get($name); - } - return $properties; - } - - /** - * Overrides \Drupal\Core\Entity\Entity::save(). - * - * @return int - * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. - * - * @throws \Drupal\field\FieldException - * If the field definition is invalid. - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - public function save() { - // Clear the derived data about the field. - unset($this->schema, $this->storageDetails); - - if ($this->isNew()) { - return $this->saveNew(); - } - else { - return $this->saveUpdated(); - } - } - - /** - * Saves a new field definition. - * - * @return int - * SAVED_NEW if the definition was saved. - * - * @throws \Drupal\field\FieldException - * If the field definition is invalid. - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - protected function saveNew() { - $module_handler = \Drupal::moduleHandler(); - $entity_manager = \Drupal::entityManager(); - $storage_controller = $entity_manager->getStorageController($this->entityType); - - // Field name cannot be longer than Field::ID_MAX_LENGTH characters. We - // use drupal_strlen() because the DB layer assumes that column widths - // are given in characters rather than bytes. - if (drupal_strlen($this->id) > static::ID_MAX_LENGTH) { - throw new FieldException(format_string( - 'Attempt to create a field with an ID longer than @max characters: %id', array( - '@max' => static::ID_MAX_LENGTH, - '%id' => $this->id, - ) - )); - } - - // Ensure the field name is unique (we do not care about deleted fields). - if ($prior_field = $storage_controller->load($this->id)) { - $message = $prior_field->active ? - 'Attempt to create field name %id which already exists and is active.' : - 'Attempt to create field name %id which already exists, although it is inactive.'; - throw new FieldException(format_string($message, array('%id' => $this->id))); - } - - // Disallow reserved field names. This can't prevent all field name - // collisions with existing entity properties, but some is better than - // none. - foreach ($entity_manager->getDefinitions() as $type => $info) { - if (in_array($this->id, $info['entity_keys'])) { - throw new FieldException(format_string('Attempt to create field %id which is reserved by entity type %type.', array('%id' => $this->id, '%type' => $type))); - } - } - - // Check that the field type is known. - $field_type = field_info_field_types($this->type); - if (!$field_type) { - throw new FieldException(format_string('Attempt to create a field of unknown type %type.', array('%type' => $this->type))); - } - $this->module = $field_type['module']; - $this->active = TRUE; - - // Make sure all settings are present, so that a complete field - // definition is passed to the various hooks and written to config. - $this->settings += $field_type['settings']; - - // Provide default storage. - $this->storage += array( - 'type' => variable_get('field_storage_default', 'field_sql_storage'), - 'settings' => array(), - ); - // Check that the storage type is known. - $storage_type = field_info_storage_types($this->storage['type']); - if (!$storage_type) { - throw new FieldException(format_string('Attempt to create a field with unknown storage type %type.', array('%type' => $this->storage['type']))); - } - $this->storage['module'] = $storage_type['module']; - $this->storage['active'] = TRUE; - // Provide default storage settings. - $this->storage['settings'] += $storage_type['settings']; - - // Invoke the storage backend's hook_field_storage_create_field(). - $module_handler->invoke($this->storage['module'], 'field_storage_create_field', array($this)); - - // Save the configuration. - $result = parent::save(); - field_cache_clear(); - - return $result; - } - - /** - * Saves an updated field definition. - * - * @return int - * SAVED_UPDATED if the definition was saved. - * - * @throws \Drupal\field\FieldException - * If the field definition is invalid. - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - protected function saveUpdated() { - $module_handler = \Drupal::moduleHandler(); - $storage_controller = \Drupal::entityManager()->getStorageController($this->entityType); - - $original = $storage_controller->loadUnchanged($this->id()); - $this->original = $original; - - // Some updates are always disallowed. - if ($this->type != $original->type) { - throw new FieldException("Cannot change an existing field's type."); - } - if ($this->entity_types != $original->entity_types) { - throw new FieldException("Cannot change an existing field's entity_types property."); - } - if ($this->storage['type'] != $original->storage['type']) { - throw new FieldException("Cannot change an existing field's storage type."); - } - - // Make sure all settings are present, so that a complete field definition - // is saved. This allows calling code to perform partial updates on field - // objects. - $this->settings += $original->settings; - - // See if any module forbids the update by throwing an exception. This - // invokes hook_field_update_forbid(). - $module_handler->invokeAll('field_update_forbid', array($this, $original)); - - // Tell the storage engine to update the field by invoking the - // hook_field_storage_update_field(). The storage engine can reject the - // definition update as invalid by raising an exception, which stops - // execution before the definition is written to config. - $module_handler->invoke($this->storage['module'], 'field_storage_update_field', array($this, $original)); - - // Save the configuration. - $result = parent::save(); - field_cache_clear(); - - return $result; - } - - /** - * {@inheritdoc} - */ - public function delete() { - if (!$this->deleted) { - $module_handler = \Drupal::moduleHandler(); - $instance_controller = \Drupal::entityManager()->getStorageController('field_instance'); - $state = \Drupal::state(); - - // Delete all non-deleted instances. - $instance_ids = array(); - foreach ($this->getBundles() as $entity_type => $bundles) { - foreach ($bundles as $bundle) { - $instance_ids[] = "$entity_type.$bundle.$this->id"; - } - } - foreach ($instance_controller->loadMultiple($instance_ids) as $instance) { - // By default, FieldInstance::delete() will automatically try to delete - // a field definition when it is deleting the last instance of the - // field. Since the whole field is being deleted here, pass FALSE as - // the $field_cleanup parameter to prevent a loop. - $instance->delete(FALSE); - } - - // Mark field data for deletion by invoking - // hook_field_storage_delete_field(). - $module_handler->invoke($this->storage['module'], 'field_storage_delete_field', array($this)); - - // Delete the configuration of this field and save the field configuration - // in the key_value table so we can use it later during - // field_purge_batch(). This makes sure a new field can be created - // immediately with the same name. - $deleted_fields = $state->get('field.field.deleted') ?: array(); - $config = $this->getExportProperties(); - $config['deleted'] = TRUE; - $deleted_fields[$this->uuid] = $config; - $state->set('field.field.deleted', $deleted_fields); - - parent::delete(); - - // Clear the cache. - field_cache_clear(); - } - } - - /** - * {@inheritdoc} - */ - public function getSchema() { - if (!isset($this->schema)) { - // Get the schema from the field item class. - $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type); - $class = $definition['class']; - $schema = $class::schema($this); - // Fill in default values for optional entries. - $schema += array('indexes' => array(), 'foreign keys' => array()); - - // Check that the schema does not include forbidden column names. - if (array_intersect(array_keys($schema['columns']), static::getReservedColumns())) { - throw new FieldException('Illegal field type columns.'); - } - - // Merge custom indexes with those specified by the field type. Custom - // indexes prevail. - $schema['indexes'] = $this->indexes + $schema['indexes']; - - $this->schema = $schema; - } - - return $this->schema; - } - - /** - * {@inheritdoc} - */ - public function getColumns() { - $schema = $this->getSchema(); - // A typical use case for the method is to iterate on the columns, while - // some other use cases rely on identifying the first column with the key() - // function. Since the schema is persisted in the Field object, we take care - // of resetting the array pointer so that the former does not interfere with - // the latter. - reset($schema['columns']); - return $schema['columns']; - } - - /** - * {@inheritdoc} - */ - public function getStorageDetails() { - if (!isset($this->storageDetails)) { - $module_handler = \Drupal::moduleHandler(); - - // Collect the storage details from the storage backend, and let other - // modules alter it. This invokes hook_field_storage_details() and - // hook_field_storage_details_alter(). - $details = (array) $module_handler->invoke($this->storage['module'], 'field_storage_details', array($this)); - $module_handler->alter('field_storage_details', $details, $this); - - $this->storageDetails = $details; - } - - return $this->storageDetails; - } - - /** - * {@inheritdoc} - */ - public function getBundles() { - if (empty($this->deleted)) { - $map = field_info_field_map(); - if (isset($map[$this->id]['bundles'])) { - return $map[$this->id]['bundles']; - } - } - return array(); - } - - /** - * {@inheritdoc} - */ - public function getFieldName() { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function getFieldType() { - return $this->type; - } - - /** - * {@inheritdoc} - */ - public function getFieldSettings() { - // @todo field_info_field_types() calls _field_info_collate_types() which - // maintains its own static cache. However, do some CPU and memory - // profiling to see if it's worth statically caching $field_type_info, or - // the default field and instance settings, within $this. - $field_type_info = field_info_field_types($this->type); - - $settings = $field_type_info['instance_settings'] + $this->settings + $field_type_info['settings']; - return $settings; - } - - /** - * {@inheritdoc} - */ - public function getFieldSetting($setting_name) { - // @todo See getFieldSettings() about potentially statically caching this. - $field_type_info = field_info_field_types($this->type); - - // We assume here that consecutive array_key_exists() is more efficient than - // calling getFieldSettings() when all we need is a single setting. - if (array_key_exists($setting_name, $field_type_info['instance_settings'])) { - return $field_type_info['instance_settings'][$setting_name]; - } - elseif (array_key_exists($setting_name, $this->settings)) { - return $this->settings[$setting_name]; - } - else { - return $field_type_info['settings'][$setting_name]; - } - } - - /** - * {@inheritdoc} - */ - public function getFieldPropertyNames() { - $schema = $this->getSchema(); - return array_keys($schema['columns']); - } - - /** - * {@inheritdoc} - */ - public function isFieldTranslatable() { - return $this->translatable; - } - - /** - * {@inheritdoc} - */ - public function getFieldLabel() { - return $this->label(); - } - - /** - * {@inheritdoc} - */ - public function getFieldDescription() { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getFieldCardinality() { - return $this->cardinality; - } - - /** - * {@inheritdoc} - */ - public function isFieldRequired() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset) { - return isset($this->{$offset}) || in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details')); - } - - /** - * {@inheritdoc} - */ - public function &offsetGet($offset) { - switch ($offset) { - case 'id': - return $this->uuid; - - case 'field_name': - return $this->id; - - case 'columns': - $this->getSchema(); - return $this->schema['columns']; - - case 'foreign keys': - $this->getSchema(); - return $this->schema['foreign keys']; - - case 'bundles': - $bundles = $this->getBundles(); - return $bundles; - - case 'storage_details': - $this->getStorageDetails(); - return $this->storageDetails; - } - - return $this->{$offset}; - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) { - if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { - $this->{$offset} = $value; - } - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) { - if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { - unset($this->{$offset}); - } - } - - /** - * {@inheritdoc} - */ - public function serialize() { - // Only store the definition, not external objects or derived data. - return serialize($this->getExportProperties()); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) { - $this->__construct(unserialize($serialized)); - } - - /** - * A list of columns that can not be used as field type columns. - * - * @return array - */ - public static function getReservedColumns() { - return array('deleted'); - } - - /** - * Determines whether a field has any data. - * - * @return - * TRUE if the field has data for any entity; FALSE otherwise. - */ - public function hasData() { - $storage_details = $this->getSchema(); - $columns = array_keys($storage_details['columns']); - $factory = \Drupal::service('entity.query'); - foreach ($this->getBundles() as $entity_type => $bundle) { - // Entity Query throws an exception if there is no base table. - $entity_info = \Drupal::entityManager()->getDefinition($entity_type); - if (!isset($entity_info['base_table'])) { - continue; - } - $query = $factory->get($entity_type); - $group = $query->orConditionGroup(); - foreach ($columns as $column) { - $group->exists($this->id() . '.' . $column); - } - $result = $query - ->condition($group) - ->count() - ->accessCheck(FALSE) - ->range(0, 1) - ->execute(); - if ($result) { - return TRUE; - } - } - - return FALSE; - } -} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldConfig.php new file mode 100644 index 0000000..eea13c6 --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldConfig.php @@ -0,0 +1,765 @@ +$field_id}. The maximum length is + * FieldConfig:ID_MAX_LENGTH. + * + * Example: body, field_main_image. + * + * @var string + */ + public $id; + + /** + * The field UUID. + * + * This is assigned automatically when the field is created. + * + * @var string + */ + public $uuid; + + /** + * The field type. + * + * Example: text, number_integer. + * + * @var string + */ + public $type; + + /** + * The name of the module that provides the field type. + * + * @var string + */ + public $module; + + /** + * Flag indicating whether the field type module is enabled. + * + * @var bool + */ + public $active; + + /** + * FieldConfig-type specific settings. + * + * An array of key/value pairs, The keys and default values are defined by the + * field type. + * + * @var array + */ + public $settings = array(); + + /** + * The field cardinality. + * + * The maximum number of values the field can hold. Possible values are + * positive integers or FIELD_CARDINALITY_UNLIMITED. Defaults to 1. + * + * @var integer + */ + public $cardinality = 1; + + /** + * Flag indicating whether the field is translatable. + * + * Defaults to FALSE. + * + * @var bool + */ + public $translatable = FALSE; + + /** + * The entity types on which the field is allowed to have instances. + * + * If empty or not specified, the field is allowed to have instances in any + * entity type. + * + * @var array + */ + public $entity_types = array(); + + /** + * Flag indicating whether the field is available for editing. + * + * If TRUE, some actions not available though the UI (but are still possible + * through direct API manipulation): + * - field settings cannot be changed, + * - new instances cannot be created + * - existing instances cannot be deleted. + * Defaults to FALSE. + * + * @var bool + */ + public $locked = FALSE; + + /** + * The field storage definition. + * + * An array of key/value pairs identifying the storage backend to use for the + * field: + * - type: (string) The storage backend used by the field. Storage backends + * are defined by modules that implement hook_field_storage_info(). + * - settings: (array) A sub-array of key/value pairs of settings. The keys + * and default values are defined by the storage backend in the 'settings' + * entry of hook_field_storage_info(). + * - module: (string, read-only) The name of the module that implements the + * storage backend. + * - active: (integer, read-only) TRUE if the module that implements the + * storage backend is currently enabled, FALSE otherwise. + * + * @var array + */ + public $storage = array(); + + /** + * The custom storage indexes for the field data storage. + * + * This set of indexes is merged with the "default" indexes specified by the + * field type in hook_field_schema() to determine the actual set of indexes + * that get created. + * + * The indexes are defined using the same definition format as Schema API + * index specifications. Only columns that are part of the field schema, as + * defined by the field type in hook_field_schema(), are allowed. + * + * Some storage backends might not support indexes, and discard that + * information. + * + * @var array + */ + public $indexes = array(); + + /** + * Flag indicating whether the field is deleted. + * + * The delete() method marks the field as "deleted" and removes the + * corresponding entry from the config storage, but keeps its definition in + * the state storage while field data is purged by a separate + * garbage-collection process. + * + * Deleted fields stay out of the regular entity lifecycle (notably, their + * values are not populated in loaded entities, and are not saved back). + * + * @var bool + */ + public $deleted = FALSE; + + /** + * The field schema. + * + * @var array + */ + protected $schema; + + /** + * The storage information for the field. + * + * @var array + */ + protected $storageDetails; + + /** + * The original field. + * + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig + */ + public $original = NULL; + + /** + * Constructs a FieldConfig object. + * + * @param array $values + * An array of field properties, keyed by property name. Most array + * elements will be used to set the corresponding properties on the class; + * see the class property documentation for details. Some array elements + * have special meanings and a few are required. Special elements are: + * - id: required. As a temporary Backwards Compatibility layer right now, + * a 'field_name' property can be accepted in place of 'id'. + * - type: required. + * + * In most cases, FieldConfig entities are created via + * entity_create('field_config', $values)), where $values is the same + * parameter as in this constructor. + * + * @see entity_create() + * + * @ingroup field_crud + */ + public function __construct(array $values, $entity_type = 'field_config') { + // Check required properties. + if (empty($values['type'])) { + throw new FieldException('Attempt to create a field with no type.'); + } + // Temporary BC layer: accept both 'id' and 'field_name'. + // @todo $field_name and the handling for it will be removed in + // http://drupal.org/node/1953408. + if (empty($values['field_name']) && empty($values['id'])) { + throw new FieldException('Attempt to create an unnamed field.'); + } + if (empty($values['id'])) { + $values['id'] = $values['field_name']; + unset($values['field_name']); + } + if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['id'])) { + throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character'); + } + + parent::__construct($values, $entity_type); + } + + /** + * {@inheritdoc} + */ + public function getExportProperties() { + $names = array( + 'id', + 'uuid', + 'status', + 'langcode', + 'type', + 'settings', + 'module', + 'active', + 'entity_types', + 'storage', + 'locked', + 'cardinality', + 'translatable', + 'indexes', + ); + $properties = array(); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + return $properties; + } + + /** + * Overrides \Drupal\Core\Entity\Entity::save(). + * + * @return int + * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. + * + * @throws \Drupal\field\FieldException + * If the field definition is invalid. + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + public function save() { + // Clear the derived data about the field. + unset($this->schema, $this->storageDetails); + + if ($this->isNew()) { + return $this->saveNew(); + } + else { + return $this->saveUpdated(); + } + } + + /** + * Saves a new field definition. + * + * @return int + * SAVED_NEW if the definition was saved. + * + * @throws \Drupal\field\FieldException + * If the field definition is invalid. + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + protected function saveNew() { + $module_handler = \Drupal::moduleHandler(); + $entity_manager = \Drupal::entityManager(); + $storage_controller = $entity_manager->getStorageController($this->entityType); + + // FieldConfig name cannot be longer than FieldConfig::ID_MAX_LENGTH characters. We + // use drupal_strlen() because the DB layer assumes that column widths + // are given in characters rather than bytes. + if (drupal_strlen($this->id) > static::ID_MAX_LENGTH) { + throw new FieldException(format_string( + 'Attempt to create a field with an ID longer than @max characters: %id', array( + '@max' => static::ID_MAX_LENGTH, + '%id' => $this->id, + ) + )); + } + + // Ensure the field name is unique (we do not care about deleted fields). + if ($prior_field = $storage_controller->load($this->id)) { + $message = $prior_field->active ? + 'Attempt to create field name %id which already exists and is active.' : + 'Attempt to create field name %id which already exists, although it is inactive.'; + throw new FieldException(format_string($message, array('%id' => $this->id))); + } + + // Disallow reserved field names. This can't prevent all field name + // collisions with existing entity properties, but some is better than + // none. + foreach ($entity_manager->getDefinitions() as $type => $info) { + if (in_array($this->id, $info['entity_keys'])) { + throw new FieldException(format_string('Attempt to create field %id which is reserved by entity type %type.', array('%id' => $this->id, '%type' => $type))); + } + } + + // Check that the field type is known. + $field_type = field_info_field_types($this->type); + if (!$field_type) { + throw new FieldException(format_string('Attempt to create a field of unknown type %type.', array('%type' => $this->type))); + } + $this->module = $field_type['module']; + $this->active = TRUE; + + // Make sure all settings are present, so that a complete field + // definition is passed to the various hooks and written to config. + $this->settings += $field_type['settings']; + + // Provide default storage. + $this->storage += array( + 'type' => variable_get('field_storage_default', 'field_sql_storage'), + 'settings' => array(), + ); + // Check that the storage type is known. + $storage_type = field_info_storage_types($this->storage['type']); + if (!$storage_type) { + throw new FieldException(format_string('Attempt to create a field with unknown storage type %type.', array('%type' => $this->storage['type']))); + } + $this->storage['module'] = $storage_type['module']; + $this->storage['active'] = TRUE; + // Provide default storage settings. + $this->storage['settings'] += $storage_type['settings']; + + // Invoke the storage backend's hook_field_storage_create_field(). + $module_handler->invoke($this->storage['module'], 'field_storage_create_field', array($this)); + + // Save the configuration. + $result = parent::save(); + field_cache_clear(); + + return $result; + } + + /** + * Saves an updated field definition. + * + * @return int + * SAVED_UPDATED if the definition was saved. + * + * @throws \Drupal\field\FieldException + * If the field definition is invalid. + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + protected function saveUpdated() { + $module_handler = \Drupal::moduleHandler(); + $storage_controller = \Drupal::entityManager()->getStorageController($this->entityType); + + $original = $storage_controller->loadUnchanged($this->id()); + $this->original = $original; + + // Some updates are always disallowed. + if ($this->type != $original->type) { + throw new FieldException("Cannot change an existing field's type."); + } + if ($this->entity_types != $original->entity_types) { + throw new FieldException("Cannot change an existing field's entity_types property."); + } + if ($this->storage['type'] != $original->storage['type']) { + throw new FieldException("Cannot change an existing field's storage type."); + } + + // Make sure all settings are present, so that a complete field definition + // is saved. This allows calling code to perform partial updates on field + // objects. + $this->settings += $original->settings; + + // See if any module forbids the update by throwing an exception. This + // invokes hook_field_update_forbid(). + $module_handler->invokeAll('field_update_forbid', array($this, $original)); + + // Tell the storage engine to update the field by invoking the + // hook_field_storage_update_field(). The storage engine can reject the + // definition update as invalid by raising an exception, which stops + // execution before the definition is written to config. + $module_handler->invoke($this->storage['module'], 'field_storage_update_field', array($this, $original)); + + // Save the configuration. + $result = parent::save(); + field_cache_clear(); + + return $result; + } + + /** + * {@inheritdoc} + */ + public function delete() { + if (!$this->deleted) { + $module_handler = \Drupal::moduleHandler(); + $instance_controller = \Drupal::entityManager()->getStorageController('field_instance_config'); + $state = \Drupal::state(); + + // Delete all non-deleted instances. + $instance_ids = array(); + foreach ($this->getBundles() as $entity_type => $bundles) { + foreach ($bundles as $bundle) { + $instance_ids[] = "$entity_type.$bundle.$this->id"; + } + } + foreach ($instance_controller->loadMultiple($instance_ids) as $instance) { + // By default, FieldInstanceConfig::delete() will automatically try to delete + // a field definition when it is deleting the last instance of the + // field. Since the whole field is being deleted here, pass FALSE as + // the $field_cleanup parameter to prevent a loop. + $instance->delete(FALSE); + } + + // Mark field data for deletion by invoking + // hook_field_storage_delete_field(). + $module_handler->invoke($this->storage['module'], 'field_storage_delete_field', array($this)); + + // Delete the configuration of this field and save the field configuration + // in the key_value table so we can use it later during + // field_purge_batch(). This makes sure a new field can be created + // immediately with the same name. + $deleted_fields = $state->get('field.field.deleted') ?: array(); + $config = $this->getExportProperties(); + $config['deleted'] = TRUE; + $deleted_fields[$this->uuid] = $config; + $state->set('field.field.deleted', $deleted_fields); + + parent::delete(); + + // Clear the cache. + field_cache_clear(); + } + } + + /** + * {@inheritdoc} + */ + public function getSchema() { + if (!isset($this->schema)) { + // Get the schema from the field item class. + $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type); + $class = $definition['class']; + $schema = $class::schema($this); + // Fill in default values for optional entries. + $schema += array('indexes' => array(), 'foreign keys' => array()); + + // Check that the schema does not include forbidden column names. + if (array_intersect(array_keys($schema['columns']), static::getReservedColumns())) { + throw new FieldException('Illegal field type columns.'); + } + + // Merge custom indexes with those specified by the field type. Custom + // indexes prevail. + $schema['indexes'] = $this->indexes + $schema['indexes']; + + $this->schema = $schema; + } + + return $this->schema; + } + + /** + * {@inheritdoc} + */ + public function getColumns() { + $schema = $this->getSchema(); + // A typical use case for the method is to iterate on the columns, while + // some other use cases rely on identifying the first column with the key() + // function. Since the schema is persisted in the FieldConfig object, we take care + // of resetting the array pointer so that the former does not interfere with + // the latter. + reset($schema['columns']); + return $schema['columns']; + } + + /** + * {@inheritdoc} + */ + public function getStorageDetails() { + if (!isset($this->storageDetails)) { + $module_handler = \Drupal::moduleHandler(); + + // Collect the storage details from the storage backend, and let other + // modules alter it. This invokes hook_field_storage_details() and + // hook_field_storage_details_alter(). + $details = (array) $module_handler->invoke($this->storage['module'], 'field_storage_details', array($this)); + $module_handler->alter('field_storage_details', $details, $this); + + $this->storageDetails = $details; + } + + return $this->storageDetails; + } + + /** + * {@inheritdoc} + */ + public function getBundles() { + if (empty($this->deleted)) { + $map = field_info_field_map(); + if (isset($map[$this->id]['bundles'])) { + return $map[$this->id]['bundles']; + } + } + return array(); + } + + /** + * {@inheritdoc} + */ + public function getFieldName() { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function getFieldType() { + return $this->type; + } + + /** + * {@inheritdoc} + */ + public function getFieldSettings() { + // @todo field_info_field_types() calls _field_info_collate_types() which + // maintains its own static cache. However, do some CPU and memory + // profiling to see if it's worth statically caching $field_type_info, or + // the default field and instance settings, within $this. + $field_type_info = field_info_field_types($this->type); + + $settings = $field_type_info['instance_settings'] + $this->settings + $field_type_info['settings']; + return $settings; + } + + /** + * {@inheritdoc} + */ + public function getFieldSetting($setting_name) { + // @todo See getFieldSettings() about potentially statically caching this. + $field_type_info = field_info_field_types($this->type); + + // We assume here that consecutive array_key_exists() is more efficient than + // calling getFieldSettings() when all we need is a single setting. + if (array_key_exists($setting_name, $field_type_info['instance_settings'])) { + return $field_type_info['instance_settings'][$setting_name]; + } + elseif (array_key_exists($setting_name, $this->settings)) { + return $this->settings[$setting_name]; + } + else { + return $field_type_info['settings'][$setting_name]; + } + } + + /** + * {@inheritdoc} + */ + public function getFieldPropertyNames() { + $schema = $this->getSchema(); + return array_keys($schema['columns']); + } + + /** + * {@inheritdoc} + */ + public function isFieldTranslatable() { + return $this->translatable; + } + + /** + * {@inheritdoc} + */ + public function getFieldLabel() { + return $this->label(); + } + + /** + * {@inheritdoc} + */ + public function getFieldDescription() { + return ''; + } + + /** + * {@inheritdoc} + */ + public function getFieldCardinality() { + return $this->cardinality; + } + + /** + * {@inheritdoc} + */ + public function isFieldRequired() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function offsetExists($offset) { + return isset($this->{$offset}) || in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details')); + } + + /** + * {@inheritdoc} + */ + public function &offsetGet($offset) { + switch ($offset) { + case 'id': + return $this->uuid; + + case 'field_name': + return $this->id; + + case 'columns': + $this->getSchema(); + return $this->schema['columns']; + + case 'foreign keys': + $this->getSchema(); + return $this->schema['foreign keys']; + + case 'bundles': + $bundles = $this->getBundles(); + return $bundles; + + case 'storage_details': + $this->getStorageDetails(); + return $this->storageDetails; + } + + return $this->{$offset}; + } + + /** + * {@inheritdoc} + */ + public function offsetSet($offset, $value) { + if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { + $this->{$offset} = $value; + } + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($offset) { + if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { + unset($this->{$offset}); + } + } + + /** + * {@inheritdoc} + */ + public function serialize() { + // Only store the definition, not external objects or derived data. + return serialize($this->getExportProperties()); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + $this->__construct(unserialize($serialized)); + } + + /** + * A list of columns that can not be used as field type columns. + * + * @return array + */ + public static function getReservedColumns() { + return array('deleted'); + } + + /** + * Determines whether a field has any data. + * + * @return + * TRUE if the field has data for any entity; FALSE otherwise. + */ + public function hasData() { + $storage_details = $this->getSchema(); + $columns = array_keys($storage_details['columns']); + $factory = \Drupal::service('entity.query'); + foreach ($this->getBundles() as $entity_type => $bundle) { + // Entity Query throws an exception if there is no base table. + $entity_info = \Drupal::entityManager()->getDefinition($entity_type); + if (!isset($entity_info['base_table'])) { + continue; + } + $query = $factory->get($entity_type); + $group = $query->orConditionGroup(); + foreach ($columns as $column) { + $group->exists($this->id() . '.' . $column); + } + $result = $query + ->condition($group) + ->count() + ->accessCheck(FALSE) + ->range(0, 1) + ->execute(); + if ($result) { + return TRUE; + } + } + + return FALSE; + } +} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php deleted file mode 100644 index cbfb636..0000000 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php +++ /dev/null @@ -1,632 +0,0 @@ -save()); the default value is - * added if the $entity object provides no explicit entry (actual values or - * "the field is empty") for the field. - * - * The default value is expressed as a numerically indexed array of items, - * each item being an array of key/value pairs matching the set of 'columns' - * defined by the "field schema" for the field type, as exposed in - * hook_field_schema(). If the number of items exceeds the cardinality of the - * field, extraneous items will be ignored. - * - * This property is overlooked if the $default_value_function is non-empty. - * - * Example for a number_integer field: - * @code - * array( - * array('value' => 1), - * array('value' => 2), - * ) - * @endcode - * - * @var array - */ - public $default_value = array(); - - /** - * The name of a callback function that returns default values. - * - * The function will be called with the following arguments: - * - \Drupal\Core\Entity\EntityInterface $entity - * The entity being created. - * - \Drupal\field\Plugin\Core\Entity\Field $field - * The field object. - * - \Drupal\field\Plugin\Core\Entity\FieldInstance $instance - * The field instance object. - * - string $langcode - * The language of the entity being created. - * It should return an array of default values, in the same format as the - * $default_value property. - * - * This property takes precedence on the list of fixed values specified in the - * $default_value property. - * - * @var string - */ - public $default_value_function = ''; - - /** - * Flag indicating whether the instance is deleted. - * - * The delete() method marks the instance as "deleted" and removes the - * corresponding entry from the config storage, but keeps its definition in - * the state storage while field data is purged by a separate - * garbage-collection process. - * - * Deleted instances stay out of the regular entity lifecycle (notably, their - * values are not populated in loaded entities, and are not saved back). - * - * @var bool - */ - public $deleted = FALSE; - - /** - * The field ConfigEntity object corresponding to $field_uuid. - * - * @var \Drupal\field\Plugin\Core\Entity\Field - */ - protected $field; - - /** - * Flag indicating whether the bundle name can be renamed or not. - * - * @var bool - */ - protected $bundle_rename_allowed = FALSE; - - /** - * The original instance. - * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance - */ - public $original = NULL; - - /** - * Constructs a FieldInstance object. - * - * @param array $values - * An array of field instance properties, keyed by property name. Most - * array elements will be used to set the corresponding properties on the - * class; see the class property documentation for details. Some array - * elements have special meanings and a few are required; these special - * elements are: - * - field_name: optional. The name of the field this is an instance of. - * - field_uuid: optional. Either field_uuid or field_name is required - * to build field instance. field_name will gain higher priority. - * If field_name is not provided, field_uuid will be checked then. - * - entity_type: required. - * - bundle: required. - * - * In most cases, Field instance entities are created via - * entity_create('field_instance', $values)), where $values is the same - * parameter as in this constructor. - * - * @see entity_create() - * - * @ingroup field_crud - */ - public function __construct(array $values, $entity_type = 'field_instance') { - // Accept incoming 'field_name' instead of 'field_uuid', for easier DX on - // creation of new instances. - if (isset($values['field_name']) && !isset($values['field_uuid'])) { - $field = field_info_field($values['field_name']); - if (!$field) { - throw new FieldException(format_string('Attempt to create an instance of unknown, disabled, or deleted field @field_id', array('@field_id' => $values['field_name']))); - } - $values['field_uuid'] = $field->uuid; - } - elseif (isset($values['field_uuid'])) { - $field = field_info_field_by_id($values['field_uuid']); - // field_info_field_by_id() will not find the field if it is inactive. - if (!$field) { - $field = current(field_read_fields(array('uuid' => $values['field_uuid']), array('include_inactive' => TRUE, 'include_deleted' => TRUE))); - } - if (!$field) { - throw new FieldException(format_string('Attempt to create an instance of unknown field @uuid', array('@uuid' => $values['field_uuid']))); - } - } - else { - throw new FieldException('Attempt to create an instance of an unspecified field.'); - } - - // At this point, we should have a 'field_uuid' and a Field. Ditch the - // 'field_name' property if it was provided, and assign the $field property. - unset($values['field_name']); - $this->field = $field; - - // Discard the 'field_type' entry that is added in config records to ease - // schema generation. See getExportProperties(). - unset($values['field_type']); - - // Check required properties. - if (empty($values['entity_type'])) { - throw new FieldException(format_string('Attempt to create an instance of field @field_id without an entity type.', array('@field_id' => $this->field->id))); - } - if (empty($values['bundle'])) { - throw new FieldException(format_string('Attempt to create an instance of field @field_id without a bundle.', array('@field_id' => $this->field->id))); - } - - // 'Label' defaults to the field ID (mostly useful for field instances - // created in tests). - $values += array( - 'label' => $this->field->id, - ); - parent::__construct($values, $entity_type); - } - - /** - * {@inheritdoc} - */ - public function id() { - return $this->entity_type . '.' . $this->bundle . '.' . $this->field->id; - } - - /** - * {@inheritdoc} - */ - public function getExportProperties() { - $names = array( - 'id', - 'uuid', - 'status', - 'langcode', - 'field_uuid', - 'entity_type', - 'bundle', - 'label', - 'description', - 'required', - 'default_value', - 'default_value_function', - 'settings', - ); - $properties = array(); - foreach ($names as $name) { - $properties[$name] = $this->get($name); - } - - // Additionally, include the field type, that is needed to be able to - // generate the field-type-dependant parts of the config schema. - $properties['field_type'] = $this->field->type; - - return $properties; - } - - /** - * Overrides \Drupal\Core\Entity\Entity::save(). - * - * @return - * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. - * - * @throws \Drupal\field\FieldException - * If the field instance definition is invalid. - * - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - public function save() { - if ($this->isNew()) { - return $this->saveNew(); - } - else { - return $this->saveUpdated(); - } - } - - /** - * Saves a new field instance definition. - * - * @return - * SAVED_NEW if the definition was saved. - * - * @throws \Drupal\field\FieldException - * If the field instance definition is invalid. - * - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - protected function saveNew() { - $module_handler = \Drupal::moduleHandler(); - $instance_controller = \Drupal::entityManager()->getStorageController($this->entityType); - - // Check that the field can be attached to this entity type. - if (!empty($this->field->entity_types) && !in_array($this->entity_type, $this->field->entity_types)) { - throw new FieldException(format_string('Attempt to create an instance of field @field_id on forbidden entity type @entity_type.', array('@field_id' => $this->field->id, '@entity_type' => $this->entity_type))); - } - - // Assign the ID. - $this->id = $this->id(); - - // Ensure the field instance is unique within the bundle. - if ($prior_instance = $instance_controller->load($this->id)) { - throw new FieldException(format_string('Attempt to create an instance of field @field_id on bundle @bundle that already has an instance of that field.', array('@field_id' => $this->field->id, '@bundle' => $this->bundle))); - } - - // Set the field UUID. - $this->field_uuid = $this->field->uuid; - - // Ensure default values are present. - $this->prepareSave(); - - // Save the configuration. - $result = parent::save(); - field_cache_clear(); - - return $result; - } - - /** - * Saves an updated field instance definition. - * - * @return - * SAVED_UPDATED if the definition was saved. - * - * @throws \Drupal\field\FieldException - * If the field instance definition is invalid. - * - * @throws \Drupal\Core\Entity\EntityStorageException - * In case of failures at the configuration storage level. - */ - protected function saveUpdated() { - $module_handler = \Drupal::moduleHandler(); - $instance_controller = \Drupal::entityManager()->getStorageController($this->entityType); - - $original = $instance_controller->loadUnchanged($this->getOriginalID()); - $this->original = $original; - - // Some updates are always disallowed. - if ($this->entity_type != $original->entity_type) { - throw new FieldException("Cannot change an existing instance's entity_type."); - } - if ($this->bundle != $original->bundle && empty($this->bundle_rename_allowed)) { - throw new FieldException("Cannot change an existing instance's bundle."); - } - if ($this->field_uuid != $original->field_uuid) { - throw new FieldException("Cannot change an existing instance's field."); - } - - // Ensure default values are present. - $this->prepareSave(); - - // Save the configuration. - $result = parent::save(); - field_cache_clear(); - - return $result; - } - - /** - * Prepares the instance definition for saving. - */ - protected function prepareSave() { - $field_type_info = field_info_field_types($this->field->type); - - // Set the default instance settings. - $this->settings += $field_type_info['instance_settings']; - } - - /** - * Overrides \Drupal\Core\Entity\Entity::delete(). - * - * @param bool $field_cleanup - * (optional) 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. - */ - public function delete($field_cleanup = TRUE) { - if (!$this->deleted) { - $module_handler = \Drupal::moduleHandler(); - $state = \Drupal::state(); - - // Delete the configuration of this instance and save the configuration - // in the key_value table so we can use it later during - // field_purge_batch(). - $deleted_instances = $state->get('field.instance.deleted') ?: array(); - $config = $this->getExportProperties(); - $config['deleted'] = TRUE; - $deleted_instances[$this->uuid] = $config; - $state->set('field.instance.deleted', $deleted_instances); - - parent::delete(); - - // Clear the cache. - field_cache_clear(); - - // Mark instance data for deletion by invoking - // hook_field_storage_delete_instance(). - $module_handler->invoke($this->field->storage['module'], 'field_storage_delete_instance', array($this)); - - // Remove the instance from the entity form displays. - if ($form_display = entity_load('entity_form_display', $this->entity_type . '.' . $this->bundle . '.default')) { - $form_display->removeComponent($this->field->id())->save(); - } - - // Remove the instance from the entity displays. - $ids = array(); - $view_modes = array('default' => array()) + entity_get_view_modes($this->entity_type); - foreach (array_keys($view_modes) as $view_mode) { - $ids[] = $this->entity_type . '.' . $this->bundle . '.' . $view_mode; - } - foreach (entity_load_multiple('entity_display', $ids) as $display) { - $display->removeComponent($this->field->id())->save(); - } - - // Delete the field itself if we just deleted its last instance. - if ($field_cleanup && count($this->field->getBundles()) == 0) { - $this->field->delete(); - } - } - } - - /** - * {@inheritdoc} - */ - public function getField() { - return $this->field; - } - - /** - * {@inheritdoc} - */ - public function getFieldName() { - return $this->field->id; - } - - /** - * {@inheritdoc} - */ - public function getFieldType() { - return $this->field->type; - } - - /** - * {@inheritdoc} - */ - public function getFieldSettings() { - return $this->settings + $this->field->getFieldSettings(); - } - - /** - * {@inheritdoc} - */ - public function getFieldSetting($setting_name) { - if (array_key_exists($setting_name, $this->settings)) { - return $this->settings[$setting_name]; - } - else { - return $this->field->getFieldSetting($setting_name); - } - } - - /** - * {@inheritdoc} - */ - public function getFieldPropertyNames() { - $schema = $this->field->getSchema(); - return array_keys($schema['columns']); - } - - /** - * {@inheritdoc} - */ - public function isFieldTranslatable() { - return $this->field->translatable; - } - - /** - * {@inheritdoc} - */ - public function getFieldLabel() { - return $this->label(); - } - - /** - * {@inheritdoc} - */ - public function getFieldDescription() { - return $this->description; - } - - /** - * {@inheritdoc} - */ - public function getFieldCardinality() { - return $this->field->cardinality; - } - - /** - * {@inheritdoc} - */ - public function isFieldRequired() { - return $this->required; - } - - /** - * {@inheritdoc} - */ - public function allowBundleRename() { - $this->bundle_rename_allowed = TRUE; - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset) { - return (isset($this->{$offset}) || $offset == 'field_id' || $offset == 'field_name'); - } - - /** - * {@inheritdoc} - */ - public function &offsetGet($offset) { - if ($offset == 'field_id') { - return $this->field_uuid; - } - if ($offset == 'field_name') { - return $this->field->id; - } - return $this->{$offset}; - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) { - if ($offset == 'field_id') { - $offset = 'field_uuid'; - } - $this->{$offset} = $value; - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) { - if ($offset == 'field_id') { - $offset = 'field_uuid'; - } - unset($this->{$offset}); - } - - /** - * {@inheritdoc} - */ - public function serialize() { - // Only store the definition, not external objects or derived data. - return serialize($this->getExportProperties()); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) { - $this->__construct(unserialize($serialized)); - } - -} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstanceConfig.php new file mode 100644 index 0000000..3793070 --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstanceConfig.php @@ -0,0 +1,632 @@ +save()); the default value is + * added if the $entity object provides no explicit entry (actual values or + * "the field is empty") for the field. + * + * The default value is expressed as a numerically indexed array of items, + * each item being an array of key/value pairs matching the set of 'columns' + * defined by the "field schema" for the field type, as exposed in + * hook_field_schema(). If the number of items exceeds the cardinality of the + * field, extraneous items will be ignored. + * + * This property is overlooked if the $default_value_function is non-empty. + * + * Example for a number_integer field: + * @code + * array( + * array('value' => 1), + * array('value' => 2), + * ) + * @endcode + * + * @var array + */ + public $default_value = array(); + + /** + * The name of a callback function that returns default values. + * + * The function will be called with the following arguments: + * - \Drupal\Core\Entity\EntityInterface $entity + * The entity being created. + * - \Drupal\field\Plugin\Core\Entity\FieldConfig $field_config + * The field object. + * - \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config + * The field instance object. + * - string $langcode + * The language of the entity being created. + * It should return an array of default values, in the same format as the + * $default_value property. + * + * This property takes precedence on the list of fixed values specified in the + * $default_value property. + * + * @var string + */ + public $default_value_function = ''; + + /** + * Flag indicating whether the instance is deleted. + * + * The delete() method marks the instance as "deleted" and removes the + * corresponding entry from the config storage, but keeps its definition in + * the state storage while field data is purged by a separate + * garbage-collection process. + * + * Deleted instances stay out of the regular entity lifecycle (notably, their + * values are not populated in loaded entities, and are not saved back). + * + * @var bool + */ + public $deleted = FALSE; + + /** + * The field ConfigEntity object corresponding to $field_uuid. + * + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig + */ + protected $fieldConfig; + + /** + * Flag indicating whether the bundle name can be renamed or not. + * + * @var bool + */ + protected $bundle_rename_allowed = FALSE; + + /** + * The original instance. + * + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig + */ + public $original = NULL; + + /** + * Constructs a FieldInstanceConfig object. + * + * @param array $values + * An array of field instance properties, keyed by property name. Most + * array elements will be used to set the corresponding properties on the + * class; see the class property documentation for details. Some array + * elements have special meanings and a few are required; these special + * elements are: + * - field_name: optional. The name of the field this is an instance of. + * - field_uuid: optional. Either field_uuid or field_name is required + * to build field instance. field_name will gain higher priority. + * If field_name is not provided, field_uuid will be checked then. + * - entity_type: required. + * - bundle: required. + * + * In most cases, Field instance entities are created via + * entity_create('field_instance_config', $values)), where $values is the same + * parameter as in this constructor. + * + * @see entity_create() + * + * @ingroup field_crud + */ + public function __construct(array $values, $entity_type = 'field_instance_config') { + // Accept incoming 'field_name' instead of 'field_uuid', for easier DX on + // creation of new instances. + if (isset($values['field_name']) && !isset($values['field_uuid'])) { + $field = field_info_field($values['field_name']); + if (!$field) { + throw new FieldException(format_string('Attempt to create an instance of unknown, disabled, or deleted field @field_id', array('@field_id' => $values['field_name']))); + } + $values['field_uuid'] = $field->uuid; + } + elseif (isset($values['field_uuid'])) { + $field = field_info_field_by_id($values['field_uuid']); + // field_info_field_by_id() will not find the field if it is inactive. + if (!$field) { + $field = current(field_read_fields(array('uuid' => $values['field_uuid']), array('include_inactive' => TRUE, 'include_deleted' => TRUE))); + } + if (!$field) { + throw new FieldException(format_string('Attempt to create an instance of unknown field @uuid', array('@uuid' => $values['field_uuid']))); + } + } + else { + throw new FieldException('Attempt to create an instance of an unspecified field.'); + } + + // At this point, we should have a 'field_uuid' and a FieldConfig. Ditch the + // 'field_name' property if it was provided, and assign the $field property. + unset($values['field_name']); + $this->fieldConfig = $field; + + // Discard the 'field_type' entry that is added in config records to ease + // schema generation. See getExportProperties(). + unset($values['field_type']); + + // Check required properties. + if (empty($values['entity_type'])) { + throw new FieldException(format_string('Attempt to create an instance of field @field_id without an entity type.', array('@field_id' => $this->fieldConfig->id))); + } + if (empty($values['bundle'])) { + throw new FieldException(format_string('Attempt to create an instance of field @field_id without a bundle.', array('@field_id' => $this->fieldConfig->id))); + } + + // 'Label' defaults to the field ID (mostly useful for field instances + // created in tests). + $values += array( + 'label' => $this->fieldConfig->id, + ); + parent::__construct($values, $entity_type); + } + + /** + * {@inheritdoc} + */ + public function id() { + return $this->entity_type . '.' . $this->bundle . '.' . $this->fieldConfig->id; + } + + /** + * {@inheritdoc} + */ + public function getExportProperties() { + $names = array( + 'id', + 'uuid', + 'status', + 'langcode', + 'field_uuid', + 'entity_type', + 'bundle', + 'label', + 'description', + 'required', + 'default_value', + 'default_value_function', + 'settings', + ); + $properties = array(); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + + // Additionally, include the field type, that is needed to be able to + // generate the field-type-dependant parts of the config schema. + $properties['field_type'] = $this->fieldConfig->type; + + return $properties; + } + + /** + * Overrides \Drupal\Core\Entity\Entity::save(). + * + * @return + * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. + * + * @throws \Drupal\field\FieldException + * If the field instance definition is invalid. + * + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + public function save() { + if ($this->isNew()) { + return $this->saveNew(); + } + else { + return $this->saveUpdated(); + } + } + + /** + * Saves a new field instance definition. + * + * @return + * SAVED_NEW if the definition was saved. + * + * @throws \Drupal\field\FieldException + * If the field instance definition is invalid. + * + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + protected function saveNew() { + $module_handler = \Drupal::moduleHandler(); + $instance_controller = \Drupal::entityManager()->getStorageController($this->entityType); + + // Check that the field can be attached to this entity type. + if (!empty($this->fieldConfig->entity_types) && !in_array($this->entity_type, $this->fieldConfig->entity_types)) { + throw new FieldException(format_string('Attempt to create an instance of field @field_id on forbidden entity type @entity_type.', array('@field_id' => $this->fieldConfig->id, '@entity_type' => $this->entity_type))); + } + + // Assign the ID. + $this->id = $this->id(); + + // Ensure the field instance is unique within the bundle. + if ($prior_instance = $instance_controller->load($this->id)) { + throw new FieldException(format_string('Attempt to create an instance of field @field_id on bundle @bundle that already has an instance of that field.', array('@field_id' => $this->fieldConfig->id, '@bundle' => $this->bundle))); + } + + // Set the field UUID. + $this->field_uuid = $this->fieldConfig->uuid; + + // Ensure default values are present. + $this->prepareSave(); + + // Save the configuration. + $result = parent::save(); + field_cache_clear(); + + return $result; + } + + /** + * Saves an updated field instance definition. + * + * @return + * SAVED_UPDATED if the definition was saved. + * + * @throws \Drupal\field\FieldException + * If the field instance definition is invalid. + * + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures at the configuration storage level. + */ + protected function saveUpdated() { + $module_handler = \Drupal::moduleHandler(); + $instance_controller = \Drupal::entityManager()->getStorageController($this->entityType); + + $original = $instance_controller->loadUnchanged($this->getOriginalID()); + $this->original = $original; + + // Some updates are always disallowed. + if ($this->entity_type != $original->entity_type) { + throw new FieldException("Cannot change an existing instance's entity_type."); + } + if ($this->bundle != $original->bundle && empty($this->bundle_rename_allowed)) { + throw new FieldException("Cannot change an existing instance's bundle."); + } + if ($this->field_uuid != $original->field_uuid) { + throw new FieldException("Cannot change an existing instance's field."); + } + + // Ensure default values are present. + $this->prepareSave(); + + // Save the configuration. + $result = parent::save(); + field_cache_clear(); + + return $result; + } + + /** + * Prepares the instance definition for saving. + */ + protected function prepareSave() { + $field_type_info = field_info_field_types($this->fieldConfig->type); + + // Set the default instance settings. + $this->settings += $field_type_info['instance_settings']; + } + + /** + * Overrides \Drupal\Core\Entity\Entity::delete(). + * + * @param bool $field_cleanup + * (optional) 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. + */ + public function delete($field_cleanup = TRUE) { + if (!$this->deleted) { + $module_handler = \Drupal::moduleHandler(); + $state = \Drupal::state(); + + // Delete the configuration of this instance and save the configuration + // in the key_value table so we can use it later during + // field_purge_batch(). + $deleted_instances = $state->get('field.instance.deleted') ?: array(); + $config = $this->getExportProperties(); + $config['deleted'] = TRUE; + $deleted_instances[$this->uuid] = $config; + $state->set('field.instance.deleted', $deleted_instances); + + parent::delete(); + + // Clear the cache. + field_cache_clear(); + + // Mark instance data for deletion by invoking + // hook_field_storage_delete_instance(). + $module_handler->invoke($this->fieldConfig->storage['module'], 'field_storage_delete_instance', array($this)); + + // Remove the instance from the entity form displays. + if ($form_display = entity_load('entity_form_display', $this->entity_type . '.' . $this->bundle . '.default')) { + $form_display->removeComponent($this->fieldConfig->id())->save(); + } + + // Remove the instance from the entity displays. + $ids = array(); + $view_modes = array('default' => array()) + entity_get_view_modes($this->entity_type); + foreach (array_keys($view_modes) as $view_mode) { + $ids[] = $this->entity_type . '.' . $this->bundle . '.' . $view_mode; + } + foreach (entity_load_multiple('entity_display', $ids) as $display) { + $display->removeComponent($this->fieldConfig->id())->save(); + } + + // Delete the field itself if we just deleted its last instance. + if ($field_cleanup && count($this->fieldConfig->getBundles()) == 0) { + $this->fieldConfig->delete(); + } + } + } + + /** + * {@inheritdoc} + */ + public function getFieldConfig() { + return $this->fieldConfig; + } + + /** + * {@inheritdoc} + */ + public function getFieldName() { + return $this->fieldConfig->id; + } + + /** + * {@inheritdoc} + */ + public function getFieldType() { + return $this->fieldConfig->type; + } + + /** + * {@inheritdoc} + */ + public function getFieldSettings() { + return $this->settings + $this->fieldConfig->getFieldSettings(); + } + + /** + * {@inheritdoc} + */ + public function getFieldSetting($setting_name) { + if (array_key_exists($setting_name, $this->settings)) { + return $this->settings[$setting_name]; + } + else { + return $this->fieldConfig->getFieldSetting($setting_name); + } + } + + /** + * {@inheritdoc} + */ + public function getFieldPropertyNames() { + $schema = $this->fieldConfig->getSchema(); + return array_keys($schema['columns']); + } + + /** + * {@inheritdoc} + */ + public function isFieldTranslatable() { + return $this->fieldConfig->translatable; + } + + /** + * {@inheritdoc} + */ + public function getFieldLabel() { + return $this->label(); + } + + /** + * {@inheritdoc} + */ + public function getFieldDescription() { + return $this->description; + } + + /** + * {@inheritdoc} + */ + public function getFieldCardinality() { + return $this->fieldConfig->cardinality; + } + + /** + * {@inheritdoc} + */ + public function isFieldRequired() { + return $this->required; + } + + /** + * {@inheritdoc} + */ + public function allowBundleRename() { + $this->bundle_rename_allowed = TRUE; + } + + /** + * {@inheritdoc} + */ + public function offsetExists($offset) { + return (isset($this->{$offset}) || $offset == 'field_id' || $offset == 'field_name'); + } + + /** + * {@inheritdoc} + */ + public function &offsetGet($offset) { + if ($offset == 'field_id') { + return $this->field_uuid; + } + if ($offset == 'field_name') { + return $this->fieldConfig->id; + } + return $this->{$offset}; + } + + /** + * {@inheritdoc} + */ + public function offsetSet($offset, $value) { + if ($offset == 'field_id') { + $offset = 'field_uuid'; + } + $this->{$offset} = $value; + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($offset) { + if ($offset == 'field_id') { + $offset = 'field_uuid'; + } + unset($this->{$offset}); + } + + /** + * {@inheritdoc} + */ + public function serialize() { + // Only store the definition, not external objects or derived data. + return serialize($this->getExportProperties()); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + $this->__construct(unserialize($serialized)); + } + +} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index ff4472f..205134d 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * A common base class for configurable entity reference fields. @@ -34,9 +34,9 @@ class ConfigEntityReferenceItemBase extends EntityReferenceItem implements Confi /** * The Field instance definition. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * Returns the field instance definition. @@ -44,13 +44,13 @@ class ConfigEntityReferenceItemBase extends EntityReferenceItem implements Confi * Copied from \Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase, * since we cannot extend it. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @return \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { - $this->instance = $parent->getInstance(); + if (!isset($this->field_instance_config) && $parent = $this->getParent()) { + $this->field_instance_config = $parent->getInstance(); } - return $this->instance; + return $this->field_instance_config; } /** @@ -93,13 +93,13 @@ public function getPropertyDefinitions() { * Copied from \Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem, * since we cannot extend it. */ - public static function schema(Field $field) { - $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->type); + public static function schema(FieldConfig $field_config) { + $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_config->type); $module = $definition['module']; module_load_install($module); $callback = "{$module}_field_schema"; if (function_exists($callback)) { - return $callback($field); + return $callback($field_config); } } @@ -129,7 +129,7 @@ public function settingsForm(array $form, array &$form_state) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $this->getInstance()->getField()->hasData()); + return $callback($this->getInstance()->getFieldConfig(), $this->getInstance(), $this->getInstance()->getFieldConfig()->hasData()); } return array(); } @@ -141,8 +141,8 @@ public function settingsForm(array $form, array &$form_state) { * since we cannot extend it. */ public function instanceSettingsForm(array $form, array &$form_state) { - if ($callback = $this->getLegacyCallback('instance_settings_form')) { - return $callback($this->getInstance()->getField(), $this->getInstance(), $form_state); + if ($callback = $this->getLegacyCallback('instance_config_settings_form')) { + return $callback($this->getInstance()->getFieldConfig(), $this->getInstance(), $form_state); } return array(); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index dfc4fba..24228e5 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -19,9 +19,9 @@ class ConfigField extends Field implements ConfigFieldInterface { /** * The Field instance definition. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * {@inheritdoc} @@ -29,7 +29,7 @@ class ConfigField extends Field implements ConfigFieldInterface { public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { parent::__construct($definition, $name, $parent); if (isset($definition['instance'])) { - $this->instance = $definition['instance']; + $this->field_instance_config = $definition['instance']; } } @@ -37,11 +37,11 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface * {@inheritdoc} */ public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { + if (!isset($this->field_instance_config) && $parent = $this->getParent()) { $instances = FieldAPI::fieldInfo()->getBundleInstances($parent->entityType(), $parent->bundle()); - $this->instance = $instances[$this->getName()]; + $this->field_instance_config = $instances[$this->getName()]; } - return $this->instance; + return $this->field_instance_config; } /** @@ -52,7 +52,7 @@ public function getConstraints() { // Check that the number of values doesn't exceed the field cardinality. For // form submitted values, this can only happen with 'multiple value' // widgets. - $cardinality = $this->getInstance()->getField()->cardinality; + $cardinality = $this->getInstance()->getFieldConfig()->cardinality; if ($cardinality != FIELD_CARDINALITY_UNLIMITED) { $constraints[] = \Drupal::typedData() ->getValidationConstraintManager() diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php index cd91c47..4cd33e5 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php @@ -17,7 +17,7 @@ /** * Returns the field instance definition. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ public function getInstance(); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php index 743ad5c..7712a11 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php @@ -17,18 +17,18 @@ /** * The Field instance definition. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - public $instance; + public $field_instance_config; /** * {@inheritdoc} */ public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { - $this->instance = $parent->getInstance(); + if (!isset($this->field_instance_config) && $parent = $this->getParent()) { + $this->field_instance_config = $parent->getInstance(); } - return $this->instance; + return $this->field_instance_config; } /** diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php index 394ec01..ccf0f63 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php @@ -8,7 +8,7 @@ namespace Drupal\field\Plugin\Type\FieldType; use Drupal\Core\Entity\Field\FieldItemInterface; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Interface definition for 'configurable field type' plugins. @@ -18,7 +18,7 @@ /** * Returns the field instance definition. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ public function getInstance(); @@ -29,7 +29,7 @@ public function getInstance(); * creation of the field. No field instances exist by then, and it is not * possible to instantiate a FieldItemInterface object yet. * - * @param \Drupal\field\Plugin\Core\Entity\Field $field + * @param \Drupal\field\Plugin\Core\Entity\FieldConfig $field_config * The field definition. * * @return array @@ -54,7 +54,7 @@ public function getInstance(); * specify another field as related, only existing SQL tables, * such as {taxonomy_term_data}. */ - public static function schema(Field $field); + public static function schema(FieldConfig $field_config); /** * Returns a form for the field-level settings. diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php index fa780a5..9a14fd7 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\Plugin\PluginSettingsBase; /** @@ -129,8 +129,8 @@ public function prepareView(array $entities, $langcode, array &$items) { } * access: http://drupal.org/node/1994140. */ protected function checkFieldAccess($op, $entity) { - if ($this->fieldDefinition instanceof FieldInstanceInterface) { - $field = $this->fieldDefinition->getField(); + if ($this->fieldDefinition instanceof FieldInstanceConfigInterface) { + $field = $this->fieldDefinition->getFieldConfig(); return field_access($op, $field, $entity->entityType(), $entity); } else { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php index dda43b0..1ad86f7 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php @@ -8,7 +8,7 @@ namespace Drupal\field\Plugin\Type\Formatter; use Drupal\Core\Entity\EntityInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\field\Plugin\PluginSettingsInterface; /** diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index f3cb4cb..ac1bced 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -16,7 +16,7 @@ use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Plugin type manager for field formatters. diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 654cbbe..d59e126 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\Plugin\PluginSettingsBase; use Symfony\Component\Validator\ConstraintViolationInterface; @@ -444,8 +444,8 @@ protected function sortItems(array &$items) { * access: http://drupal.org/node/1994140. */ protected function checkFieldAccess($op, $entity) { - if ($this->fieldDefinition instanceof FieldInstanceInterface) { - $field = $this->fieldDefinition->getField(); + if ($this->fieldDefinition instanceof FieldInstanceConfigInterface) { + $field = $this->fieldDefinition->getFieldConfig(); return field_access($op, $field, $entity->entityType(), $entity); } else { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php index fbc939c..fd61d28 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php @@ -8,7 +8,7 @@ namespace Drupal\field\Plugin\Type\Widget; use Drupal\Core\Entity\EntityInterface; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Symfony\Component\Validator\ConstraintViolationInterface; /** diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php index bfbf092..7ae1b26 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php @@ -42,12 +42,12 @@ public function validate() { $entity = $this->getParent(); $langcode = $entity->language()->id; - if (isset($legacy_errors[$this->getInstance()->getField()->id()][$langcode])) { - foreach ($legacy_errors[$this->getInstance()->getField()->id()][$langcode] as $delta => $item_errors) { + if (isset($legacy_errors[$this->getInstance()->getFieldConfig()->id()][$langcode])) { + foreach ($legacy_errors[$this->getInstance()->getFieldConfig()->id()][$langcode] as $delta => $item_errors) { foreach ($item_errors as $item_error) { // We do not have the information about which column triggered the // error, so assume the first column... - $column = key($this->getInstance()->getField()->getColumns()); + $column = key($this->getInstance()->getFieldConfig()->getColumns()); $violations->add(new ConstraintViolation($item_error['message'], $item_error['message'], array(), $this, $delta . '.' . $column, $this->offsetGet($delta)->get($column)->getValue(), NULL, $item_error['error'])); } } @@ -115,7 +115,7 @@ protected function legacyCallback($hook, $args = array()) { $items = (array) $this->getValue(TRUE); $args = array_merge(array( $entity, - $this->getInstance()->getField(), + $this->getInstance()->getFieldConfig(), $this->getInstance(), $langcode, &$items diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index ea4073b..a8343fd 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -8,7 +8,7 @@ namespace Drupal\field\Plugin\field\field_type; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Plugin implementation for legacy field types. @@ -28,13 +28,13 @@ /** * {@inheritdoc} */ - public static function schema(Field $field) { - $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->type); + public static function schema(FieldConfig $field_config) { + $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_config->type); $module = $definition['module']; module_load_install($module); $callback = "{$module}_field_schema"; if (function_exists($callback)) { - return $callback($field); + return $callback($field_config); } } @@ -48,7 +48,7 @@ public function isEmpty() { $item = $this->getValue(TRUE); // The previous hook was never called on an empty item, but EntityNG always // creates a FieldItem element for an empty field. - return empty($item) || $callback($item, $this->getInstance()->getField()->type); + return empty($item) || $callback($item, $this->getInstance()->getFieldConfig()->type); } /** @@ -58,7 +58,7 @@ public function settingsForm(array $form, array &$form_state) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $this->getInstance()->getField()->hasData()); + return $callback($this->getInstance()->getFieldConfig(), $this->getInstance(), $this->getInstance()->getFieldConfig()->hasData()); } return array(); } @@ -67,8 +67,8 @@ public function settingsForm(array $form, array &$form_state) { * {@inheritdoc} */ public function instanceSettingsForm(array $form, array &$form_state) { - if ($callback = $this->getLegacyCallback('instance_settings_form')) { - return $callback($this->getInstance()->getField(), $this->getInstance(), $form_state); + if ($callback = $this->getLegacyCallback('instance_config_settings_form')) { + return $callback($this->getInstance()->getFieldConfig(), $this->getInstance(), $form_state); } return array(); } @@ -95,7 +95,7 @@ public function prepareCache() { $args = array( $entity->entityType(), array($entity_id => $entity), - $this->getInstance()->getField(), + $this->getInstance()->getFieldConfig(), array($entity_id => $this->getInstance()), $langcode, &$items, diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 3604142..7cac2b8 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\field\Plugin\views\field\Field. + * Definition of Drupal\field\Plugin\views\field\FieldConfig. */ namespace Drupal\field\Plugin\views\field; @@ -36,7 +36,7 @@ class Field extends FieldPluginBase { /** * The field information as returned by field_info_field(). * - * @var \Drupal\field\FieldInterface + * @var \Drupal\field\FieldConfigInterface */ public $field_info; @@ -76,7 +76,7 @@ class Field extends FieldPluginBase { protected $formatterPluginManager; /** - * Constructs a \Drupal\field\Plugin\views\field\Field object. + * Constructs a \Drupal\field\Plugin\views\field\FieldConfig object. * * @param array $configuration * A configuration array containing information about the plugin instance. diff --git a/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php b/core/modules/field/lib/Drupal/field/Tests/ActiveTest.php index c74d426..4d39196 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', ), ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $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 9637826..af99af6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -7,7 +7,7 @@ namespace Drupal\field\Tests; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; @@ -113,14 +113,14 @@ function setUp() { } // Create two fields. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'bf_1', 'type' => 'test_field', 'cardinality' => 1 )); $field->save(); $this->fields[] = $field; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'bf_2', 'type' => 'test_field', 'cardinality' => 4 @@ -133,7 +133,7 @@ function setUp() { $this->entity_type = 'entity_test'; foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field->id(), 'entity_type' => $this->entity_type, 'bundle' => $bundle, diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index b7b7d58..2ce9556 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -41,34 +41,34 @@ function testCreateField() { 'type' => 'test_field', ); field_test_memorize(); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $mem = field_test_memorize(); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]['field_name'], $field_definition['field_name'], 'hook_entity_create() called with correct arguments.'); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]['type'], $field_definition['type'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_config_create'][0][0]['field_name'], $field_definition['field_name'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_config_create'][0][0]['type'], $field_definition['type'], 'hook_entity_create() called with correct arguments.'); // 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. - $field_config = \Drupal::config('field.field.' . $field->id())->get(); + $field_config_raw = \Drupal::config('field.field.' . $field->id())->get(); // Ensure that basic properties are preserved. - $this->assertEqual($field_config['id'], $field_definition['field_name'], 'The field name is properly saved.'); - $this->assertEqual($field_config['type'], $field_definition['type'], 'The field type is properly saved.'); + $this->assertEqual($field_config_raw['id'], $field_definition['field_name'], 'The field name is properly saved.'); + $this->assertEqual($field_config_raw['type'], $field_definition['type'], 'The field type is properly saved.'); // Ensure that cardinality defaults to 1. - $this->assertEqual($field_config['cardinality'], 1, 'Cardinality defaults to 1.'); + $this->assertEqual($field_config_raw['cardinality'], 1, 'Cardinality defaults to 1.'); // Ensure that default settings are present. $field_type = field_info_field_types($field_definition['type']); - $this->assertEqual($field_config['settings'], $field_type['settings'], 'Default field settings have been written.'); + $this->assertEqual($field_config_raw['settings'], $field_type['settings'], 'Default field settings have been written.'); // Ensure that default storage was set. - $this->assertEqual($field_config['storage']['type'], config('field.settings')->get('default_storage'), 'The field type is properly saved.'); + $this->assertEqual($field_config_raw['storage']['type'], config('field.settings')->get('default_storage'), 'The field type is properly saved.'); // Guarantee that the name is unique. try { - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create two fields with the same name.')); } catch (FieldException $e) { @@ -80,7 +80,7 @@ function testCreateField() { $field_definition = array( 'field_name' => 'field_1', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with no type.')); } catch (FieldException $e) { @@ -92,7 +92,7 @@ function testCreateField() { $field_definition = array( 'type' => 'test_field' ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create an unnamed field.')); } catch (FieldException $e) { @@ -105,7 +105,7 @@ function testCreateField() { 'field_name' => '2field_2', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name starting with a digit.')); } catch (FieldException $e) { @@ -118,7 +118,7 @@ function testCreateField() { 'field_name' => 'field#_3', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name containing an illegal character.')); } catch (FieldException $e) { @@ -131,7 +131,7 @@ function testCreateField() { 'field_name' => '_12345678901234567890123456789012', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name longer than 32 characters.')); } catch (FieldException $e) { @@ -145,7 +145,7 @@ function testCreateField() { 'type' => 'test_field', 'field_name' => 'id', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field bearing the name of an entity key.')); } catch (FieldException $e) { @@ -159,22 +159,22 @@ function testCreateField() { function testCreateFieldFail() { $field_name = 'duplicate'; $field_definition = array('field_name' => $field_name, 'type' => 'test_field', 'storage' => array('type' => 'field_test_storage_failure')); - $field = entity_load('field_entity', $field_name); + $field = entity_load('field_config', $field_name); // The field does not exist. $this->assertFalse($field, 'The field does not exist.'); // Try to create the field. try { - entity_create('field_entity', $field_definition)->save(); - $this->assertTrue(FALSE, 'Field creation (correctly) fails.'); + entity_create('field_config', $field_definition)->save(); + $this->assertTrue(FALSE, 'FieldConfig creation (correctly) fails.'); } catch (\Exception $e) { - $this->assertTrue(TRUE, 'Field creation (correctly) fails.'); + $this->assertTrue(TRUE, 'FieldConfig creation (correctly) fails.'); } // The field does not exist. - $field = entity_load('field_entity', $field_name); + $field = entity_load('field_config', $field_name); $this->assertFalse($field, 'The field does not exist.'); } @@ -186,7 +186,7 @@ function testReadField() { 'field_name' => 'field_1', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); // Read the field back. $field = field_read_field($field_definition['field_name']); @@ -201,7 +201,7 @@ function testReadFields() { 'field_name' => 'field_1', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); // Check that 'single column' criteria works. $fields = field_read_fields(array('field_name' => $field_definition['field_name'])); @@ -219,7 +219,7 @@ function testReadFields() { 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance_definition)->save(); + entity_create('field_instance_config', $instance_definition)->save(); } /** @@ -231,11 +231,11 @@ function testFieldIndexes() { 'field_name' => 'field_1', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value')); - $this->assertEqual($schema['indexes'], $expected_indexes, 'Field type indexes saved by default'); + $this->assertEqual($schema['indexes'], $expected_indexes, 'FieldConfig type indexes saved by default'); // Check that indexes specified by the field definition override the field // type indexes. @@ -246,7 +246,7 @@ function testFieldIndexes() { 'value' => array(), ), ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array()); @@ -261,7 +261,7 @@ function testFieldIndexes() { 'value_2' => array('value'), ), ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $field = field_read_field($field_definition['field_name']); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); @@ -276,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'); - entity_create('field_entity', $this->field)->save(); + entity_create('field_config', $this->field)->save(); $this->another_field = array('field_name' => 'field_2', 'type' => 'test_field'); - entity_create('field_entity', $this->another_field)->save(); + entity_create('field_config', $this->another_field)->save(); // Create instances for each. $this->instance_definition = array( @@ -286,10 +286,10 @@ function testDeleteField() { 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $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(); + entity_create('field_instance_config', $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)); @@ -322,8 +322,8 @@ function testDeleteField() { // Try to create a new field the same name as a deleted field and // write data into it. - entity_create('field_entity', $this->field)->save(); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_config', $this->field)->save(); + entity_create('field_instance_config', $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('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -347,7 +347,7 @@ function testDeleteField() { function testUpdateFieldType() { $field_definition = array('field_name' => 'field_type', 'type' => 'number_decimal'); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); try { @@ -368,13 +368,13 @@ function testUpdateField() { // respected. Since cardinality enforcement is consistent across database // systems, it makes a good test case. $cardinality = 4; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'field_update', 'type' => 'test_field', 'cardinality' => $cardinality, )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'field_update', 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -409,7 +409,7 @@ function testUpdateField() { * Test field type modules forbidding an update. */ function testUpdateFieldForbid() { - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'forbidden', 'type' => 'test_field', 'settings' => array( diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 70195d3..b3b8a43 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -96,8 +96,8 @@ function setUp() { ), ); - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $instance)->save(); // Create a display for the default view mode. entity_get_display($instance['entity_type'], $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 58fb767..716ddac 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -55,13 +55,13 @@ function setUp() { 'field_name' => 'test_view_field', 'type' => 'text', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field['field_name'], 'entity_type' => 'node', 'bundle' => $content_type, ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $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 4739d5f..38a8e11 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -192,7 +192,7 @@ function testFieldAttachPrepareViewMultiple() { $formatter_setting = $this->randomName(); $instance_definition = $this->instance_definition; $instance_definition['bundle'] = 'test_bundle_2'; - $this->instance2 = entity_create('field_instance', $instance_definition); + $this->instance2 = entity_create('field_instance_config', $instance_definition); $this->instance2->save(); $display_2 = entity_get_display('entity_test', 'test_bundle_2', 'full') @@ -265,7 +265,7 @@ function testFieldAttachCache() { $instance_definition = $this->instance_definition; $instance_definition['entity_type'] = $entity_type; $instance_definition['bundle'] = $entity_type; - entity_create('field_instance', $instance_definition)->save(); + entity_create('field_instance_config', $instance_definition)->save(); entity_info_cache_clear(); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index e5f28d0..39886ba 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -20,9 +20,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase { /** * The field instance. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * Field name to use in the test. @@ -130,11 +130,11 @@ function testFieldAttachLoadMultiple() { ); for ($i = 1; $i <= 3; $i++) { $field_names[$i] = 'field_' . $i; - $field = entity_create('field_entity', array('field_name' => $field_names[$i], 'type' => 'test_field')); + $field = entity_create('field_config', array('field_name' => $field_names[$i], 'type' => 'test_field')); $field->save(); $field_ids[$i] = $field['uuid']; foreach ($field_bundles_map[$i] as $bundle) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_names[$i], 'entity_type' => $entity_type, 'bundle' => $bundles[$bundle], @@ -203,13 +203,13 @@ function testFieldAttachSaveLoadDifferentStorage() { ), ); foreach ($fields as $field) { - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field['field_name'], 'entity_type' => $entity_type, 'bundle' => $entity_type, ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1)); @@ -238,14 +238,14 @@ function testFieldAttachSaveLoadDifferentStorage() { */ function testFieldStorageDetailsAlter() { $field_name = 'field_test_change_my_details'; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field', 'cardinality' => 4, 'storage' => array('type' => 'field_test_storage'), )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -345,7 +345,7 @@ function testFieldAttachSaveEmptyDataDefaultValue() { // Verify that fields are populated with default values. $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1)); - $default = field_test_default_value($entity_init, $this->field, $this->instance); + $default = field_test_default_value($entity_init, $this->field, $this->field_instance_config); $this->assertEqual($entity_init->{$this->field_name}->getValue(), $default, 'Default field value correctly populated.'); // Insert: Field is NULL. @@ -370,7 +370,7 @@ function testFieldAttachSaveEmptyDataDefaultValue() { function testFieldAttachDelete() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $rev[0] = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->instance['bundle'])); + $rev[0] = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->field_instance_config['bundle'])); // Create revision 0 $values = $this->_generateTestFieldValues($this->field['cardinality']); @@ -378,18 +378,18 @@ function testFieldAttachDelete() { field_attach_insert($rev[0]); // Create revision 1 - $rev[1] = entity_create($entity_type, array('id' => 0, 'revision_id' => 1, 'type' => $this->instance['bundle'])); + $rev[1] = entity_create($entity_type, array('id' => 0, 'revision_id' => 1, 'type' => $this->field_instance_config['bundle'])); $rev[1]->{$this->field_name} = $values; field_attach_update($rev[1]); // Create revision 2 - $rev[2] = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->instance['bundle'])); + $rev[2] = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->field_instance_config['bundle'])); $rev[2]->{$this->field_name} = $values; field_attach_update($rev[2]); // Confirm each revision loads foreach (array_keys($rev) as $vid) { - $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->instance['bundle'])); + $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->field_instance_config['bundle'])); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); } @@ -397,24 +397,24 @@ function testFieldAttachDelete() { // Delete revision 1, confirm the other two still load. field_attach_delete_revision($rev[1]); foreach (array(0, 2) as $vid) { - $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->instance['bundle'])); + $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->field_instance_config['bundle'])); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); } // Confirm the current revision still loads - $read = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->instance['bundle'])); + $read = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->field_instance_config['bundle'])); field_attach_load($entity_type, array(0 => $read)); $this->assertEqual(count($read->{$this->field_name}), $this->field['cardinality'], "The test entity current revision has {$this->field['cardinality']} values."); // Delete all field data, confirm nothing loads field_attach_delete($rev[2]); foreach (array(0, 1, 2) as $vid) { - $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->instance['bundle'])); + $read = entity_create($entity_type, array('id' => 0, 'revision_id' => $vid, 'type' => $this->field_instance_config['bundle'])); field_attach_load_revision($entity_type, array(0 => $read)); $this->assertIdentical($read->{$this->field_name}[0]->getValue(), array(), "The test entity revision $vid is deleted."); } - $read = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->instance['bundle'])); + $read = entity_create($entity_type, array('id' => 0, 'revision_id' => 2, 'type' => $this->field_instance_config['bundle'])); field_attach_load($entity_type, array(0 => $read)); $this->assertIdentical($read->{$this->field_name}[0]->getValue(), array(), 'The test entity current revision is deleted.'); } @@ -432,16 +432,16 @@ function testEntityCreateRenameBundle() { // Add an instance to that bundle. $this->instance_definition['bundle'] = $new_bundle; - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Save an entity with data in the field. - $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->field_instance_config['bundle'])); $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity->{$this->field_name} = $values; field_attach_insert($entity); // Verify the field data is present on load. - $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->field_instance_config['bundle'])); field_attach_load($entity_type, array(0 => $entity)); $this->assertEqual(count($entity->{$this->field_name}), $this->field['cardinality'], "Data is retrieved for the new bundle"); @@ -450,11 +450,11 @@ function testEntityCreateRenameBundle() { entity_test_rename_bundle($this->instance_definition['bundle'], $new_bundle, $entity_type); // Check that the instance definition has been updated. - $this->instance = field_info_instance($entity_type, $this->field_name, $new_bundle); - $this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance."); + $this->field_instance_config = field_info_instance($entity_type, $this->field_name, $new_bundle); + $this->assertIdentical($this->field_instance_config['bundle'], $new_bundle, "Bundle name has been updated in the instance."); // Verify the field data is present on load. - $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->field_instance_config['bundle'])); field_attach_load($entity_type, array(0 => $entity)); $this->assertEqual(count($entity->{$this->field_name}), $this->field['cardinality'], "Bundle name has been updated in the field storage"); } @@ -472,12 +472,12 @@ function testEntityDeleteBundle() { // Add an instance to that bundle. $this->instance_definition['bundle'] = $new_bundle; - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $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); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => $entity_type, @@ -486,7 +486,7 @@ function testEntityDeleteBundle() { 'description' => $this->randomName() . '_description', 'weight' => mt_rand(0, 127), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Save an entity with data for both fields $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0, 'type' => $this->instance['bundle'])); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php index 6e4b8b8..461bd40 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php @@ -51,7 +51,7 @@ function testImportChange() { $this->configImporter()->import(); // Check that the updated config was correctly imported. - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertEqual($instance['label'], $new_label, 'Instance label updated'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php index bdfae09..fe1821f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php @@ -33,11 +33,11 @@ function testImportCreateDefault() { $instance_id_2b = "entity_test.entity_test.$field_id_2"; // Check that the fields and instances do not exist yet. - $this->assertFalse(entity_load('field_entity', $field_id)); - $this->assertFalse(entity_load('field_instance', $instance_id)); - $this->assertFalse(entity_load('field_entity', $field_id_2)); - $this->assertFalse(entity_load('field_instance', $instance_id_2a)); - $this->assertFalse(entity_load('field_instance', $instance_id_2b)); + $this->assertFalse(entity_load('field_config', $field_id)); + $this->assertFalse(entity_load('field_instance_config', $instance_id)); + $this->assertFalse(entity_load('field_config', $field_id_2)); + $this->assertFalse(entity_load('field_instance_config', $instance_id_2a)); + $this->assertFalse(entity_load('field_instance_config', $instance_id_2b)); // Create a second bundle for the 'Entity test' entity type. entity_test_create_bundle('test_bundle'); @@ -47,17 +47,17 @@ function testImportCreateDefault() { module_enable(array('field_test_config')); // A field with one instance. - $field = entity_load('field_entity', $field_id); + $field = entity_load('field_config', $field_id); $this->assertTrue($field, 'The field was created.'); - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'The field instance was deleted.'); // A field with multiple instances. - $field_2 = entity_load('field_entity', $field_id_2); + $field_2 = entity_load('field_config', $field_id_2); $this->assertTrue($field_2, 'The second field was created.'); - $instance_2a = entity_load('field_instance', $instance_id_2a); + $instance_2a = entity_load('field_instance_config', $instance_id_2a); $this->assertTrue($instance->bundle, 'test_bundle', 'The second field instance was created on bundle test_bundle.'); - $instance_2b = entity_load('field_instance', $instance_id_2b); + $instance_2b = entity_load('field_instance_config', $instance_id_2b); $this->assertTrue($instance->bundle, 'test_bundle_2', 'The second field instance was created on bundle test_bundle_2.'); // Tests field info contains the right data. @@ -103,15 +103,15 @@ function testImportCreate() { $this->configImporter()->import(); // Check that the field and instance were created. - $field = entity_load('field_entity', $field_id); + $field = entity_load('field_config', $field_id); $this->assertTrue($field, 'Test import field from staging exists'); - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'Test import field instance from staging exists'); - $field = entity_load('field_entity', $field_id_2); + $field = entity_load('field_config', $field_id_2); $this->assertTrue($field, 'Test import field 2 from staging exists'); - $instance = entity_load('field_instance', $instance_id_2a); + $instance = entity_load('field_instance_config', $instance_id_2a); $this->assertTrue($instance, 'Test import field instance 2a from staging exists'); - $instance = entity_load('field_instance', $instance_id_2b); + $instance = entity_load('field_instance_config', $instance_id_2b); $this->assertTrue($instance, 'Test import field instance 2b from staging exists'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php index 216d36a..6cbeaac 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php @@ -49,8 +49,8 @@ public function testImportDelete() { $this->installConfig(array('field_test_config')); // Get the uuid's for the fields. - $field_uuid = entity_load('field_entity', $field_id)->uuid(); - $field_uuid_2 = entity_load('field_entity', $field_id_2)->uuid(); + $field_uuid = entity_load('field_config', $field_id)->uuid(); + $field_uuid_2 = entity_load('field_config', $field_id_2)->uuid(); $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); @@ -65,15 +65,15 @@ public function testImportDelete() { $this->configImporter()->import(); // Check that the fields and instances are gone. - $field = entity_load('field_entity', $field_id, TRUE); + $field = entity_load('field_config', $field_id, TRUE); $this->assertFalse($field, 'The field was deleted.'); - $field_2 = entity_load('field_entity', $field_id_2, TRUE); + $field_2 = entity_load('field_config', $field_id_2, TRUE); $this->assertFalse($field_2, 'The second field was deleted.'); - $instance = entity_load('field_instance', $instance_id, TRUE); + $instance = entity_load('field_instance_config', $instance_id, TRUE); $this->assertFalse($instance, 'The field instance was deleted.'); - $instance_2a = entity_load('field_instance', $instance_id_2a, TRUE); + $instance_2a = entity_load('field_instance_config', $instance_id_2a, TRUE); $this->assertFalse($instance_2a, 'The second field instance on test bundle was deleted.'); - $instance_2b = entity_load('field_instance', $instance_id_2b, TRUE); + $instance_2b = entity_load('field_instance_config', $instance_id_2b, TRUE); $this->assertFalse($instance_2b, 'The second field instance on test bundle 2 was deleted.'); // Check that all config files are gone. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index 012ee4f..288fe0e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -50,7 +50,7 @@ function testFieldInfo() { // Create a field, verify it shows up. $core_fields = field_info_fields(); - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', )); @@ -76,7 +76,7 @@ function testFieldInfo() { 'description' => $this->randomName(), 'weight' => mt_rand(0, 127), ); - $instance = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); $info = entity_get_info('entity_test'); @@ -124,7 +124,7 @@ function testFieldPrepare() { 'field_name' => 'field', 'type' => 'test_field', ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); // Simulate a stored field definition missing a field setting (e.g. a @@ -151,13 +151,13 @@ function testInstancePrepare() { 'field_name' => 'field', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $instance_definition = array( 'field_name' => $field_definition['field_name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - $instance = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); // Simulate a stored instance definition missing various settings (e.g. a @@ -186,13 +186,13 @@ function testInstanceDisabledEntityType() { 'field_name' => 'field', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $instance_definition = array( 'field_name' => 'field', 'entity_type' => 'comment', 'bundle' => 'comment_node_article', ); - entity_create('field_instance', $instance_definition)->save(); + entity_create('field_instance_config', $instance_definition)->save(); // Disable coment module. This clears field_info cache. module_disable(array('comment')); @@ -221,7 +221,7 @@ function testFieldMap() { ), ); foreach ($fields as $field) { - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); } // Create a couple instances. @@ -248,7 +248,7 @@ function testFieldMap() { ), ); foreach ($instances as $instance) { - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } $expected = array( @@ -301,7 +301,7 @@ 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 = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field', )); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 29e6cb2..a3b0450 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -14,7 +14,7 @@ class FieldInstanceCrudTest extends FieldUnitTestBase { /** * The field entity. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $field; @@ -47,7 +47,7 @@ function setUp() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', ); - $this->field = entity_create('field_entity', $this->field_definition); + $this->field = entity_create('field_config', $this->field_definition); $this->field->save(); $this->instance_definition = array( 'field_name' => $this->field['field_name'], @@ -66,7 +66,7 @@ function setUp() { * Test the creation of a field instance. */ function testCreateFieldInstance() { - $instance = entity_create('field_instance', $this->instance_definition); + $instance = entity_create('field_instance_config', $this->instance_definition); $instance->save(); // Read the configuration. Check against raw configuration data rather than @@ -86,7 +86,7 @@ function testCreateFieldInstance() { // Guarantee that the field/bundle combination is unique. try { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $this->fail(t('Cannot create two instances with the same field / bundle combination.')); } catch (FieldException $e) { @@ -96,7 +96,7 @@ function testCreateFieldInstance() { // Check that the specified field exists. try { $this->instance_definition['field_name'] = $this->randomName(); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $this->fail(t('Cannot create an instance of a non-existing field.')); } catch (FieldException $e) { @@ -109,7 +109,7 @@ function testCreateFieldInstance() { 'type' => 'test_field', 'entity_types' => array('entity_test_cache'), ); - $field_restricted = entity_create('field_entity', $field_restricted_definition); + $field_restricted = entity_create('field_config', $field_restricted_definition); $field_restricted->save(); // Check that an instance can be added to an entity type allowed @@ -118,7 +118,7 @@ function testCreateFieldInstance() { $instance = $this->instance_definition; $instance['field_name'] = $field_restricted_definition['field_name']; $instance['entity_type'] = 'entity_test_cache'; - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); $this->pass(t('Can create an instance on an entity type allowed by the field.')); } catch (FieldException $e) { @@ -130,7 +130,7 @@ function testCreateFieldInstance() { try { $instance = $this->instance_definition; $instance['field_name'] = $field_restricted_definition['field_name']; - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); $this->fail(t('Cannot create an instance on an entity type forbidden by the field.')); } catch (FieldException $e) { @@ -144,7 +144,7 @@ function testCreateFieldInstance() { * Test reading back an instance definition. */ function testReadFieldInstance() { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Read the instance back. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -157,7 +157,7 @@ function testReadFieldInstance() { * Test the update of a field instance. */ function testUpdateFieldInstance() { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Check that basic changes are saved. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -185,10 +185,10 @@ function testDeleteFieldInstance() { // Create two instances for the same field so we can test that only one // is deleted. - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $another_instance_definition = $this->instance_definition; $another_instance_definition['bundle'] .= '_another_bundle'; - entity_create('field_instance', $another_instance_definition)->save(); + entity_create('field_instance_config', $another_instance_definition)->save(); // Test that the first instance is not deleted, and then delete it. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index 4580e7b..537b58b 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -65,7 +65,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu $instance_definition = 'instance_definition' . $suffix; $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix); - $this->$field = entity_create('field_entity', array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4)); + $this->$field = entity_create('field_config', array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4)); $this->$field->save(); $this->$field_id = $this->{$field}['uuid']; $this->$instance_definition = array( @@ -78,7 +78,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu 'test_instance_setting' => $this->randomName(), ), ); - $this->$instance = entity_create('field_instance', $this->$instance_definition); + $this->$instance = entity_create('field_instance_config', $this->$instance_definition); $this->$instance->save(); entity_get_form_display($entity_type, $bundle, 'default') diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index b7c600e..4ddeb95 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -81,8 +81,8 @@ function testFieldFormSingle() { $field = $this->field_single; $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -166,8 +166,8 @@ function testFieldFormDefaultValue() { $this->instance['field_name'] = $field_name; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -197,8 +197,8 @@ function testFieldFormSingleRequired() { $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; $this->instance['required'] = TRUE; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -238,16 +238,16 @@ function testFieldFormSingleRequired() { // $this->field = $this->field_multiple; // $field_name = $this->field['field_name']; // $this->instance['field_name'] = $field_name; -// entity_create('field_entity', $this->field)->save(); -// entity_create('field_instance', $this->instance)->save(); +// entity_create('field_config', $this->field)->save(); +// entity_create('field_instance_config', $this->instance)->save(); // } function testFieldFormUnlimited() { $field = $this->field_unlimited; $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -333,15 +333,15 @@ function testFieldFormMultivalueWithRequiredRadio() { $field = $this->field_unlimited; $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; // Add a required radio field. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'required_radio_test', 'type' => 'list_text', 'settings' => array( @@ -354,7 +354,7 @@ function testFieldFormMultivalueWithRequiredRadio() { 'bundle' => 'entity_test', 'required' => TRUE, ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') ->setComponent($instance['field_name'], array( 'type' => 'options_buttons', @@ -380,8 +380,8 @@ function testFieldFormJSAddMore() { $field = $this->field_unlimited; $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -442,8 +442,8 @@ function testFieldFormMultipleWidget() { $field = $this->field_multiple; $field_name = $field['field_name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name, array( 'type' => 'test_field_widget_multiple', @@ -493,8 +493,8 @@ function testFieldFormAccess() { $instance['field_name'] = $field_name; $instance['entity_type'] = $entity_type; $instance['bundle'] = $entity_type; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($entity_type, $entity_type, 'default') ->setComponent($field_name) ->save(); @@ -511,8 +511,8 @@ function testFieldFormAccess() { 'bundle' => $entity_type, 'default_value' => array(0 => array('value' => 99)), ); - entity_create('field_entity', $field_no_access)->save(); - entity_create('field_instance', $instance_no_access)->save(); + entity_create('field_config', $field_no_access)->save(); + entity_create('field_instance_config', $instance_no_access)->save(); entity_get_form_display($instance_no_access['entity_type'], $instance_no_access['bundle'], 'default') ->setComponent($field_name_no_access) ->save(); @@ -582,8 +582,8 @@ function testFieldFormHiddenWidget() { $this->instance['default_value'] = array(0 => array('value' => 99)); $this->instance['entity_type'] = $entity_type; $this->instance['bundle'] = $entity_type; - entity_create('field_entity', $field)->save(); - $this->instance = entity_create('field_instance', $this->instance); + entity_create('field_config', $field)->save(); + $this->instance = entity_create('field_instance_config', $this->instance); $this->instance->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name'], array( diff --git a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php index 3d180f6..027696c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php @@ -53,17 +53,17 @@ public function setUp() { */ function testNestedFieldForm() { // Add two instances on the 'entity_test' - entity_create('field_entity', $this->field_single)->save(); - entity_create('field_entity', $this->field_unlimited)->save(); + entity_create('field_config', $this->field_single)->save(); + entity_create('field_config', $this->field_unlimited)->save(); $this->instance['field_name'] = 'field_single'; $this->instance['label'] = 'Single field'; - entity_create('field_instance', $this->instance)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); $this->instance['field_name'] = 'field_unlimited'; $this->instance['label'] = 'Unlimited field'; - entity_create('field_instance', $this->instance)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); diff --git a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php index 6f7f3a0..ac42ff1 100644 --- a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php @@ -45,13 +45,13 @@ public function setUp() { 'field_name' => $this->field_name, 'type' => 'shape', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $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 e8b85d1..cb27267 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php @@ -45,13 +45,13 @@ public function setUp() { 'field_name' => $this->field_name, 'type' => 'test_field', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $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 ebf9722..6d5dfe5 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -58,22 +58,22 @@ class TranslationTest extends FieldUnitTestBase { /** * The field to use in this test. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The field instance to use in this test. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; public static function getInfo() { return array( - 'name' => 'Field translations tests', + 'name' => 'FieldConfig translations tests', 'description' => 'Test multilanguage fields logic.', - 'group' => 'Field API', + 'group' => 'FieldConfig API', ); } @@ -90,16 +90,16 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - entity_create('field_entity', $this->field_definition)->save(); - $this->field = field_read_field($this->field_name); + entity_create('field_config', $this->field_definition)->save(); + $this->field_config = field_read_field($this->field_name); $this->instance_definition = array( 'field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'bundle' => 'entity_test', ); - entity_create('field_instance', $this->instance_definition)->save(); - $this->instance = field_read_instance($this->entity_type, $this->field_name, $this->entity_type); + entity_create('field_instance_config', $this->instance_definition)->save(); + $this->field_instance_config = field_read_instance($this->entity_type, $this->field_name, $this->entity_type); for ($i = 0; $i < 3; ++$i) { $language = new Language(array( @@ -116,7 +116,7 @@ function setUp() { function testFieldAvailableLanguages() { // Test 'translatable' fieldable info. field_test_entity_info_translatable('entity_test', FALSE); - $field = clone($this->field); + $field = clone($this->field_config); $field['field_name'] .= '_untranslatable'; // Enable field translations for the entity. @@ -125,7 +125,7 @@ function testFieldAvailableLanguages() { // Test hook_field_languages() invocation on a translatable field. \Drupal::state()->set('field_test.field_available_languages_alter', TRUE); $langcodes = field_content_languages(); - $available_langcodes = field_available_languages($this->entity_type, $this->field); + $available_langcodes = field_available_languages($this->entity_type, $this->field_config); foreach ($available_langcodes as $delta => $langcode) { if ($langcode != 'xx' && $langcode != 'en') { $this->assertTrue(in_array($langcode, $langcodes), format_string('%language is an enabled language.', array('%language' => $langcode))); @@ -135,9 +135,9 @@ function testFieldAvailableLanguages() { $this->assertFalse(in_array('en', $available_langcodes), format_string('%language was made unavailable.', array('%language' => 'en'))); // Test field_available_languages() behavior for untranslatable fields. - $this->field['translatable'] = FALSE; - $this->field->save(); - $available_langcodes = field_available_languages($this->entity_type, $this->field); + $this->field_config['translatable'] = FALSE; + $this->field_config->save(); + $available_langcodes = field_available_languages($this->entity_type, $this->field_config); $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === Language::LANGCODE_NOT_SPECIFIED, 'For untranslatable fields only Language::LANGCODE_NOT_SPECIFIED is available.'); } @@ -154,19 +154,19 @@ function testTranslatableFieldSaveLoad() { $entity_type = 'entity_test'; field_test_entity_info_translatable($entity_type, TRUE); $id = $revision_id = 1; - $entity = entity_create($entity_type, array('id' => $id, 'revision_id' => $revision_id, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => $id, 'revision_id' => $revision_id, 'type' => $this->field_instance_config['bundle'])); $field_translations = array(); - $available_langcodes = field_available_languages($entity_type, $this->field); + $available_langcodes = field_available_languages($entity_type, $this->field_config); $this->assertTrue(count($available_langcodes) > 1, 'Field is translatable.'); $entity->langcode->value = reset($available_langcodes); foreach ($available_langcodes as $langcode) { - $field_translations[$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $field_translations[$langcode] = $this->_generateTestFieldValues($this->field_config['cardinality']); $entity->getTranslation($langcode)->{$this->field_name}->setValue($field_translations[$langcode]); } // Save and reload the field translations. field_attach_insert($entity); - $entity = entity_create($entity_type, array('id' => $id, 'revision_id' => $revision_id, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => $id, 'revision_id' => $revision_id, 'type' => $this->field_instance_config['bundle'])); $entity->langcode->value = reset($available_langcodes); field_attach_load($entity_type, array($id => $entity)); @@ -183,12 +183,12 @@ function testTranslatableFieldSaveLoad() { $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); $field_definition = $this->field_definition; $field_definition['field_name'] = $field_name_default; - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $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 = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); entity_info_cache_clear(); @@ -202,7 +202,7 @@ function testTranslatableFieldSaveLoad() { $values = array('id' => $id, 'revision_id' => $revision_id, 'type' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field_config['cardinality']); $entity->getTranslation($langcode, FALSE)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); } @@ -222,7 +222,7 @@ function testTranslatableFieldSaveLoad() { $values = array('id' => $id, 'revision_id' => $revision_id, 'type' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field_config['cardinality']); $entity->getTranslation($langcode)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); $entity->getTranslation($langcode)->{$field_name_default}->setValue($empty_items); $values[$field_name_default][$langcode] = $empty_items; @@ -249,19 +249,19 @@ function testFieldDisplayLanguage() { 'cardinality' => 2, 'translatable' => TRUE, ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field['field_name'], 'entity_type' => $entity_type, 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); $enabled_langcodes = field_content_languages(); - $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance['bundle']));; + $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->field_instance_config['bundle']));; $entity->langcode->value = reset($enabled_langcodes); - $instances = field_info_instances($entity_type, $this->instance['bundle']); + $instances = field_info_instances($entity_type, $this->field_instance_config['bundle']); $langcodes = array(); // This array is used to store, for each field name, which one of the locked diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index df93f12..4377ade 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -38,16 +38,16 @@ class TranslationWebTest extends FieldTestBase { /** * The field to use in this test. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The field instance to use in this test. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; public static function getInfo() { return array( @@ -70,16 +70,16 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - entity_create('field_entity', $field)->save(); - $this->field = field_read_field($this->field_name); + entity_create('field_config', $field)->save(); + $this->field_config = field_read_field($this->field_name); $instance = array( 'field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'bundle' => $this->entity_type, ); - entity_create('field_instance', $instance)->save(); - $this->instance = field_read_instance($this->entity_type, $this->field_name, $this->entity_type); + entity_create('field_instance_config', $instance)->save(); + $this->field_instance_config = field_read_instance($this->entity_type, $this->field_name, $this->entity_type); entity_get_form_display($this->entity_type, $this->entity_type, 'default') ->setComponent($this->field_name) @@ -104,10 +104,10 @@ function testFieldFormTranslationRevisions() { // Prepare the field translations. field_test_entity_info_translatable($this->entity_type, TRUE); $entity = entity_create($this->entity_type, array()); - $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field)); + $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field_config)); unset($available_langcodes[Language::LANGCODE_NOT_SPECIFIED]); unset($available_langcodes[Language::LANGCODE_NOT_APPLICABLE]); - $field_name = $this->field['field_name']; + $field_name = $this->field_config['field_name']; // Store the field translations. $entity->langcode->value = key($available_langcodes); @@ -136,11 +136,12 @@ function testFieldFormTranslationRevisions() { * by the passed arguments were correctly stored. */ private function checkTranslationRevisions($id, $revision_id, $available_langcodes) { - $field_name = $this->field['field_name']; + $field_name = $this->field_config['field_name']; $entity = entity_revision_load($this->entity_type, $revision_id); foreach ($available_langcodes as $langcode => $value) { $passed = $entity->getTranslation($langcode)->{$field_name}->value == $value + 1; $this->assertTrue($passed, format_string('The @language translation for revision @revision was correctly stored', array('@language' => $langcode, '@revision' => $entity->getRevisionId()))); } } + } 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 4bf2625..1c2cf9e 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', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // The second one will be attached to users only. $instance = array( @@ -44,7 +44,7 @@ function setUp() { 'entity_type' => 'user', 'bundle' => 'user', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $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', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); $instance = array( 'field_name' => $field_names[2], 'entity_type' => 'user', 'bundle' => 'user', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $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 3cba44c..b419808 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php @@ -61,7 +61,7 @@ function setUpFields($amount = 3) { $field_names[$i] = 'field_name_' . $i; $field = array('field_name' => $field_names[$i], 'type' => 'text'); - $this->fields[$i] = $field = entity_create('field_entity', $field); + $this->fields[$i] = $field = entity_create('field_config', $field); $field->save(); } return $field_names; @@ -74,7 +74,7 @@ function setUpInstances($bundle = 'page') { 'entity_type' => 'node', 'bundle' => 'page', ); - $this->instances[$key] = entity_create('field_instance', $instance); + $this->instances[$key] = entity_create('field_instance_config', $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 8658c52..63d97d7 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -47,10 +47,10 @@ protected function setUp() { $this->setUpFields(3); // Setup a field with cardinality > 1. - $this->fields[3] = $field = entity_create('field_entity', array('field_name' => 'field_name_3', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $this->fields[3] = $field = entity_create('field_config', 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 = entity_create('field_entity', array('field_name' => 'field_name_4', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); + $this->fields[4] = $field = entity_create('field_config', array('field_name' => 'field_name_4', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED)); $field->save(); $this->setUpInstances(); diff --git a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php index 6d4ed4a..80fe09a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php @@ -50,12 +50,12 @@ function setUp() { function testReEnabledField() { // Add a telephone field to the article content type. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'field_telephone', 'type' => 'telephone', )); $field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_telephone', 'label' => 'Telephone Number', 'entity_type' => 'node', diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index db22e81..60fd1a6 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -7,7 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\field\FieldException; -use Drupal\field\FieldInterface; +use Drupal\field\FieldConfigInterface; /** * Implements hook_field_info(). @@ -163,9 +163,9 @@ function field_test_field_settings_form($field, $instance) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function field_test_field_instance_settings_form($field, $instance) { +function field_test_field_instance_config_settings_form($field, $instance) { $settings = $instance['settings']; $form['test_instance_setting'] = array( @@ -201,14 +201,14 @@ function field_test_default_value(EntityInterface $entity, $field, $instance) { /** * Implements hook_field_access(). */ -function field_test_field_access($op, FieldInterface $field, $entity_type, $entity, $account) { - if ($field['field_name'] == "field_no_{$op}_access") { +function field_test_field_access($op, FieldConfigInterface $field_config, $entity_type, $entity, $account) { + if ($field_config['field_name'] == "field_no_{$op}_access") { return FALSE; } // Only grant view access to test_view_field fields when the user has // 'view test_view_field content' permission. - if ($field['field_name'] == 'test_view_field' && $op == 'view' && !user_access('view test_view_field content')) { + if ($field_config['field_name'] == 'test_view_field' && $op == 'view' && !user_access('view test_view_field content')) { return FALSE; } 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 800f4d4..ba04e29 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -1,7 +1,7 @@ save(); + * entity_create('field_config', $field_definition)->save(); * * // retrieve and reset the memorized hook call data * $mem = field_test_memorize(); * * // make sure hook_field_create_field() is invoked correctly - * assertEqual(count($mem['field_test_field_entity_create']), 1); - * assertEqual($mem['field_test_field_entity_create'][0], array($field)); + * assertEqual(count($mem['field_test_field_config_create']), 1); + * assertEqual($mem['field_test_field_config_create'][0], array($field)); * @endcode * * @param $key @@ -130,9 +130,9 @@ function field_test_memorize($key = NULL, $value = NULL) { } /** - * Memorize calls to field_test_field_entity_create() for field creation. + * Memorize calls to field_test_field_config_create() for field creation. */ -function field_test_field_entity_create(FieldInterface $field) { +function field_test_field_config_create(FieldConfigInterface $field_config) { $args = func_get_args(); field_test_memorize(__FUNCTION__, $args); } diff --git a/core/modules/field/tests/modules/field_test/field_test.storage.inc b/core/modules/field/tests/modules/field_test/field_test.storage.inc index 66c9911..1495fe0 100644 --- a/core/modules/field/tests/modules/field_test/field_test.storage.inc +++ b/core/modules/field/tests/modules/field_test/field_test.storage.inc @@ -6,7 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; /** * Implements hook_field_storage_info(). @@ -442,17 +442,17 @@ function field_test_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_instance'. + * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ -function field_test_field_instance_delete(FieldInstanceInterface $field_instance) { +function field_test_field_instance_config_delete(FieldInstanceConfigInterface $field_instance_config) { $data = _field_test_storage_data(); - $field = $field_instance->getField(); - if ($field->storage['type'] == 'field_test_storage') { - $field_data = &$data[$field->uuid]; + $field_config = $field_instance_config->getFieldConfig(); + if ($field_config->storage['type'] == 'field_test_storage') { + $field_data = &$data[$field_config->uuid]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as &$row) { - if ($row->bundle == $field_instance->bundle) { + if ($row->bundle == $field_instance_config->bundle) { $row->deleted = TRUE; } } diff --git a/core/modules/field_sql_storage/field_sql_storage.install b/core/modules/field_sql_storage/field_sql_storage.install index 8d14ca8..4f5bd4c 100644 --- a/core/modules/field_sql_storage/field_sql_storage.install +++ b/core/modules/field_sql_storage/field_sql_storage.install @@ -5,7 +5,7 @@ * Install, update, and uninstall functions for the Field SQL Storage module. */ -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Writes field data directly to SQL storage. @@ -96,14 +96,14 @@ function field_sql_storage_update_8000(&$sandbox) { // Retrieve the next field definition. When the index exceeds the number of // 'configuration' fields, use it to iterate on deleted fields. if (isset($config_names[$sandbox['index']])) { - $field_config = config($config_names[$sandbox['index']])->get(); + $field_config_raw = config($config_names[$sandbox['index']])->get(); } else { - $field_config = $deleted_fields[$sandbox['index'] - count($config_names)]; + $field_config_raw = $deleted_fields[$sandbox['index'] - count($config_names)]; } - if ($field_config['storage']['type'] == 'field_sql_storage') { - $field = new Field($field_config); + if ($field_config_raw['storage']['type'] == 'field_sql_storage') { + $field_config = new FieldConfig($field_config_raw); // Prepare updated schema data structures. $primary_key_data = array( @@ -132,8 +132,8 @@ function field_sql_storage_update_8000(&$sandbox) { ); $table_info = array( - _field_sql_storage_tablename($field) => $primary_key_data, - _field_sql_storage_revision_tablename($field) => $primary_key_revision, + _field_sql_storage_tablename($field_config) => $primary_key_data, + _field_sql_storage_revision_tablename($field_config) => $primary_key_revision, ); foreach ($table_info as $table => $primary_key) { // Do not update tables which already have the langcode column, diff --git a/core/modules/field_sql_storage/field_sql_storage.module b/core/modules/field_sql_storage/field_sql_storage.module index 5e3e0dd..124fb3c 100644 --- a/core/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field_sql_storage/field_sql_storage.module @@ -8,7 +8,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityInterface; use Drupal\field\FieldUpdateForbiddenException; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Implements hook_help(). @@ -94,7 +94,7 @@ function _field_sql_storage_revision_tablename($field) { * unique among all other fields. */ function _field_sql_storage_columnname($name, $column) { - return in_array($column, Field::getReservedColumns()) ? $column : $name . '_' . $column; + return in_array($column, FieldConfig::getReservedColumns()) ? $column : $name . '_' . $column; } /** 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 fce0a52..4a9b12c 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 @@ -38,16 +38,16 @@ class FieldSqlStorageTest extends EntityUnitTestBase { /** * A field to use in this class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * A field instance to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * Name of the revision table of the field. @@ -70,20 +70,20 @@ function setUp() { $entity_type = 'entity_test_rev'; $this->field_name = strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'test_field', 'cardinality' => 4, )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->field_config->save(); + $this->field_instance_config = entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type )); - $this->instance->save(); - $this->table = _field_sql_storage_tablename($this->field); - $this->revision_table = _field_sql_storage_revision_tablename($this->field); + $this->field_instance_config->save(); + $this->table = _field_sql_storage_tablename($this->field_config); + $this->revision_table = _field_sql_storage_revision_tablename($this->field_config); } /** @@ -102,7 +102,7 @@ function testFieldAttachLoad() { for ($evid = 0; $evid < 4; ++$evid) { $values[$evid] = array(); // Note: we insert one extra value ('<=' instead of '<'). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field_config['cardinality']; $delta++) { $value = mt_rand(1, 127); $values[$evid][] = $value; $query->values(array($entity_type, $eid, $evid, $delta, $langcode, $value)); @@ -124,7 +124,7 @@ function testFieldAttachLoad() { )); field_attach_load($entity_type, array($eid => $entity)); foreach ($values[0] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_config['cardinality']) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value, "Value $delta is loaded correctly for current revision"); } else { @@ -140,7 +140,7 @@ function testFieldAttachLoad() { )); field_attach_load_revision($entity_type, array($eid => $entity)); foreach ($values[$evid] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_config['cardinality']) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value, "Value $delta for revision $evid is loaded correctly"); } else { @@ -180,7 +180,7 @@ function testFieldAttachInsertAndUpdate() { $values = array(); // Note: we try to insert one extra value ('<=' instead of '<'). // TODO : test empty values filtering and "compression" (store consecutive deltas). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field_config['cardinality']; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name} = $rev_values[0] = $values; @@ -188,7 +188,7 @@ function testFieldAttachInsertAndUpdate() { $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_config['cardinality']) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Value $delta is inserted correctly")); } else { @@ -203,7 +203,7 @@ function testFieldAttachInsertAndUpdate() { )); $values = array(); // Note: we try to update one extra value ('<=' instead of '<'). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field_config['cardinality']; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $rev_values[1] = $values; @@ -211,7 +211,7 @@ function testFieldAttachInsertAndUpdate() { field_attach_update($entity); $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_config['cardinality']) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Value $delta is updated correctly")); } else { @@ -241,7 +241,7 @@ function testFieldAttachInsertAndUpdate() { field_attach_update($entity); $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field->cardinality) { + if ($delta < $this->field_config->cardinality) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Update with no field_name entry leaves value $delta untouched")); } } @@ -302,7 +302,7 @@ function testFieldAttachSaveMissingData() { $unavailable_langcode = 'xx'; db_insert($this->table) ->fields(array('entity_type', 'bundle', 'deleted', 'entity_id', 'revision_id', 'delta', 'langcode')) - ->values(array($entity_type, $this->instance->bundle, 0, 0, 0, 0, $unavailable_langcode)) + ->values(array($entity_type, $this->field_instance_config->bundle, 0, 0, 0, 0, $unavailable_langcode)) ->execute(); $count = db_select($this->table) ->countQuery() @@ -346,13 +346,13 @@ function testFieldAttachSaveMissingData() { function testUpdateFieldSchemaWithData() { $entity_type = 'entity_test_rev'; // Create a decimal 5.2 field and add some data. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'decimal52', 'type' => 'number_decimal', 'settings' => array('precision' => 5, 'scale' => 2), )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'decimal52', 'entity_type' => $entity_type, 'bundle' => $entity_type, @@ -381,7 +381,7 @@ function testUpdateFieldSchemaWithData() { */ function testFieldUpdateFailure() { // Create a text field. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'test_text', 'type' => 'text', 'settings' => array('max_length' => 255), @@ -412,11 +412,11 @@ function testFieldUpdateIndexesWithData() { // Create a decimal field. $field_name = 'testfield'; $entity_type = 'entity_test_rev'; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'text')); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, @@ -467,12 +467,12 @@ function testFieldUpdateIndexesWithData() { * Test the storage details. */ function testFieldStorageDetails() { - $current = _field_sql_storage_tablename($this->field); - $revision = _field_sql_storage_revision_tablename($this->field); + $current = _field_sql_storage_tablename($this->field_config); + $revision = _field_sql_storage_revision_tablename($this->field_config); // Retrieve the field and instance with field_info so the storage details are attached. $field = field_info_field($this->field_name); - $instance = field_info_instance($this->instance->entity_type, $field->id(), $this->instance->bundle); + $instance = field_info_instance($this->field_instance_config->entity_type, $field->id(), $this->field_instance_config->bundle); // The storage details are indexed by a storage engine type. $storage_details = $field->getStorageDetails(); @@ -485,7 +485,7 @@ function testFieldStorageDetails() { // Test current and revision storage details together because the columns // are the same. - $schema = $this->field->getSchema(); + $schema = $this->field_config->getSchema(); foreach ($schema['columns'] as $column_name => $attributes) { $storage_column_name = _field_sql_storage_columnname($this->field_name, $column_name); $this->assertEqual($details[FIELD_LOAD_CURRENT][$current][$column_name], $storage_column_name, t('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => $current))); @@ -501,7 +501,7 @@ function testFieldSqlStorageForeignKeys() { // field_test_field_schema()). $field_name = 'testfield'; $foreign_key_name = 'shape'; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'shape', 'settings' => array('foreign_key_name' => $foreign_key_name), diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 2040df2..8b59aea 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -253,8 +253,8 @@ function field_ui_element_info() { * Implements hook_entity_info(). */ function field_ui_entity_info(&$entity_info) { - $entity_info['field_instance']['controllers']['form']['delete'] = 'Drupal\field_ui\Form\FieldDeleteForm'; - $entity_info['field_entity']['controllers']['list'] = 'Drupal\field_ui\FieldListController'; + $entity_info['field_instance_config']['controllers']['form']['delete'] = 'Drupal\field_ui\Form\FieldDeleteForm'; + $entity_info['field_config']['controllers']['list'] = 'Drupal\field_ui\FieldListController'; } /** diff --git a/core/modules/field_ui/field_ui.routing.yml b/core/modules/field_ui/field_ui.routing.yml index 946d60e..c1bacd8 100644 --- a/core/modules/field_ui/field_ui.routing.yml +++ b/core/modules/field_ui/field_ui.routing.yml @@ -1,6 +1,6 @@ field_list: pattern: 'admin/reports/fields' defaults: - _entity_list: 'field_entity' + _entity_list: 'field_config' requirements: _permission: 'administer content types' diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 841c056..3f64340 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Controller\ControllerInterface; use Drupal\entity\EntityDisplayBaseInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -38,15 +38,15 @@ public function getFormID() { /** * {@inheritdoc} */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field_row = parent::buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); + protected function buildFieldRow($field_id, FieldInstanceConfigInterface $field_instance_config, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + $field_row = parent::buildFieldRow($field_id, $field_instance_config, $entity_display, $form, $form_state); $display_options = $entity_display->getComponent($field_id); // Insert the label column. $label = array( 'label' => array( '#type' => 'select', - '#title' => t('Label display for @title', array('@title' => $instance['label'])), + '#title' => t('Label display for @title', array('@title' => $field_instance_config['label'])), '#title_display' => 'invisible', '#options' => $this->getFieldLabelOptions(), '#default_value' => $display_options ? $display_options['label'] : 'above', @@ -57,7 +57,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $field_row = array_slice($field_row, 0, $label_position, TRUE) + $label + array_slice($field_row, $label_position, count($field_row) - 1, TRUE); // Update the (invisible) title of the 'plugin' column. - $field_row['plugin']['#title'] = t('Formatter for @title', array('@title' => $instance['label'])); + $field_row['plugin']['#title'] = t('Formatter for @title', array('@title' => $field_instance_config['label'])); if (!empty($field_row['plugin']['settings_edit_form'])) { $plugin_type_info = $entity_display->getRenderer($field_id)->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = t('Format settings:') . ' ' . $plugin_type_info['label'] . ''; @@ -189,11 +189,11 @@ protected function getFieldLabelOptions() { /** * {@inheritdoc} */ - protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceInterface $instance, array $form, array &$form_state) { + protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceConfigInterface $field_instance_config, array $form, array &$form_state) { $context = array( 'formatter' => $plugin, - 'field' => $instance->getField(), - 'instance' => $instance, + 'field' => $field_instance_config->getFieldConfig(), + 'instance' => $field_instance_config, 'view_mode' => $this->mode, 'form' => $form, ); @@ -203,11 +203,11 @@ protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstan /** * {@inheritdoc} */ - protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceInterface $instance) { + protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceConfigInterface $field_instance_config) { $context = array( 'formatter' => $plugin, - 'field' => $instance->getField(), - 'instance' => $instance, + 'field' => $field_instance_config->getFieldConfig(), + 'instance' => $field_instance_config, 'view_mode' => $this->mode, ); drupal_alter('field_formatter_settings_summary', $summary, $context); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index 5a45c21..c84f83e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -10,7 +10,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Core\Entity\EntityManager; use Drupal\entity\EntityDisplayBaseInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -191,7 +191,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, * * @param string $field_id * The field ID. - * @param \Drupal\field\FieldInstanceInterface $instance + * @param \Drupal\field\FieldInstanceConfigInterface $field_instance_config * The field instance. * @param \Drupal\entity\EntityDisplayBaseInterface $entity_display * The entity display. @@ -203,8 +203,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, * @return array * A table row array. */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field = $instance->getField(); + protected function buildFieldRow($field_id, FieldInstanceConfigInterface $field_instance_config, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + $field = $field_instance_config->getFieldConfig(); $display_options = $entity_display->getComponent($field_id); $field_row = array( @@ -216,11 +216,11 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En 'defaultPlugin' => $this->getDefaultPlugin($field['type']), ), 'human_name' => array( - '#markup' => check_plain($instance['label']), + '#markup' => check_plain($field_instance_config['label']), ), 'weight' => array( '#type' => 'textfield', - '#title' => t('Weight for @title', array('@title' => $instance['label'])), + '#title' => t('Weight for @title', array('@title' => $field_instance_config['label'])), '#title_display' => 'invisible', '#default_value' => $display_options ? $display_options['weight'] : '0', '#size' => 3, @@ -229,7 +229,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En 'parent_wrapper' => array( 'parent' => array( '#type' => 'select', - '#title' => t('Label display for @title', array('@title' => $instance['label'])), + '#title' => t('Label display for @title', array('@title' => $field_instance_config['label'])), '#title_display' => 'invisible', '#options' => drupal_map_assoc(array_keys($this->getRegions())), '#empty_value' => '', @@ -248,7 +248,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $field_row['plugin'] = array( 'type' => array( '#type' => 'select', - '#title' => t('Plugin for @title', array('@title' => $instance['label'])), + '#title' => t('Plugin for @title', array('@title' => $field_instance_config['label'])), '#title_display' => 'invisible', '#options' => $this->getPluginOptions($field['type']), '#default_value' => $display_options ? $display_options['type'] : 'hidden', @@ -268,7 +268,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En } // Get the corresponding plugin object. - $plugin = $this->getPlugin($instance, $display_options); + $plugin = $this->getPlugin($field_instance_config, $display_options); // Base button element for the various plugin settings actions. $base_button = array( @@ -289,7 +289,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En if ($plugin) { // Generate the settings form and allow other modules to alter it. $settings_form = $plugin->settingsForm($form, $form_state); - $this->alterSettingsForm($settings_form, $plugin, $instance, $form, $form_state); + $this->alterSettingsForm($settings_form, $plugin, $field_instance_config, $form, $form_state); if ($settings_form) { $field_row['plugin']['#cell_attributes'] = array('colspan' => 3); @@ -334,7 +334,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $summary = $plugin->settingsSummary(); // Allow other modules to alter the summary. - $this->alterSettingsSummary($summary, $plugin, $instance); + $this->alterSettingsSummary($summary, $plugin, $field_instance_config); if (!empty($summary)) { $field_row['settings_summary'] = array( @@ -622,7 +622,7 @@ public function multistepAjax($form, &$form_state) { /** * Returns the widget or formatter plugin for a field. * - * @param \Drupal\field\FieldInstanceInterface $instance + * @param \Drupal\field\FieldInstanceConfigInterface $field_instance_config * The field instance. * @param array $configuration * The plugin configuration @@ -630,7 +630,7 @@ public function multistepAjax($form, &$form_state) { * @return object * The corresponding plugin. */ - abstract protected function getPlugin($instance, $configuration); + abstract protected function getPlugin($field_instance_config, $configuration); /** * Returns an array of widget or formatter options for a field type. @@ -736,14 +736,14 @@ protected function getExtraFieldVisibilityOptions() { * The widget or formatter settings form. * @param object $plugin * The widget or formatter. - * @param FieldInstanceInterface $instance + * @param FieldInstanceConfigInterface $field_instance_config * The field instance. * @param array $form * The The (entire) configuration form array. * @param array $form_state * The form state. */ - abstract protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceInterface $instance, array $form, array &$form_state); + abstract protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceConfigInterface $field_instance_config, array $form, array &$form_state); /** * Alters the widget or formatter settings summary. @@ -752,9 +752,9 @@ protected function getExtraFieldVisibilityOptions() { * The widget or formatter settings summary. * @param object $plugin * The widget or formatter. - * @param FieldInstanceInterface $instance + * @param FieldInstanceConfigInterface $field_instance_config * The field instance. */ - abstract protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceInterface $instance); + abstract protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceConfigInterface $field_instance_config); } 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 8e7e770..cc1f9dd 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -9,7 +9,7 @@ use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Field UI field overview form. @@ -156,7 +156,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, '#description' => t('A unique machine-readable name containing letters, numbers, and underscores.'), // Calculate characters depending on the length of the field prefix // setting. Maximum length is 32. - '#maxlength' => Field::ID_MAX_LENGTH - strlen($field_prefix), + '#maxlength' => FieldConfig::ID_MAX_LENGTH - strlen($field_prefix), '#prefix' => '
 
', '#machine_name' => array( 'source' => array('fields', $name, 'label'), @@ -349,8 +349,8 @@ public function submitForm(array &$form, array &$form_state) { // Create the field and instance. try { - $this->entityManager->getStorageController('field_entity')->create($field)->save(); - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $this->entityManager->getStorageController('field_config')->create($field)->save(); + $new_instance = $this->entityManager->getStorageController('field_instance_config')->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' form mode (using @@ -396,7 +396,7 @@ public function submitForm(array &$form, array &$form_state) { ); try { - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $new_instance = $this->entityManager->getStorageController('field_instance_config')->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' form mode (using diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index e53eec9..5c36c5c 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -73,7 +73,7 @@ public function getCancelPath() { * {@inheritdoc} */ public function submit(array $form, array &$form_state) { - $field = $this->entity->getField(); + $field = $this->entity->getFieldConfig(); $bundles = entity_get_bundles(); $bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label']; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 305596f..7b3f045 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -11,7 +11,7 @@ use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\Field; use Drupal\field_ui\FieldUI; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,9 +24,9 @@ class FieldEditForm implements FormInterface, ControllerInterface { /** * The field instance being edited. * - * @var \Drupal\field\FieldInstanceInterface + * @var \Drupal\field\FieldInstanceConfigInterface */ - protected $instance; + protected $fieldInstanceConfig; /** * The entity manager. @@ -64,15 +64,15 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - $this->instance = $form_state['instance'] = $field_instance; + public function buildForm(array $form, array &$form_state, FieldInstanceConfigInterface $field_instance_config = NULL) { + $this->fieldInstanceConfig = $form_state['instance'] = $field_instance_config; - $field = $this->instance->getField(); + $field = $this->fieldInstanceConfig->getFieldConfig(); $form['#field'] = $field; - drupal_set_title($this->instance->label()); + drupal_set_title($this->fieldInstanceConfig->label()); - $description = '

' . t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $this->instance->label())) . '

'; + $description = '

' . t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $this->fieldInstanceConfig->label())) . '

'; // Create a form structure for the field values. $form['field'] = array( @@ -136,7 +136,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac ); // Create an arbitrary entity object, so that we can have an instantiated // FieldItem. - $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL); + $ids = (object) array('entity_type' => $this->fieldInstanceConfig['entity_type'], 'bundle' => $this->fieldInstanceConfig['bundle'], 'entity_id' => NULL); $entity = _field_create_entity_from_ids($ids); $form['field']['settings'] += $this->getFieldItem($entity, $field['field_name'])->settingsForm($form, $form_state); @@ -182,15 +182,15 @@ public function submitForm(array &$form, array &$form_state) { // Update the field. try { $field->save(); - drupal_set_message(t('Updated field %label field settings.', array('%label' => $this->instance->label()))); + drupal_set_message(t('Updated field %label field settings.', array('%label' => $this->fieldInstanceConfig->label()))); $next_destination = FieldUI::getNextDestination(); if (empty($next_destination)) { - $next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields'; + $next_destination = $this->entityManager->getAdminPath($this->fieldInstanceConfig->entity_type, $this->fieldInstanceConfig->bundle) . '/fields'; } $form_state['redirect'] = $next_destination; } catch (\Exception $e) { - drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $this->instance->label(), '%message' => $e->getMessage())), 'error'); + drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $this->fieldInstanceConfig->label(), '%message' => $e->getMessage())), 'error'); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index 26264ac..21f9395 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -10,7 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityNG; use Drupal\Core\Language\Language; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; /** * Provides a form for the field instance settings form. @@ -21,36 +21,36 @@ class FieldInstanceEditForm extends FieldInstanceFormBase { * {@inheritdoc} */ public function getFormID() { - return 'field_ui_field_instance_edit_form'; + return 'field_ui_field_instance_config_edit_form'; } /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - parent::buildForm($form, $form_state, $field_instance); + public function buildForm(array $form, array &$form_state, FieldInstanceConfigInterface $field_instance_config = NULL) { + parent::buildForm($form, $form_state, $field_instance_config); - $bundle = $this->instance['bundle']; - $entity_type = $this->instance['entity_type']; - $field = $this->instance->getField(); + $bundle = $this->fieldInstanceConfig['bundle']; + $entity_type = $this->fieldInstanceConfig['entity_type']; + $field_config = $this->fieldInstanceConfig->getFieldConfig(); $entity_form_display = entity_get_form_display($entity_type, $bundle, 'default'); $bundles = entity_get_bundles(); drupal_set_title(t('%instance settings for %bundle', array( - '%instance' => $this->instance->label(), + '%instance' => $this->fieldInstanceConfig->label(), '%bundle' => $bundles[$entity_type][$bundle]['label'], )), PASS_THROUGH); - $form['#field'] = $field; + $form['#field'] = $field_config; $form['#entity_form_display'] = $entity_form_display; // Create an arbitrary entity object (used by the 'default value' widget). - $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL); + $ids = (object) array('entity_type' => $this->fieldInstanceConfig['entity_type'], 'bundle' => $this->fieldInstanceConfig['bundle'], 'entity_id' => NULL); $form['#entity'] = _field_create_entity_from_ids($ids); $form['#entity']->field_ui_default_value = TRUE; - if (!empty($field['locked'])) { + if (!empty($field_config['locked'])) { $form['locked'] = array( - '#markup' => t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->label())), + '#markup' => t('The field %field is locked and cannot be edited.', array('%field' => $this->fieldInstanceConfig->label())), ); return $form; } @@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac // Build the non-configurable instance values. $form['instance']['field_name'] = array( '#type' => 'value', - '#value' => $this->instance['field_name'], + '#value' => $this->fieldInstanceConfig['field_name'], ); $form['instance']['entity_type'] = array( '#type' => 'value', @@ -78,7 +78,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['label'] = array( '#type' => 'textfield', '#title' => t('Label'), - '#default_value' => $this->instance->label() ?: $field['field_name'], + '#default_value' => $this->fieldInstanceConfig->label() ?: $field_config['field_name'], '#required' => TRUE, '#weight' => -20, ); @@ -86,7 +86,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['description'] = array( '#type' => 'textarea', '#title' => t('Help text'), - '#default_value' => !empty($this->instance['description']) ? $this->instance['description'] : '', + '#default_value' => !empty($this->fieldInstanceConfig['description']) ? $this->fieldInstanceConfig['description'] : '', '#rows' => 5, '#description' => t('Instructions to present to the user below this field on the editing form.
Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '
' . t('This field supports tokens.'), '#weight' => -10, @@ -95,17 +95,17 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['required'] = array( '#type' => 'checkbox', '#title' => t('Required field'), - '#default_value' => !empty($this->instance['required']), + '#default_value' => !empty($this->fieldInstanceConfig['required']), '#weight' => -5, ); // Add instance settings for the field type. - $form['instance']['settings'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->instanceSettingsForm($form, $form_state); + $form['instance']['settings'] = $this->getFieldItem($form['#entity'], $this->fieldInstanceConfig['field_name'])->instanceSettingsForm($form, $form_state); $form['instance']['settings']['#weight'] = 10; // Add handling for default value if not provided by any other module. - if (field_behaviors_widget('default_value', $this->instance) == FIELD_BEHAVIOR_DEFAULT && empty($this->instance['default_value_function'])) { - $form['instance']['default_value_widget'] = $this->getDefaultValueWidget($field, $form, $form_state); + if (field_behaviors_widget('default_value', $this->fieldInstanceConfig) == FIELD_BEHAVIOR_DEFAULT && empty($this->fieldInstanceConfig['default_value_function'])) { + $form['instance']['default_value_widget'] = $this->getDefaultValueWidget($field_config, $form, $form_state); } $form['actions'] = array('#type' => 'actions'); @@ -125,9 +125,10 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { - // Take the incoming values as the $this->instance definition, so that the 'default - // value' gets validated using the instance settings being submitted. - $field_name = $this->instance['field_name']; + // Take the incoming values as the $this->fieldInstanceConfig definition, so + // that the 'default value' gets validated using the instance settings being + // submitted. + $field_name = $this->fieldInstanceConfig['field_name']; $entity = $form['#entity']; $entity_form_display = $form['#entity_form_display']; @@ -136,7 +137,7 @@ public function validateForm(array &$form, array &$form_state) { // Extract the 'default value'. $items = array(); - $entity_form_display->getRenderer($this->instance->getField()->id)->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $entity_form_display->getRenderer($this->fieldInstanceConfig->getFieldConfig()->id)->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); // @todo Simplify when all entity types are converted to EntityNG. if ($entity instanceof EntityNG) { @@ -160,7 +161,7 @@ public function validateForm(array &$form, array &$form_state) { field_form_set_state($element['#parents'], $field_name, Language::LANGCODE_NOT_SPECIFIED, $form_state, $field_state); // Assign reported errors to the correct form element. - $entity_form_display->getRenderer($this->instance->getField()->id)->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $entity_form_display->getRenderer($this->fieldInstanceConfig->getFieldConfig()->id)->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); } } } @@ -178,18 +179,18 @@ public function submitForm(array &$form, array &$form_state) { // Extract field values. $items = array(); - $entity_form_display->getRenderer($this->instance->getField()->id)->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $entity_form_display->getRenderer($this->fieldInstanceConfig->getFieldConfig()->id)->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); - $this->instance['default_value'] = $items ? $items : NULL; + $this->fieldInstanceConfig['default_value'] = $items ? $items : NULL; } // Merge incoming values into the instance. foreach ($form_state['values']['instance'] as $key => $value) { - $this->instance[$key] = $value; + $this->fieldInstanceConfig[$key] = $value; } - $this->instance->save(); + $this->fieldInstanceConfig->save(); - drupal_set_message(t('Saved %label configuration.', array('%label' => $this->instance->label()))); + drupal_set_message(t('Saved %label configuration.', array('%label' => $this->fieldInstanceConfig->label()))); $form_state['redirect'] = $this->getNextDestination(); } @@ -203,7 +204,7 @@ public function delete(array &$form, array &$form_state) { $destination = drupal_get_destination(); unset($_GET['destination']); } - $form_state['redirect'] = array('admin/structure/types/manage/' . $this->instance['bundle'] . '/fields/' . $this->instance->id() . '/delete', array('query' => $destination)); + $form_state['redirect'] = array('admin/structure/types/manage/' . $this->fieldInstanceConfig['bundle'] . '/fields/' . $this->fieldInstanceConfig->id() . '/delete', array('query' => $destination)); } /** @@ -226,18 +227,19 @@ protected function getDefaultValueWidget($field, array &$form, &$form_state) { // Adjust the instance definition used for the form element. We want a // non-required input and no description. - $this->instance['required'] = FALSE; - $this->instance['description'] = ''; + $this->fieldInstanceConfig['required'] = FALSE; + $this->fieldInstanceConfig['description'] = ''; // Adjust the instance definition to use the default widget of this field type // instead of the hidden widget. - // @todo Clean this up since we don't have $this->instance['widget'] anymore. + // @todo Clean this up since we don't have + // $this->fieldInstanceConfig['widget'] anymore. // see https://drupal.org/node/2028759 - if ($this->instance['widget']['type'] == 'hidden') { + if ($this->fieldInstanceConfig['widget']['type'] == 'hidden') { $field_type = field_info_field_types($field['type']); $default_widget = $this->widgetManager->getDefinition($field_type['default_widget']); - $this->instance['widget'] = array( + $this->fieldInstanceConfig['widget'] = array( 'type' => $default_widget['id'], 'settings' => $default_widget['settings'], 'weight' => 0, @@ -247,10 +249,10 @@ protected function getDefaultValueWidget($field, array &$form, &$form_state) { // Insert the widget. Since we do not use the "official" instance definition, // the whole flow cannot use field_invoke_method(). $items = array(); - if (!empty($this->instance['default_value'])) { - $items = (array) $this->instance['default_value']; + if (!empty($this->fieldInstanceConfig['default_value'])) { + $items = (array) $this->fieldInstanceConfig['default_value']; } - $element += $entity_form_display->getRenderer($this->instance->getField()->id)->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $element += $entity_form_display->getRenderer($this->fieldInstanceConfig->getFieldConfig()->id)->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); return $element; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php index 5f7ca61..ccece25 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php @@ -11,7 +11,7 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Drupal\field_ui\FieldUI; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,9 +20,9 @@ /** * The field instance being edited. * - * @var \Drupal\field\FieldInstanceInterface + * @var \Drupal\field\FieldInstanceConfigInterface */ - protected $instance; + protected $fieldInstanceConfig; /** * The field widget plugin manager. @@ -64,8 +64,8 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - $this->instance = $form_state['instance'] = $field_instance; + public function buildForm(array $form, array &$form_state, FieldInstanceConfigInterface $field_instance_config = NULL) { + $this->fieldInstanceConfig = $form_state['instance'] = $field_instance_config; } /** @@ -77,7 +77,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac protected function getNextDestination() { $next_destination = FieldUI::getNextDestination(); if (empty($next_destination)) { - $next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields'; + $next_destination = $this->entityManager->getAdminPath($this->fieldInstanceConfig->entity_type, $this->fieldInstanceConfig->bundle) . '/fields'; } return $next_destination; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php index d2ab86a..9c6bab9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Controller\ControllerInterface; use Drupal\entity\EntityDisplayBaseInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -38,11 +38,11 @@ public function getFormID() { /** * {@inheritdoc} */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field_row = parent::buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); + protected function buildFieldRow($field_id, FieldInstanceConfigInterface $field_instance_config, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + $field_row = parent::buildFieldRow($field_id, $field_instance_config, $entity_display, $form, $form_state); // Update the (invisible) title of the 'plugin' column. - $field_row['plugin']['#title'] = t('Formatter for @title', array('@title' => $instance['label'])); + $field_row['plugin']['#title'] = t('Formatter for @title', array('@title' => $field_instance_config['label'])); if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $entity_display->getRenderer($field_id))) { $plugin_type_info = $plugin->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = t('Widget settings:') . ' ' . $plugin_type_info['label'] . ''; @@ -134,11 +134,11 @@ protected function getOverviewPath($mode) { /** * {@inheritdoc} */ - protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceInterface $instance, array $form, array &$form_state) { + protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstanceConfigInterface $field_instance_config, array $form, array &$form_state) { $context = array( 'widget' => $plugin, - 'field' => $instance->getField(), - 'instance' => $instance, + 'field' => $field_instance_config->getFieldConfig(), + 'instance' => $field_instance_config, 'form_mode' => $this->mode, 'form' => $form, ); @@ -148,11 +148,11 @@ protected function alterSettingsForm(array &$settings_form, $plugin, FieldInstan /** * {@inheritdoc} */ - protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceInterface $instance) { + protected function alterSettingsSummary(array &$summary, $plugin, FieldInstanceConfigInterface $field_instance_config) { $context = array( 'widget' => $plugin, - 'field' => $instance->getField(), - 'instance' => $instance, + 'field' => $field_instance_config->getFieldConfig(), + 'instance' => $field_instance_config, 'form_mode' => $this->mode, ); drupal_alter('field_widget_settings_summary', $summary, $context); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index e994202..724b1c5 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -54,22 +54,22 @@ public function routes(RouteBuildEvent $event) { $path = $entity_info['route_base_path']; $route = new Route( - "$path/fields/{field_instance}", + "$path/fields/{field_instance_config}", array('_form' => '\Drupal\field_ui\Form\FieldInstanceEditForm'), array('_permission' => 'administer ' . $entity_type . ' fields') ); $collection->add("field_ui.instance_edit.$entity_type", $route); $route = new Route( - "$path/fields/{field_instance}/field", + "$path/fields/{field_instance_config}/field", array('_form' => '\Drupal\field_ui\Form\FieldEditForm'), array('_permission' => 'administer ' . $entity_type . ' fields') ); $collection->add("field_ui.field_edit.$entity_type", $route); $route = new Route( - "$path/fields/{field_instance}/delete", - array('_entity_form' => 'field_instance.delete'), + "$path/fields/{field_instance_config}/delete", + array('_entity_form' => 'field_instance_config.delete'), array('_permission' => 'administer ' . $entity_type . ' fields') ); $collection->add("field_ui.delete.$entity_type", $route); 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 645ae95..621763a 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 @@ -45,7 +45,7 @@ function setUp() { 'field_name' => 'field_' . $vocabulary->id(), 'type' => 'taxonomy_term_reference', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => 'field_' . $vocabulary->id(), @@ -53,7 +53,7 @@ function setUp() { 'label' => 'Tags', 'bundle' => 'article', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', 'article', 'default') ->setComponent('field_' . $vocabulary->id()) @@ -275,11 +275,11 @@ function testFieldPrefix() { function testDefaultValue() { // Create a test field and instance. $field_name = 'test'; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'test_field' ))->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => $this->type, @@ -385,14 +385,14 @@ function testDeleteField() { function testLockedField() { // Create a locked field and attach it to a bundle. We need to do this // programatically as there's no way to create a locked field through UI. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => strtolower($this->randomName(8)), 'type' => 'test_field', 'cardinality' => 1, 'locked' => TRUE )); $field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_uuid' => $field->uuid, 'entity_type' => 'node', 'bundle' => $this->type, @@ -425,14 +425,14 @@ function testHiddenFields() { // Create a field and an instance programmatically. $field_name = 'hidden_test_field'; - entity_create('field_entity', array('field_name' => $field_name, 'type' => $field_name))->save(); + entity_create('field_config', array('field_name' => $field_name, 'type' => $field_name))->save(); $instance = array( 'field_name' => $field_name, 'bundle' => $this->type, 'entity_type' => 'node', 'label' => t('Hidden field'), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', $this->type, 'default') ->setComponent($field_name) ->save(); @@ -509,12 +509,12 @@ function testDeleteTaxonomyField() { */ function testHelpDescriptions() { // Create an image field - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_image', 'type' => 'image', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_image', 'entity_type' => 'node', 'label' => 'Image', @@ -546,4 +546,5 @@ function fieldListAdminPage() { $this->assertText($this->field_name, 'Field name is displayed in field list.'); $this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->type . '/fields'), 'Link to content type using field is displayed in field list.'); } + } diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 3305a00..afed2d6 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -78,9 +78,9 @@ function file_field_settings_form($field, $instance) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function file_field_instance_settings_form($field, $instance) { +function file_field_instance_config_settings_form($field, $instance) { $settings = $instance['settings']; $form['file_directory'] = array( @@ -135,7 +135,7 @@ function file_field_instance_settings_form($field, $instance) { * parse_size(). * * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). + * file_field_instance_config_settings_form(). */ function _file_generic_settings_max_filesize($element, &$form_state) { if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { @@ -147,7 +147,7 @@ function _file_generic_settings_max_filesize($element, &$form_state) { * Render API callback: Validates the allowed file extensions field. * * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). + * file_field_instance_config_settings_form(). * * This doubles as a convenience clean-up function and a validation routine. * Commas are allowed by the end-user, but ultimately the value will be stored @@ -175,7 +175,7 @@ function _file_generic_settings_extensions($element, &$form_state) { * value. * * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). + * file_field_instance_config_settings_form(). */ function _file_generic_settings_file_directory_validate($element, &$form_state) { // Strip slashes from the beginning and end of $widget['file_directory']. diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 1f31e43..6e5ca53 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -5,7 +5,7 @@ * Install, update and uninstall functions for File module. */ -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Implements hook_schema(). @@ -302,10 +302,10 @@ function file_update_8002() { */ function file_update_8003() { foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) { - $field_config = config($config_name); + $field_config_raw = config($config_name); // Only update file fields that use the default SQL storage. - if (in_array($field_config->get('type'), array('file', 'image')) && $field_config->get('storage.type') == 'field_sql_storage') { - $field = new Field($field_config->get()); + if (in_array($field_config_raw->get('type'), array('file', 'image')) && $field_config_raw->get('storage.type') == 'field_sql_storage') { + $field = new FieldConfig($field_config_raw->get()); $tables = array( _field_sql_storage_tablename($field), @@ -331,11 +331,11 @@ function file_update_8003() { } // Update the indexes in field config as well. - $indexes = $field_config->get('indexes'); + $indexes = $field_config_raw->get('indexes'); unset($indexes['fid']); $indexes['target_id'] = array('target_id'); - $field_config->set('indexes', $indexes); - $field_config->save(); + $field_config_raw->set('indexes', $indexes); + $field_config_raw->save(); } } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 965c44d..7d18337 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -74,7 +74,7 @@ function createFileField($name, $type_name, $field_settings = array(), $instance 'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1, ); $field_definition['settings'] = array_merge($field_definition['settings'], $field_settings); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $this->attachFileField($name, 'node', $type_name, $instance_settings, $widget_settings); @@ -107,7 +107,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra 'settings' => array(), ); $instance['settings'] = array_merge($instance['settings'], $instance_settings); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($entity_type, $bundle, 'default') ->setComponent($name, array( diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index fd00c11..2df0d4c 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -44,12 +44,12 @@ public function setUp() { $this->installSchema('file', 'file_managed'); $this->installSchema('file', 'file_usage'); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'file_test', 'type' => 'file', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'file_test', 'bundle' => 'entity_test', diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index d44da5c..217b411 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -52,7 +52,7 @@ function forum_enable() { // is being enabled at the same time as taxonomy after both modules have been // enabled, the field might exist but still be marked inactive. if (!field_read_field('taxonomy_forums', array('include_inactive' => TRUE))) { - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'taxonomy_forums', 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -76,7 +76,7 @@ function forum_enable() { $term->save(); // Create the instance on the bundle. - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'taxonomy_forums', 'entity_type' => 'node', 'label' => $vocabulary->name, diff --git a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php index ea55fd9..dc2a216 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php @@ -77,31 +77,31 @@ function setUp() { language_save($german); // Create the test text field. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test_text', 'type' => 'text', 'translatable' => FALSE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_text', 'bundle' => 'entity_test', ))->save(); // Create the test translatable field. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test_translatable_text', 'type' => 'text', 'translatable' => TRUE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_translatable_text', 'bundle' => 'entity_test', ))->save(); // Create the test entity reference field. - entity_create('field_entity', array( + entity_create('field_config', array( 'translatable' => TRUE, 'settings' => array( 'target_type' => 'entity_test', @@ -109,7 +109,7 @@ function setUp() { 'field_name' => 'field_test_entity_reference', 'type' => 'entity_reference', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test', diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index 9609960..470f135 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -87,13 +87,13 @@ function image_field_settings_form($field, $instance) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function image_field_instance_settings_form($field, $instance) { +function image_field_instance_config_settings_form($field, $instance) { $settings = $instance['settings']; // Use the file field instance settings form as a basis. - $form = file_field_instance_settings_form($field, $instance); + $form = file_field_instance_config_settings_form($field, $instance); // Add maximum and minimum resolution settings. $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); diff --git a/core/modules/image/image.install b/core/modules/image/image.install index fd440da..e538584 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -6,7 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Implements hook_install(). diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 4e786bd..d9cb397 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -7,14 +7,14 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; -use Drupal\field\Plugin\Core\Entity\Field; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldConfig; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; use Drupal\Component\Uuid\Uuid; use Drupal\file\Plugin\Core\Entity\File; use Drupal\image\ImageStyleInterface; use Drupal\image\Plugin\Core\Entity\ImageStyle; -use Drupal\field\FieldInterface; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldInstanceConfigInterface; /** * Image style constant for user presets in the database. @@ -671,10 +671,10 @@ function _image_effect_definitions_sort($a, $b) { */ function image_entity_presave(EntityInterface $entity, $type) { $field = FALSE; - if ($entity instanceof FieldInstance) { - $field = $entity->getField(); + if ($entity instanceof FieldInstanceConfig) { + $field = $entity->getFieldConfig(); } - elseif ($entity instanceof Field) { + elseif ($entity instanceof FieldConfig) { $field = $entity; } if ($field && $field->type == 'image' && is_array($entity->settings['default_image'])) { @@ -688,18 +688,18 @@ function image_entity_presave(EntityInterface $entity, $type) { } /** - * Implements hook_ENTITY_TYPE_update() for 'field_entity'. + * Implements hook_ENTITY_TYPE_update() for 'field_config'. */ -function image_field_entity_update(FieldInterface $field) { - if ($field->type != 'image') { +function image_field_entity_update(FieldConfigInterface $field_config) { + if ($field_config->type != 'image') { // Only act on image fields. return; } - $prior_field = $field->original; + $prior_field = $field_config->original; // The value of a managed_file element can be an array if #extended == TRUE. - $fid_new = (isset($field->settings['default_image']['fids']) ? $field->settings['default_image']['fids'] : $field->settings['default_image']); + $fid_new = (isset($field_config->settings['default_image']['fids']) ? $field_config->settings['default_image']['fids'] : $field->settings['default_image']); $fid_old = (isset($prior_field->settings['default_image']['fids']) ? $prior_field->settings['default_image']['fids'] : $prior_field->settings['default_image']); $file_new = $fid_new ? file_load($fid_new) : FALSE; @@ -710,38 +710,38 @@ function image_field_entity_update(FieldInterface $field) { if ($file_new) { $file_new->status = FILE_STATUS_PERMANENT; $file_new->save(); - file_usage()->add($file_new, 'image', 'default_image', $field->uuid); + file_usage()->add($file_new, 'image', 'default_image', $field_config->uuid); } // Is there an old file? if ($fid_old && ($file_old = file_load($fid_old[0]))) { - file_usage()->delete($file_old, 'image', 'default_image', $field->uuid); + file_usage()->delete($file_old, 'image', 'default_image', $field_config->uuid); } } // If the upload destination changed, then move the file. - if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field->settings['uri_scheme'])) { - $directory = $field->settings['uri_scheme'] . '://default_images/'; + if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_config->settings['uri_scheme'])) { + $directory = $field_config->settings['uri_scheme'] . '://default_images/'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); file_move($file_new, $directory . $file_new->filename); } } /** - * Implements hook_ENTITY_TYPE_update() for 'field_instance'. + * Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. */ -function image_field_instance_update(FieldInstanceInterface $field_instance) { - $field = $field_instance->getField(); +function image_field_instance_config_update(FieldInstanceConfigInterface $field_instance_config) { + $field = $field_instance_config->getFieldConfig(); if ($field->type != 'image') { // Only act on image fields. return; } - $prior_instance = $field_instance->original; + $prior_instance = $field_instance_config->original; // The value of a managed_file element can be an array if the #extended // property is set to TRUE. - $fid_new = $field_instance->settings['default_image']; + $fid_new = $field_instance_config->settings['default_image']; if (isset($fid_new['fids'])) { $fid_new = $fid_new['fids']; } @@ -757,11 +757,11 @@ function image_field_instance_update(FieldInstanceInterface $field_instance) { if ($file_new) { $file_new->status = FILE_STATUS_PERMANENT; $file_new->save(); - file_usage()->add($file_new, 'image', 'default_image', $field_instance->uuid); + file_usage()->add($file_new, 'image', 'default_image', $field_instance_config->uuid); } // Delete the old file, if present. if ($fid_old && ($file_old = file_load($fid_old[0]))) { - file_usage()->delete($file_old, 'image', 'default_image', $field_instance->uuid); + file_usage()->delete($file_old, 'image', 'default_image', $field_instance_config->uuid); } } @@ -774,40 +774,40 @@ function image_field_instance_update(FieldInstanceInterface $field_instance) { } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_entity'. + * Implements hook_ENTITY_TYPE_delete() for 'field_config'. */ -function image_field_entity_delete(FieldInterface $field) { - if ($field->type != 'image') { +function image_field_entity_delete(FieldConfigInterface $field_config) { + if ($field_config->type != 'image') { // Only act on image fields. return; } // The value of a managed_file element can be an array if #extended == TRUE. - $fid = (isset($field->settings['default_image']['fids']) ? $field->settings['default_image']['fids'] : $field->settings['default_image']); + $fid = (isset($field_config->settings['default_image']['fids']) ? $field_config->settings['default_image']['fids'] : $field_config->settings['default_image']); if ($fid && ($file = file_load($fid[0]))) { - file_usage()->delete($file, 'image', 'default_image', $field->uuid); + file_usage()->delete($file, 'image', 'default_image', $field_config->uuid); } } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_instance'. + * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ -function image_field_instance_delete(FieldInstanceInterface $field_instance) { - $field = $field_instance->getField(); - if ($field->type != 'image') { +function image_field_instance_config_delete(FieldInstanceConfigInterface $field_instance_config) { + $field_config = $field_instance_config->getFieldConfig(); + if ($field_config->type != 'image') { // Only act on image fields. return; } // The value of a managed_file element can be an array if the #extended // property is set to TRUE. - $fid = $field_instance->settings['default_image']; + $fid = $field_instance_config->settings['default_image']; if (is_array($fid)) { $fid = $fid['fid']; } // Remove the default image when the instance is deleted. if ($fid && ($file = file_load($fid))) { - file_usage()->delete($file, 'image', 'default_image', $field_instance->uuid); + file_usage()->delete($file, 'image', 'default_image', $field_instance_config->uuid); } } diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 7dd36c0..0914e58 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -133,7 +133,7 @@ protected static function replaceImageStyle(ImageStyleInterface $style) { $instances = field_read_instances(); // Loop through all fields searching for image fields. foreach ($instances as $instance) { - if ($instance->getField()->type == 'image') { + if ($instance->getFieldConfig()->type == 'image') { $view_modes = entity_get_view_modes($instance['entity_type']); $view_modes = array('default') + array_keys($view_modes); foreach ($view_modes as $view_mode) { diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php index 06374b6..e02762e 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php @@ -32,7 +32,7 @@ public function prepareView(array $entities, $langcode, array &$items) { // Otherwise, use the default for the field. // Note, that we have to bypass getFieldSetting() as this returns the // instance-setting default. - elseif (($field = $this->fieldDefinition->getField()) && !empty($field->settings['default_image'])) { + elseif (($field = $this->fieldDefinition->getFieldConfig()) && !empty($field->settings['default_image'])) { $fid = array($field->settings['default_image']); } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index 164cbad..24f56f2 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -51,23 +51,23 @@ function testDefaultImages() { $widget_settings = array( 'preview_image_style' => 'medium', ); - $instance = $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings); + $field_instance_config = $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings); $field = field_info_field($field_name); // Add another instance with another default image to the page content type. - $instance2 = entity_create('field_instance', array( + $field_instance_config2 = entity_create('field_instance_config', array( 'field_name' => $field->id(), 'entity_type' => 'node', 'bundle' => 'page', - 'label' => $instance->label(), - 'required' => $instance->required, + 'label' => $field_instance_config->label(), + 'required' => $field_instance_config->required, 'settings' => array( 'default_image' => $default_images['instance2']->id(), ), )); - $instance2->save(); + $field_instance_config2->save(); - $widget_settings = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($field['field_name']); + $widget_settings = entity_get_form_display($field_instance_config['entity_type'], $field_instance_config['bundle'], 'default')->getComponent($field['field_name']); entity_get_form_display('node', 'page', 'default') ->setComponent($field->id(), $widget_settings) ->save(); @@ -76,7 +76,7 @@ function testDefaultImages() { ->save(); // Confirm the defaults are present on the article field settings form. - $this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field"); + $this->drupalGet("admin/structure/types/manage/article/fields/$field_instance_config->id/field"); $this->assertFieldByXpath( '//input[@name="field[settings][default_image][fids]"]', $default_images['field']->id(), @@ -86,7 +86,7 @@ function testDefaultImages() { ) ); // Confirm the defaults are present on the article field edit form. - $this->drupalGet("admin/structure/types/manage/article/fields/$instance->id"); + $this->drupalGet("admin/structure/types/manage/article/fields/$field_instance_config->id"); $this->assertFieldByXpath( '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance']->id(), @@ -97,7 +97,7 @@ function testDefaultImages() { ); // Confirm the defaults are present on the page field settings form. - $this->drupalGet("admin/structure/types/manage/page/fields/$instance->id/field"); + $this->drupalGet("admin/structure/types/manage/page/fields/$field_instance_config->id/field"); $this->assertFieldByXpath( '//input[@name="field[settings][default_image][fids]"]', $default_images['field']->id(), @@ -107,7 +107,7 @@ function testDefaultImages() { ) ); // Confirm the defaults are present on the page field edit form. - $this->drupalGet("admin/structure/types/manage/page/fields/$instance2->id"); + $this->drupalGet("admin/structure/types/manage/page/fields/$field_instance_config2->id"); $this->assertFieldByXpath( '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance2']->id(), @@ -146,7 +146,7 @@ function testDefaultImages() { $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"); + $this->drupalGet("admin/structure/types/manage/article/fields/$field_instance_config->id/field"); $this->assertFieldByXpath( '//input[@name="field[settings][default_image][fids]"]', $default_images['field_new']->id(), @@ -177,12 +177,12 @@ function testDefaultImages() { ); // Upload a new default for the article's field instance. - $instance['settings']['default_image'] = $default_images['instance_new']->id(); - $instance->save(); + $field_instance_config['settings']['default_image'] = $default_images['instance_new']->id(); + $field_instance_config->save(); // Confirm the new field instance default is used on the article field // admin form. - $this->drupalGet("admin/structure/types/manage/article/fields/$instance->id"); + $this->drupalGet("admin/structure/types/manage/article/fields/$field_instance_config->id"); $this->assertFieldByXpath( '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance_new']->id(), @@ -216,11 +216,11 @@ function testDefaultImages() { ); // Remove the instance default from articles. - $instance['settings']['default_image'] = 0; - $instance->save(); + $field_instance_config['settings']['default_image'] = 0; + $field_instance_config->save(); // Confirm the article field instance default has been removed. - $this->drupalGet("admin/structure/types/manage/article/fields/$instance->id"); + $this->drupalGet("admin/structure/types/manage/article/fields/$field_instance_config->id"); $this->assertFieldByXpath( '//input[@name="instance[settings][default_image][fids]"]', '', diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index e7775ad..6542b9c 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -196,7 +196,7 @@ function testImageFieldSettings() { $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]' => $this->randomName($test_size), ); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); - $schema = $instance->getField()->getSchema(); + $schema = $instance->getFieldConfig()->getSchema(); $this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array( '%max' => $schema['columns']['alt']['length'], '%length' => $test_size, diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index b1d1716..83dd691 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -67,6 +67,8 @@ function setUp() { * A list of instance settings that will be added to the instance defaults. * @param $widget_settings * A list of widget settings that will be added to the widget defaults. + * + * @return \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ function createImageField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) { $field = array( @@ -76,7 +78,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); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field['field_name'], @@ -88,8 +90,8 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc 'settings' => array(), ); $instance['settings'] = array_merge($instance['settings'], $instance_settings); - $field_instance = entity_create('field_instance', $instance); - $field_instance->save(); + $field_instance_config = entity_create('field_instance_config', $instance); + $field_instance_config->save(); entity_get_form_display('node', $type_name, 'default') ->setComponent($field['field_name'], array( @@ -102,8 +104,7 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc ->setComponent($field['field_name']) ->save(); - return $field_instance; - + return $field_instance_config; } /** diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php index 5e7472f..70369c9 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php @@ -43,12 +43,12 @@ public function setUp() { $this->installSchema('file', array('file_managed', 'file_usage')); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'image_test', 'type' => 'image', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'image_test', 'bundle' => 'entity_test', diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index b4033ff..717eea6 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -25,16 +25,16 @@ class LinkFieldTest extends WebTestBase { /** * A field to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The instance used in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * A user with permission to view and manage test entities. @@ -67,12 +67,12 @@ function setUp() { function testURLValidation() { $field_name = drupal_strtolower($this->randomName()); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'link', )); - $this->field->save(); - entity_create('field_instance', array( + $this->field_config->save(); + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -141,12 +141,12 @@ function testURLValidation() { function testLinkTitle() { $field_name = drupal_strtolower($this->randomName()); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'link', )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->field_config->save(); + $this->field_instance_config = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -155,7 +155,7 @@ function testLinkTitle() { 'title' => DRUPAL_OPTIONAL, ), )); - $this->instance->save(); + $this->field_instance_config->save(); entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', @@ -177,8 +177,8 @@ function testLinkTitle() { // Verify that the link text field works according to the field setting. foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) { // Update the link title field setting. - $this->instance->settings['title'] = $title_setting; - $this->instance->save(); + $this->field_instance_config->settings['title'] = $title_setting; + $this->field_instance_config->save(); // Display creation form. $this->drupalGet('entity_test/add'); @@ -260,13 +260,13 @@ function testLinkTitle() { function testLinkFormatter() { $field_name = drupal_strtolower($this->randomName()); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'link', 'cardinality' => 2, )); - $this->field->save(); - entity_create('field_instance', array( + $this->field_config->save(); + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'label' => 'Read more about this entity', @@ -403,13 +403,13 @@ function testLinkFormatter() { function testLinkSeparateFormatter() { $field_name = drupal_strtolower($this->randomName()); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'link', 'cardinality' => 2, )); - $this->field->save(); - entity_create('field_instance', array( + $this->field_config->save(); + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -465,7 +465,7 @@ function testLinkSeparateFormatter() { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field_config['field_name'], $display_options) ->save(); $this->renderTestEntity($id); diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php index 2cd88bc..e33173e 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php @@ -35,11 +35,11 @@ public function setUp() { parent::setUp(); // Create an link field and instance for validation. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test', 'type' => 'link', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', diff --git a/core/modules/link/link.module b/core/modules/link/link.module index 61066dd..c5a2e29 100644 --- a/core/modules/link/link.module +++ b/core/modules/link/link.module @@ -38,9 +38,9 @@ function link_field_info() { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function link_field_instance_settings_form($field, $instance) { +function link_field_instance_config_settings_form($field, $instance) { $form['title'] = array( '#type' => 'radios', '#title' => t('Allow link text'), diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php index 65e3aec..9b76886 100644 --- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -40,14 +40,14 @@ function testMultiStepNodeFormBasicOptions() { // Create an unlimited cardinality field. $this->field_name = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'text', 'cardinality' => -1, ))->save(); // Attach an instance of the field to the page content type. - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page', diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php index adee17d..e6d99de 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php @@ -178,4 +178,5 @@ protected function assertTaxonomyPage($is_admin) { } } } + } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php index e1a33aa..1bec156 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php @@ -61,11 +61,11 @@ public function setUp() { // Add a custom field to the page content type. $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'text' ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page', diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php index f2209d7..66ae71d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php @@ -154,4 +154,5 @@ function testRevisions() { '%revision-date' => format_date($old_revision_date), ))); } + } diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index b485545..953da2d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -67,7 +67,7 @@ function setUp() { // Set up a field and instance. $this->field_name = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -80,7 +80,7 @@ function setUp() { ), 'cardinality' => '-1', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page', diff --git a/core/modules/node/node.module b/core/modules/node/node.module index b04718c..3dfdc4a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -398,7 +398,7 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { $field = field_info_field('body'); $instance = field_info_instance('node', 'body', $type->id()); if (empty($field)) { - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'body', 'type' => 'text_with_summary', 'entity_types' => array('node'), @@ -406,7 +406,7 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { $field->save(); } if (empty($instance)) { - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'body', 'entity_type' => 'node', 'bundle' => $type->id(), 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 1baa48e..0449c81 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 @@ -49,7 +49,7 @@ function node_access_test_language_node_access_records(EntityInterface $node) { * (restricted access) in a given translation. */ function node_access_test_language_enable() { - $field_private = entity_create('field_entity', array( + $field_private = entity_create('field_config', array( 'field_name' => 'field_private', 'type' => 'list_boolean', 'cardinality' => 1, @@ -60,7 +60,7 @@ function node_access_test_language_enable() { )); $field_private->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_private->id(), 'entity_type' => 'node', 'bundle' => 'page', diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 8bea406..a11411b 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -25,16 +25,16 @@ class NumberFieldTest extends WebTestBase { /** * A field to use in this class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * A field instance to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * A user with permission to view and manage entities and content types. @@ -63,22 +63,22 @@ function setUp() { */ function testNumberDecimalField() { // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field_config = entity_create('field_config', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'number_decimal', 'settings' => array( 'precision' => 8, 'scale' => 4, 'decimal_separator' => '.', ) )); - $this->field->save(); - entity_create('field_instance', array( - 'field_name' => $this->field->id(), + $this->field_config->save(); + entity_create('field_instance_config', array( + 'field_name' => $this->field_config->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($this->field_config->id(), array( 'type' => 'number', 'settings' => array( 'placeholder' => '0.00' @@ -86,7 +86,7 @@ function testNumberDecimalField() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($this->field_config->id(), array( 'type' => 'number_decimal', )) ->save(); @@ -94,7 +94,7 @@ function testNumberDecimalField() { // Display creation form. $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget is displayed'); + $this->assertFieldByName("{$this->field_config['field_name']}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertRaw('placeholder="0.00"'); // Submit a signed decimal value within the allowed precision and scale. @@ -102,7 +102,7 @@ function testNumberDecimalField() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field['field_name']}[$langcode][0][value]" => $value, + "{$this->field_config['field_name']}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); @@ -122,10 +122,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, + "{$this->field_config['field_name']}[$langcode][0][value]" => $wrong_entry, ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $this->field['field_name'])), 'Correctly failed to save decimal value with more than one decimal point.'); + $this->assertRaw(t('%name must be a number.', array('%name' => $this->field_config['field_name'])), 'Correctly failed to save decimal value with more than one decimal point.'); } // Try to create entries with minus sign not in the first position. @@ -140,10 +140,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, + "{$this->field_config['field_name']}[$langcode][0][value]" => $wrong_entry, ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $this->field['field_name'])), 'Correctly failed to save decimal value with minus sign in the wrong position.'); + $this->assertRaw(t('%name must be a number.', array('%name' => $this->field_config['field_name'])), 'Correctly failed to save decimal value with minus sign in the wrong position.'); } } @@ -182,4 +182,5 @@ function testNumberIntegerField() { ); $this->drupalPost(NULL, $edit, t('Save')); } + } diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php index a0cc904..a47ec44 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php @@ -36,11 +36,11 @@ public function setUp() { // Create number fields and instances for validation. foreach (array('integer', 'float', 'decimal') as $type) { - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_' . $type, 'type' => 'number_' . $type, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'bundle' => 'entity_test', diff --git a/core/modules/number/number.module b/core/modules/number/number.module index 5e6bd92..28e6e8b 100644 --- a/core/modules/number/number.module +++ b/core/modules/number/number.module @@ -83,9 +83,9 @@ function number_field_settings_form($field, $instance) { } /** - * Implements hook_field_instance_settings_form(). + * Implements hook_field_instance_config_settings_form(). */ -function number_field_instance_settings_form($field, $instance) { +function number_field_instance_config_settings_form($field, $instance) { $settings = $instance['settings']; $form['min'] = array( diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php index c270e4a..31d5407 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php @@ -32,7 +32,7 @@ function setUp() { parent::setUp(); $this->field_name = 'test_options'; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'list_text', 'cardinality' => 1, @@ -40,7 +40,7 @@ function setUp() { 'allowed_values_function' => 'options_test_dynamic_values_callback', ), ))->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 218e413..3b31ba2 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -48,9 +48,9 @@ function testUpdateAllowedValues() { $entity = entity_create('entity_test', array()); $entity->{$this->fieldName}->value = 1; $entity->save(); - $this->field->settings['allowed_values'] = array(2 => 'Two'); + $this->field_config->settings['allowed_values'] = array(2 => 'Two'); try { - $this->field->save(); + $this->field_config->save(); $this->fail(t('Cannot update a list field to not include keys with existing data.')); } catch (FieldException $e) { @@ -61,8 +61,9 @@ function testUpdateAllowedValues() { $entity->save(); // Removed options do not appear. - $this->field->settings['allowed_values'] = array(2 => 'Two'); - $this->field->save(); + $this->field_config->settings['allowed_values'] = array(2 => 'Two'); + $this->field_config->save(); + $entity = entity_create('entity_test', array()); $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist'); @@ -70,8 +71,8 @@ function testUpdateAllowedValues() { $this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist'); // Completely new options appear. - $this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); - $this->field->save(); + $this->field_config['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); + $this->field_config->save(); $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist'); $this->assertTrue(empty($form[$this->fieldName][$langcode][2]), 'Option 2 does not exist'); @@ -80,9 +81,9 @@ function testUpdateAllowedValues() { $this->assertTrue(!empty($form[$this->fieldName][$langcode][20]), 'Option 20 exists'); // Options are reset when a new field with the same name is created. - $this->field->delete(); - entity_create('field_entity', $this->fieldDefinition)->save(); - entity_create('field_instance', array( + $this->field_config->delete(); + entity_create('field_config', $this->fieldDefinition)->save(); + entity_create('field_instance_config', array( 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index d34f178..68d3988 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -258,11 +258,11 @@ function testOptionsTrimmedValuesText() { */ protected function createOptionsField($type) { // Create a test field and instance. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => $type, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => $this->type, diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php index 748ee6e..e5ae075 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php @@ -39,16 +39,16 @@ class OptionsFieldUnitTestBase extends FieldUnitTestBase { /** * The list field used in the test. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ - protected $field; + protected $field_config; /** * The list field instance used in the test. * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + * @var \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig */ - protected $instance; + protected $field_instance_config; /** * {@inheritdoc} @@ -65,16 +65,16 @@ public function setUp() { 'allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'), ), ); - $this->field = entity_create('field_entity', $this->fieldDefinition); - $this->field->save(); + $this->field_config = entity_create('field_config', $this->fieldDefinition); + $this->field_config->save(); $instance = array( 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - $this->instance = entity_create('field_instance', $instance); - $this->instance->save(); + $this->field_instance_config = entity_create('field_instance_config', $instance); + $this->field_instance_config->save(); entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->fieldName, array( diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index dbc1876..b9fcee6 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -25,21 +25,21 @@ class OptionsWidgetsTest extends FieldTestBase { /** * A field with cardinality 1 to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $card_1; /** * A field with cardinality 2 to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $card_2; /** * A boolean field to use in this test class. * - * @var \Drupal\field\Plugin\Core\Entity\Field + * @var \Drupal\field\Plugin\Core\Entity\FieldConfig */ protected $bool; @@ -62,8 +62,8 @@ public static function getInfo() { function setUp() { parent::setUp(); - // Field with cardinality 1. - $this->card_1 = entity_create('field_entity', array( + // FieldConfig with cardinality 1. + $this->card_1 = entity_create('field_config', array( 'field_name' => 'card_1', 'type' => 'list_integer', 'cardinality' => 1, @@ -74,8 +74,8 @@ function setUp() { )); $this->card_1->save(); - // Field with cardinality 2. - $this->card_2 = entity_create('field_entity', array( + // FieldConfig with cardinality 2. + $this->card_2 = entity_create('field_config', array( 'field_name' => 'card_2', 'type' => 'list_integer', 'cardinality' => 2, @@ -87,7 +87,7 @@ function setUp() { $this->card_2->save(); // Boolean field. - $this->bool = entity_create('field_entity', array( + $this->bool = entity_create('field_config', array( 'field_name' => 'bool', 'type' => 'list_boolean', 'cardinality' => 1, @@ -107,7 +107,7 @@ function setUp() { */ function testRadioButtons() { // Create an instance of the 'single value' field. - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->card_1->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -166,7 +166,7 @@ function testRadioButtons() { */ function testCheckBoxes() { // Create an instance of the 'multiple values' field. - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->card_2->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -258,7 +258,7 @@ function testCheckBoxes() { */ function testSelectListSingle() { // Create an instance of the 'single value' field. - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->card_1->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -360,7 +360,7 @@ function testSelectListSingle() { */ function testSelectListMultiple() { // Create an instance of the 'multiple values' field. - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->card_2->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -482,7 +482,7 @@ function testSelectListMultiple() { */ function testOnOffCheckbox() { // Create an instance of the 'boolean' field. - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->bool->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -537,7 +537,7 @@ function testOnOffCheckbox() { $fieldUpdate = $this->bool; $fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue'); $fieldUpdate->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->bool['field_name'], 'entity_type' => 'node', 'bundle' => 'page', diff --git a/core/modules/options/options.module b/core/modules/options/options.module index e6ebdbe..0df510e 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -8,7 +8,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; -use Drupal\field\FieldInterface; +use Drupal\field\FieldConfigInterface; use Drupal\field\FieldUpdateForbiddenException; /** @@ -214,16 +214,16 @@ function options_field_settings_form_value_boolean_allowed_values($element, $inp } /** - * Implements hook_ENTITY_TYPE_update() for 'field_entity'. + * Implements hook_ENTITY_TYPE_update() for 'field_config'. */ -function options_field_entity_update(FieldInterface $field) { +function options_field_entity_update(FieldConfigInterface $field_config) { drupal_static_reset('options_allowed_values'); } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_entity'. + * Implements hook_ENTITY_TYPE_delete() for 'field_config'. */ -function options_field_entity_delete(FieldInterface $field) { +function options_field_entity_delete(FieldConfigInterface $field_config) { drupal_static_reset('options_allowed_values'); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php index 78c91ca..25dacd4 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php @@ -153,7 +153,7 @@ function testNodeTeaser() { * @todo Move this to TaxonomyTestBase, like the other field modules. */ protected function createTaxonomyTermReferenceField($field_name, $vocabulary) { - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -166,7 +166,7 @@ protected function createTaxonomyTermReferenceField($field_name, $vocabulary) { ), ), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'article', diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php index 48d0293..237178f 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.php @@ -34,7 +34,7 @@ protected function setUp() { parent::setUp(); // Create the test field. - entity_create('field_entity', array( + entity_create('field_config', array( 'settings' => array( 'target_type' => 'entity_test_mulrev', ), @@ -43,7 +43,7 @@ protected function setUp() { ))->save(); // Create the test field instance. - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test_mulrev', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test_mulrev', diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php index 74fa8d9..8afb242 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. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test_text', 'type' => 'text', 'cardinality' => 1, 'translatable' => FALSE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test_mulrev', 'field_name' => 'field_test_text', 'bundle' => 'entity_test_mulrev', diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php index a7be5be..531a273 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php @@ -231,12 +231,12 @@ function testEnableModulesFixedList() { 'bundle' => 'entity_test', 'mode' => 'default', )); - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => 'test_field', 'type' => 'test_field' )); $field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 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 f15f382..39e6a9c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php @@ -34,12 +34,12 @@ function setUp() { // Create a multi-valued field for 'page' nodes to use for Ajax testing. $field_name = 'field_ajax_test'; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page', 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 faa7090..89fa2c6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryAggregateTest.php @@ -61,12 +61,12 @@ public function setUp() { // Add some fieldapi fields to be used in the test. for ($i = 1; $i <= 2; $i++) { $field_name = 'field_test_' . $i; - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $field_name, 'type' => 'number_integer', 'cardinality' => 2, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 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 71b8141..ffea7f4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php @@ -85,9 +85,9 @@ public function setUp() { 'type' => 'taxonomy_term_reference', ); $field['settings']['allowed_values']['vocabulary'] = $vocabulary->id(); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); // Third, create the instance. - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test', 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 284526f..6e6af14 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -62,7 +62,7 @@ function setUp() { $figures = drupal_strtolower($this->randomName()); $greetings = drupal_strtolower($this->randomName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'field_name' => $field_name, 'type' => $field_type, 'cardinality' => 2, @@ -80,7 +80,7 @@ function setUp() { } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle)); entity_test_create_bundle($bundle); foreach ($fields as $field) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field->id(), 'entity_type' => 'entity_test_mulrev', 'bundle' => $bundle, @@ -411,7 +411,7 @@ protected function testCount() { // can test whether cross entity type fields produce the correct query. $field_name = $this->figures; $bundle = $this->randomName(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => $bundle, 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 15d6fc3..6d385cc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -51,7 +51,7 @@ function setUp() { // Create a translatable test field. $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4, @@ -61,7 +61,7 @@ function setUp() { // Create instance in all entity variations. foreach (entity_test_entity_types() as $entity_type) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, @@ -455,7 +455,7 @@ function testEntityTranslationAPI() { // Check that per-language defaults are properly populated. $entity = $this->reloadEntity($entity); $instance_id = implode('.', array($entity->entityType(), $entity->bundle(), $this->field_name)); - $instances = $this->entityManager->getStorageController('field_instance')->loadMultiple(array($instance_id)); + $instances = $this->entityManager->getStorageController('field_instance_config')->loadMultiple(array($instance_id)); $instance = reset($instances); $instance['default_value_function'] = 'entity_test_field_default_value'; $instance->save(); 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 cc6546a..f6f85f7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php @@ -33,13 +33,13 @@ function setUp() { parent::setUp(); // Auto-create a field for testing. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'test_multiple', 'type' => 'text', 'cardinality' => -1, 'translatable' => FALSE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'user', 'field_name' => 'test_multiple', 'bundle' => 'user', 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 c580e88..0410812 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, ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', 'page', 'default') ->setComponent($field_name, array('type' => 'text_test')) ->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php index dd13cf9..a656028 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -216,7 +216,7 @@ function testFieldUpgradeToConfig() { 'entity_id' => 2, 'revision_id' => 2, )); - field_attach_load('node', array(2 => $entity), FIELD_LOAD_CURRENT, array('instance' => entity_create('field_instance', $deleted_instance))); + field_attach_load('node', array(2 => $entity), FIELD_LOAD_CURRENT, array('instance' => entity_create('field_instance_config', $deleted_instance))); $deleted_value = $entity->get('test_deleted_field'); $this->assertEqual($deleted_value[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Some deleted value'); @@ -229,4 +229,5 @@ function testFieldUpgradeToConfig() { $this->drupalPost('node/add/article', $edit, 'Save and publish'); $this->assertText($value); } + } 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 d6f1b34..4195e0c 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.install +++ b/core/modules/system/tests/modules/entity_test/entity_test.install @@ -10,7 +10,7 @@ */ function entity_test_install() { // Auto-create a field for testing. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test_text', 'type' => 'text', 'cardinality' => 1, @@ -24,7 +24,7 @@ function entity_test_install() { 'entity_test_mulrev', ); foreach ($entity_types as $entity_type) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => $entity_type, 'field_name' => 'field_test_text', 'bundle' => $entity_type, diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 05498f7..01a56a4 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -7,8 +7,8 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\entity\Plugin\Core\Entity\EntityFormDisplay; -use Drupal\field\Plugin\Core\Entity\Field; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Core\Entity\FieldConfig; +use Drupal\field\Plugin\Core\Entity\FieldInstanceConfig; /** * Filter that limits test entity list to revisable ones. @@ -468,15 +468,16 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity the field belongs to. - * @param \Drupal\field\Plugin\Core\Entity\Field $field + * @param \Drupal\field\Plugin\Core\Entity\FieldConfig $field_config * The field for which default values should be provided. - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance + * @param \Drupal\field\Plugin\Core\Entity\FieldInstanceConfig $field_instance_config * The field instance for which default values should be provided. * @param string $langcode * The field language code to fill-in with the default value. + * @return array */ -function entity_test_field_default_value(EntityInterface $entity, Field $field, FieldInstance $instance, $langcode) { - return array(array('value' => $field['field_name'] . '_' . $langcode)); +function entity_test_field_default_value(EntityInterface $entity, FieldConfig $field_config, FieldInstanceConfig $field_instance_config, $langcode) { + return array(array('value' => $field_config['field_name'] . '_' . $langcode)); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index c9b8078..f27c376 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -37,7 +37,7 @@ function setUp() { $this->vocabulary = $this->createVocabulary(); $this->field_name = 'taxonomy_' . $this->vocabulary->id(); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -51,7 +51,7 @@ function setUp() { ), )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'bundle' => 'article', 'entity_type' => 'node', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php index 2308f63..c58a2ad 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -44,7 +44,7 @@ public function setUp() { )); $vocabulary->save(); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test_taxonomy', 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -57,7 +57,7 @@ public function setUp() { ), ), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_taxonomy', 'bundle' => 'entity_test', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index c19ce9d..dfeb08e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -42,7 +42,7 @@ function setUp() { // Set up a field and instance. $this->field_name = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -59,7 +59,7 @@ function setUp() { ), ) ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index e893001..d3ce8f3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -45,7 +45,7 @@ function setUp() { // Setup a field and instance. $this->field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -58,7 +58,7 @@ function setUp() { ) )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 8fa30c3..f46b1eb 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -33,7 +33,7 @@ function setUp() { $this->vocabulary = $this->createVocabulary(); $this->field_name_1 = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name_1, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -46,7 +46,7 @@ function setUp() { ), ), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name_1, 'bundle' => 'article', 'entity_type' => 'node', @@ -63,7 +63,7 @@ function setUp() { ->save(); $this->field_name_2 = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name_2, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -76,7 +76,7 @@ function setUp() { ), ), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name_2, 'bundle' => 'article', 'entity_type' => 'node', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 9dbf118..84d09b1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -41,9 +41,9 @@ function setUp() { ), ), ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => 'taxonomy_' . $this->vocabulary->id(), 'bundle' => 'article', 'entity_type' => 'node', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index 622eae7..a9a9391 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -29,7 +29,7 @@ function setUp() { $this->vocabulary = $this->createVocabulary(); $this->langcode = Language::LANGCODE_NOT_SPECIFIED; $this->field_name = 'taxonomy_' . $this->vocabulary->id(); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -43,7 +43,7 @@ function setUp() { ), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'bundle' => 'article', 'entity_type' => 'node', 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 e7c7031..91b34bb 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php @@ -77,7 +77,7 @@ protected function mockStandardInstall() { )); $this->vocabulary->save(); $this->field_name = 'field_' . $this->vocabulary->id(); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', // Set cardinality to unlimited for tagging. @@ -91,7 +91,7 @@ protected function mockStandardInstall() { ), ), ))->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'label' => 'Tags', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index fec21c3..1f449ac 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -154,11 +154,11 @@ function testTaxonomyVocabularyLoadMultiple() { */ function testTaxonomyVocabularyChangeMachineName() { // Add a field instance to the vocabulary. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test', 'type' => 'test_field', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_test', 'entity_type' => 'taxonomy_term', 'bundle' => $this->vocabulary->id(), @@ -191,14 +191,14 @@ function testUninstallReinstall() { 'type' => 'text', 'cardinality' => 4 ); - entity_create('field_entity', $this->field_definition)->save(); + entity_create('field_config', $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', ); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); module_disable(array('taxonomy')); require_once DRUPAL_ROOT . '/core/includes/install.inc'; @@ -211,7 +211,7 @@ function testUninstallReinstall() { // an instance of this field on the same bundle name should be successful. $this->vocabulary->enforceIsNew(); $this->vocabulary->save(); - entity_create('field_entity', $this->field_definition)->save(); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_config', $this->field_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); } } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 860cde3..2be0417 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -6,7 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Implements hook_uninstall(). @@ -357,7 +357,7 @@ function taxonomy_update_8007() { $field_config = config($config_name); // Only update taxonomy reference fields that use the default SQL storage. if ($field_config->get('type') == 'taxonomy_term_reference' && $field_config->get('storage.type') == 'field_sql_storage') { - $field = new Field($field_config->get()); + $field = new FieldConfig($field_config->get()); $tables = array( _field_sql_storage_tablename($field), diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php index c7725d9..b5e59d2 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php @@ -10,7 +10,7 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Plugin implementation of the 'telephone' field type. @@ -36,7 +36,7 @@ class TelephoneItem extends ConfigFieldItemBase { /** * {@inheritdoc} */ - public static function schema(Field $field) { + public static function schema(FieldConfig $field_config) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php index 6158f07..e279814 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php +++ b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php @@ -53,11 +53,11 @@ function setUp() { function testTelephoneField() { // Add the telepone field to the article content type. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_telephone', 'type' => 'telephone', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_telephone', 'label' => 'Telephone Number', 'entity_type' => 'node', diff --git a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php index bd3633b..5fa7b9f 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php +++ b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php @@ -35,11 +35,11 @@ public function setUp() { parent::setUp(); // Create a telephone field and instance for validation. - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => 'field_test', 'type' => 'telephone', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php index 26326fc..11cfd09 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Plugin implementation of the 'text' field type. @@ -34,12 +34,12 @@ class TextItem extends TextItemBase { /** * {@inheritdoc} */ - public static function schema(Field $field) { + public static function schema(FieldConfig $field_config) { return array( 'columns' => array( 'value' => array( 'type' => 'varchar', - 'length' => $field->settings['max_length'], + 'length' => $field_config->settings['max_length'], 'not null' => FALSE, ), 'format' => array( @@ -65,7 +65,7 @@ public static function schema(Field $field) { */ public function settingsForm(array $form, array &$form_state) { $element = array(); - $field = $this->getInstance()->getField(); + $field = $this->getInstance()->getFieldConfig(); $element['max_length'] = array( '#type' => 'number', diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index 80c93b3..69ed0c3 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -74,8 +74,8 @@ public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - if (!empty($this->getInstance()->getField()->settings['max_length'])) { - $max_length = $this->getInstance()->getField()->settings['max_length']; + if (!empty($this->getInstance()->getFieldConfig()->settings['max_length'])) { + $max_length = $this->getInstance()->getFieldConfig()->settings['max_length']; $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( 'Length' => array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php index be86655..bb72699 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Plugin implementation of the 'text_long' field type. @@ -31,7 +31,7 @@ class TextLongItem extends TextItemBase { /** * {@inheritdoc} */ - public static function schema(Field $field) { + public static function schema(FieldConfig $field_config) { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php index 4d9030d..0751d77 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; -use Drupal\field\Plugin\Core\Entity\Field; +use Drupal\field\Plugin\Core\Entity\FieldConfig; /** * Plugin implementation of the 'text_with_summary' field type. @@ -64,7 +64,7 @@ public function getPropertyDefinitions() { /** * {@inheritdoc} */ - public static function schema(Field $field) { + public static function schema(FieldConfig $field_config) { return array( 'columns' => array( 'value' => array( @@ -110,8 +110,8 @@ public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - if (!empty($this->getInstance()->getField()->settings['max_length'])) { - $max_length = $this->getInstance()->getField()->settings['max_length']; + if (!empty($this->getInstance()->getFieldConfig()->settings['max_length'])) { + $max_length = $this->getInstance()->getFieldConfig()->settings['max_length']; $constraints[] = $constraint_manager->create('ComplexData', array( 'summary' => array( 'Length' => array( 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 0a2b900..c03f693 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 = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => $this->field_type, 'settings' => $this->field_settings, )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'entity_type' => $this->entity_type, 'bundle' => $this->bundle, 'field_name' => $this->field_name, diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index c349d6d..97f8c79 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -49,7 +49,7 @@ function setUp() { function testTextFieldValidation() { // Create a field with settings to validate. $max_length = 3; - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'text', 'settings' => array( @@ -57,7 +57,7 @@ function testTextFieldValidation() { ) )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -92,12 +92,12 @@ function _testTextfieldWidgets($field_type, $widget_type) { // Setup a field and instance $entity_type = 'entity_test'; $this->field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => $field_type )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -160,12 +160,12 @@ function testTextfieldWidgetsFormatted() { function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Setup a field and instance $this->field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => $field_type )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 32dc5cc..6651b85 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -191,17 +191,17 @@ function testRegistrationDefaultValues() { } /** - * Tests Field API fields on user registration forms. + * Tests FieldConfig API fields on user registration forms. */ function testRegistrationWithUserFields() { // Create a field, and an instance on 'user' entity type. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'type' => 'test_field', 'field_name' => 'test_user_field', 'cardinality' => 1, )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_user_field', 'entity_type' => 'user', 'label' => 'Some user field', diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 37dc770..984b944 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -279,7 +279,7 @@ function user_install_picture_field() { 'default_image' => FALSE, ), ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => 'user_picture', @@ -299,7 +299,7 @@ function user_install_picture_field() { 'default_image' => 0, ), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Assign form display settings for the 'default' view mode. entity_get_form_display('user', 'user', 'default') diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index 1fa8689..9a7da31 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -61,7 +61,7 @@ protected function setUp() { // Setup a field and instance. $this->field_name = drupal_strtolower($this->randomName()); - entity_create('field_entity', array( + entity_create('field_config', array( 'field_name' => $this->field_name, 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -73,7 +73,7 @@ protected function setUp() { ), ) ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page', 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 2f870d8..bf2e8c3 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -55,7 +55,7 @@ function setUp() { $this->tag_vocabulary->save(); // Create the tag field itself. - $this->tag_field = entity_create('field_entity', array( + $this->tag_field = entity_create('field_config', array( 'field_name' => 'field_views_testing_tags', 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -77,7 +77,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => $this->node_type_with_tags->type, ); - entity_create('field_instance', $this->tag_instance)->save(); + entity_create('field_instance_config', $this->tag_instance)->save(); entity_get_form_display('node', $this->node_type_with_tags->type, 'default') ->setComponent('field_views_testing_tags', array( @@ -189,7 +189,7 @@ function testTaggedWithByNodeType() { // "tagged with" form element should not appear for it too. $instance = $this->tag_instance; $instance['bundle'] = $this->node_type_without_tags->type; - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', $this->node_type_without_tags->type, 'default') ->setComponent('field_views_testing_tags', array( 'type' => 'taxonomy_autocomplete', diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 85aecf9..d66c076 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -16,7 +16,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\views\Plugin\Core\Entity\View; use Drupal\views\Views; -use Drupal\field\FieldInstanceInterface; +use Drupal\field\FieldInstanceConfigInterface; /** * Implements hook_forms(). @@ -647,25 +647,25 @@ function views_language_list($field = 'name', $flags = Language::STATE_ALL) { } /** - * Implements hook_ENTITY_TYPE_create() for 'field_instance'. + * Implements hook_ENTITY_TYPE_create() for 'field_instance_config'. */ -function views_field_instance_create(FieldInstanceInterface $field_instance) { +function views_field_instance_config_create(FieldInstanceConfigInterface $field_instance_config) { cache('views_info')->deleteAll(); cache('views_results')->deleteAll(); } /** - * Implements hook_ENTITY_TYPE_update() for 'field_instance'. + * Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. */ -function views_field_instance_update(FieldInstanceInterface $field_instance) { +function views_field_instance_config_update(FieldInstanceConfigInterface $field_instance_config) { cache('views_info')->deleteAll(); cache('views_results')->deleteAll(); } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_instance'. + * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ -function views_field_instance_delete(FieldInstanceInterface $field_instance) { +function views_field_instance_config_delete(FieldInstanceConfigInterface $field_instance_config) { cache('views_info')->deleteAll(); cache('views_results')->deleteAll(); } diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index 87ec22a..3aa5455 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -93,7 +93,7 @@ ), ), ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $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(), ); } - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } $parents = array(); // Vocabularies without hierarchy get one term, single parent vocabularies get