diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 00caf8e..b833a01 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -89,8 +89,7 @@ function custom_block_add_body_field($block_type_id, $label = 'Body') { } if (empty($instance)) { $instance = entity_create('field_instance_config', array( - 'field_name' => 'body', - 'entity_type' => 'custom_block', + 'field' => $field, 'bundle' => $block_type_id, 'label' => $label, 'settings' => array('display_summary' => FALSE), diff --git a/core/modules/block/custom_block/src/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/src/Tests/CustomBlockFieldTest.php index 5c7d46b..63a8911 100644 --- a/core/modules/block/custom_block/src/Tests/CustomBlockFieldTest.php +++ b/core/modules/block/custom_block/src/Tests/CustomBlockFieldTest.php @@ -72,8 +72,7 @@ public function testBlockFields() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field->getName(), - 'entity_type' => 'custom_block', + 'field' => $this->field, 'bundle' => 'link', 'settings' => array( 'title' => DRUPAL_OPTIONAL, diff --git a/core/modules/config/src/Tests/ConfigExportImportUITest.php b/core/modules/config/src/Tests/ConfigExportImportUITest.php index b087124..baa12f5 100644 --- a/core/modules/config/src/Tests/ConfigExportImportUITest.php +++ b/core/modules/config/src/Tests/ConfigExportImportUITest.php @@ -79,8 +79,7 @@ public function testExportImport() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => 'node', + 'field' => $this->field, 'bundle' => $this->content_type->type, ))->save(); entity_get_form_display('node', $this->content_type->type, 'default') diff --git a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php index 28216aa..4308ca7 100644 --- a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php @@ -53,8 +53,7 @@ protected function setUp() { ))->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => 'contact_message', + 'field' => $this->field, 'bundle' => 'contact_message', ))->save(); diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index 0b5caf0..62b69cb 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -66,8 +66,7 @@ function setUp() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'required' => TRUE, )); @@ -305,8 +304,7 @@ function testDefaultValue() { $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field->name, - 'entity_type' => 'node', + 'field' => $field, 'bundle' => 'date_content', )); $instance->save(); diff --git a/core/modules/datetime/src/Tests/DateTimeItemTest.php b/core/modules/datetime/src/Tests/DateTimeItemTest.php index e709902..79f0781 100644 --- a/core/modules/datetime/src/Tests/DateTimeItemTest.php +++ b/core/modules/datetime/src/Tests/DateTimeItemTest.php @@ -43,8 +43,7 @@ public function setUp() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'settings' => array( 'default_value' => 'blank', diff --git a/core/modules/entity/src/Tests/EntityDisplayTest.php b/core/modules/entity/src/Tests/EntityDisplayTest.php index 250f5e0..26e47d6 100644 --- a/core/modules/entity/src/Tests/EntityDisplayTest.php +++ b/core/modules/entity/src/Tests/EntityDisplayTest.php @@ -153,8 +153,7 @@ public function testFieldComponent() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'entity_test', )); $instance->save(); @@ -328,8 +327,7 @@ public function testDeleteFieldInstance() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'entity_test', )); $instance->save(); diff --git a/core/modules/entity/src/Tests/EntityFormDisplayTest.php b/core/modules/entity/src/Tests/EntityFormDisplayTest.php index eb0477f..aa47ca6 100644 --- a/core/modules/entity/src/Tests/EntityFormDisplayTest.php +++ b/core/modules/entity/src/Tests/EntityFormDisplayTest.php @@ -64,8 +64,7 @@ public function testFieldComponent() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'entity_test', )); $instance->save(); @@ -192,8 +191,7 @@ public function testDeleteFieldInstance() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'entity_test', )); $instance->save(); diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php index f999bf0..ff29c03 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php @@ -56,8 +56,7 @@ function testEntityReferenceDefaultValue() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => 'node', + 'field' => $this->field, 'bundle' => 'reference_content', 'settings' => array( 'handler' => 'default', diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php index 19f5035..f33e759 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php @@ -74,8 +74,7 @@ public function testNodeHandler() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', @@ -217,8 +216,7 @@ public function testUserHandler() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', @@ -363,8 +361,7 @@ public function testCommentHandler() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php index 06f0a69..43ce3a2 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php @@ -66,7 +66,7 @@ public function testSort() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_field', + 'field' => $field, 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', 'settings' => array( diff --git a/core/modules/entity_reference/src/Tests/Views/SelectionTest.php b/core/modules/entity_reference/src/Tests/Views/SelectionTest.php index a8c97cf..56328a3 100644 --- a/core/modules/entity_reference/src/Tests/Views/SelectionTest.php +++ b/core/modules/entity_reference/src/Tests/Views/SelectionTest.php @@ -52,8 +52,7 @@ public function testSelectionHandler() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'views', diff --git a/core/modules/field/src/Entity/FieldInstanceConfig.php b/core/modules/field/src/Entity/FieldInstanceConfig.php index 0292ec9..9f6f912 100644 --- a/core/modules/field/src/Entity/FieldInstanceConfig.php +++ b/core/modules/field/src/Entity/FieldInstanceConfig.php @@ -211,36 +211,47 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi /** * 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: The name of the field this is an instance of. This only - * supports non-deleted fields. - * - field_uuid: (optional) The uuid of the field this is an instance of. - * If present and the instance is marked as 'deleted', this has priority - * over the 'field_name' value for retrieving the related field. - * - 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. * + * @param array $values + * An array of field instance properties, keyed by property name. The field + * this is an instance of can be specified either with: + * - field: the FieldConfigInterface object, + * or by referring to an existing field in the current configuration with: + * - field_name: The field name. + * - entity_type: The entity type. + * Additionally, a 'bundle' property is required to indicate the entity + * bundle to which the instance is attached to. Other array elements will be + * used to set the corresponding properties on the class; see the class + * property documentation for details. + * * @see entity_create() * * @ingroup field_crud */ public function __construct(array $values, $entity_type = 'field_instance_config') { - // Check required properties. - if (empty($values['field_name'])) { - throw new FieldException('Attempt to create an instance of a field without a field_name.'); + // Allow either an injected FieldConfig object, or a field_name and + // entity_type. + if (isset($values['field'])) { + if (!$values['field'] instanceof FieldConfigInterface) { + throw new FieldException('Attempt to create a configurable instance of a non-configurable field.'); + } + $field = $values['field']; + $values['field_name'] = $field->getName(); + $values['entity_type'] = $field->getTargetEntityTypeId(); + $this->field = $field; } - if (empty($values['entity_type'])) { - throw new FieldException(String::format('Attempt to create an instance of field @field_name without an entity_type.', array('@field_name' => $values['field_name']))); + else { + if (empty($values['field_name'])) { + throw new FieldException('Attempt to create an instance of a field without a field_name.'); + } + if (empty($values['entity_type'])) { + throw new FieldException(String::format('Attempt to create an instance of field @field_name without an entity_type.', array('@field_name' => $values['field_name']))); + } } + // 'bundle' is required in either case. if (empty($values['bundle'])) { throw new FieldException(String::format('Attempt to create an instance of field @field_name without a bundle.', array('@field_name' => $values['field_name']))); } @@ -471,31 +482,14 @@ public static function postDelete(EntityStorageInterface $storage, array $instan */ public function getField() { if (!$this->field) { - // Load the corresponding field. - // - If the instance is deleted (case of field purge), load the field - // based on the UUID. - // - Otherwise (regular case), fetch the field from the EntityManager - // registry. - if (!empty($this->deleted)) { - if ($fields = entity_load_multiple_by_properties('field_config', array('uuid' => $this->field_uuid, 'include_deleted' => TRUE))) { - $field = current($fields); - } - else { - throw new FieldException(String::format('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); - } + $fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); + if (!isset($fields[$this->field_name])) { + throw new FieldException(String::format('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); } - else { - $fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); - if (!isset($fields[$this->field_name])) { - throw new FieldException(String::format('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); - } - if (!$fields[$this->field_name] instanceof FieldConfigInterface) { - throw new FieldException(String::format('Attempt to create a configurable instance of non-configurable field @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); - } - $field = $fields[$this->field_name]; + if (!$fields[$this->field_name] instanceof FieldConfigInterface) { + throw new FieldException(String::format('Attempt to create a configurable instance of non-configurable field @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); } - - $this->field = $field; + $this->field = $fields[$this->field_name]; } return $this->field; diff --git a/core/modules/field/src/FieldConfigStorage.php b/core/modules/field/src/FieldConfigStorage.php index b268bb7..a8d6550 100644 --- a/core/modules/field/src/FieldConfigStorage.php +++ b/core/modules/field/src/FieldConfigStorage.php @@ -101,18 +101,18 @@ public function loadByProperties(array $conditions = array()) { if (isset($conditions['entity_type']) && isset($conditions['field_name'])) { // Optimize for the most frequent case where we do have a specific ID. $id = $conditions['entity_type'] . $conditions['field_name']; - $fields = $this->entityManager->getStorage($this->entityTypeId)->loadMultiple(array($id)); + $fields = $this->loadMultiple(array($id)); } else { // No specific ID, we need to examine all existing fields. - $fields = $this->entityManager->getStorage($this->entityTypeId)->loadMultiple(); + $fields = $this->loadMultiple(); } // Merge deleted fields (stored in state) if needed. if ($include_deleted) { $deleted_fields = $this->state->get('field.field.deleted') ?: array(); foreach ($deleted_fields as $id => $config) { - $fields[$id] = $this->entityManager->getStorage($this->entityTypeId)->create($config); + $fields[$id] = $this->create($config); } } diff --git a/core/modules/field/src/FieldInstanceConfigStorage.php b/core/modules/field/src/FieldInstanceConfigStorage.php index 6f1edd4..8dfd30c 100644 --- a/core/modules/field/src/FieldInstanceConfigStorage.php +++ b/core/modules/field/src/FieldInstanceConfigStorage.php @@ -108,18 +108,23 @@ public function loadByProperties(array $conditions = array()) { if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) { // Optimize for the most frequent case where we do have a specific ID. $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name']; - $instances = $this->entityManager->getStorage($this->entityTypeId)->loadMultiple(array($id)); + $instances = $this->loadMultiple(array($id)); } else { // No specific ID, we need to examine all existing instances. - $instances = $this->entityManager->getStorage($this->entityTypeId)->loadMultiple(); + $instances = $this->loadMultiple(); } // Merge deleted instances (stored in state) if needed. if ($include_deleted) { $deleted_instances = $this->state->get('field.instance.deleted') ?: array(); + $deleted_fields = $this->state->get('field.field.deleted') ?: array(); foreach ($deleted_instances as $id => $config) { - $instances[$id] = $this->entityManager->getStorage($this->entityTypeId)->create($config); + // If the field itself is deleted, inject it directly in the instance. + if (isset($deleted_fields[$config['field_uuid']])) { + $config['field'] = $this->entityManager->getStorage('field_config')->create($deleted_fields[$config['field_uuid']]); + } + $instances[$id] = $this->create($config); } } diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php index 542139e..41636e6 100644 --- a/core/modules/field/src/Tests/BulkDeleteTest.php +++ b/core/modules/field/src/Tests/BulkDeleteTest.php @@ -136,8 +136,7 @@ function setUp() { foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { entity_create('field_instance_config', array( - 'field_name' => $field->name, - 'entity_type' => $this->entity_type, + 'field' => $field, 'bundle' => $bundle, ))->save(); } diff --git a/core/modules/field/src/Tests/CrudTest.php b/core/modules/field/src/Tests/CrudTest.php index be546ab..782897c 100644 --- a/core/modules/field/src/Tests/CrudTest.php +++ b/core/modules/field/src/Tests/CrudTest.php @@ -396,7 +396,7 @@ function testUpdateField() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'field_update', + 'field' => $field, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); diff --git a/core/modules/field/src/Tests/Email/EmailFieldTest.php b/core/modules/field/src/Tests/Email/EmailFieldTest.php index 4197798..02f707d 100644 --- a/core/modules/field/src/Tests/Email/EmailFieldTest.php +++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php @@ -67,8 +67,7 @@ function testEmailField() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', )); $this->instance->save(); diff --git a/core/modules/field/src/Tests/FieldEntityCountTest.php b/core/modules/field/src/Tests/FieldEntityCountTest.php index f08cee4..b55619f 100644 --- a/core/modules/field/src/Tests/FieldEntityCountTest.php +++ b/core/modules/field/src/Tests/FieldEntityCountTest.php @@ -40,8 +40,7 @@ public function testEntityCountAndHasData() { )); $field->save(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_int', + 'field' => $field, 'bundle' => 'entity_test', ))->save(); diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php index 40d925f..b7ebce8 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php @@ -54,8 +54,7 @@ public function testImportDeleteUninstall() { $unrelated_field->save(); $unrelated_field_uuid = $unrelated_field->uuid(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_int', + 'field' => $unrelated_field, 'bundle' => 'entity_test', ))->save(); @@ -68,8 +67,7 @@ public function testImportDeleteUninstall() { $field->save(); $field_uuid = $field->uuid(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_test', + 'field' => $field, 'bundle' => 'entity_test', ))->save(); @@ -131,8 +129,7 @@ public function testImportAlreadyDeletedUninstall() { $field->save(); $field_uuid = $field->uuid(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_test', + 'field' => $field, 'bundle' => 'entity_test', ))->save(); diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php index 93bdb75..c8f6db0 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php @@ -51,8 +51,7 @@ public function testImportDeleteUninstall() { $field->save(); $tel_field_uuid = $field->uuid(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_tel', + 'field' => $field, 'bundle' => 'entity_test', ))->save(); @@ -65,8 +64,7 @@ public function testImportDeleteUninstall() { $text_field->save(); $text_field_uuid = $field->uuid(); entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => 'field_text', + 'field' => $text_field, 'bundle' => 'entity_test', ))->save(); diff --git a/core/modules/field/src/Tests/FieldInstanceCrudTest.php b/core/modules/field/src/Tests/FieldInstanceCrudTest.php index 0acb7c7..2a0385b 100644 --- a/core/modules/field/src/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/src/Tests/FieldInstanceCrudTest.php @@ -57,8 +57,7 @@ function setUp() { $this->field = entity_create('field_config', $this->field_definition); $this->field->save(); $this->instance_definition = array( - 'field_name' => $this->field->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', ); } @@ -102,7 +101,10 @@ function testCreateFieldInstance() { // Check that the specified field exists. try { $this->instance_definition['field_name'] = $this->randomName(); - entity_create('field_instance_config', $this->instance_definition)->save(); + entity_create('field_instance_config', array( + 'field_name' => $this->randomName(), + 'entity_type' => 'entity_test', + ))->save(); $this->fail(t('Cannot create an instance of a non-existing field.')); } catch (FieldException $e) { diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php index 457a09f..f0a6653 100644 --- a/core/modules/field/src/Tests/FieldUnitTestBase.php +++ b/core/modules/field/src/Tests/FieldUnitTestBase.php @@ -77,8 +77,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu $this->$field->save(); $this->$field_id = $this->{$field}->uuid(); $this->$instance_definition = array( - 'field_name' => $this->$field_name, - 'entity_type' => $entity_type, + 'field' => $this->$field, 'bundle' => $bundle, 'label' => $this->randomName() . '_label', 'description' => $this->randomName() . '_description', diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index ba4ebd3..334657c 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -96,7 +96,7 @@ function setUp() { function testFieldFormSingle() { $field = $this->field_single; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; 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') @@ -178,7 +178,7 @@ function testFieldFormSingle() { function testFieldFormDefaultValue() { $field = $this->field_single; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); entity_create('field_config', $field)->save(); @@ -209,7 +209,7 @@ function testFieldFormDefaultValue() { function testFieldFormSingleRequired() { $field = $this->field_single; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; $this->instance['required'] = TRUE; entity_create('field_config', $field)->save(); entity_create('field_instance_config', $this->instance)->save(); @@ -258,7 +258,7 @@ function testFieldFormSingleRequired() { function testFieldFormUnlimited() { $field = $this->field_unlimited; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; 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') @@ -344,7 +344,7 @@ function testFieldFormMultivalueWithRequiredRadio() { // Create a multivalue test field. $field = $this->field_unlimited; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; 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') @@ -391,7 +391,7 @@ function testFieldFormMultivalueWithRequiredRadio() { function testFieldFormJSAddMore() { $field = $this->field_unlimited; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; 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') @@ -452,7 +452,7 @@ function testFieldFormMultipleWidget() { // widget. $field = $this->field_multiple; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; 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') @@ -501,8 +501,7 @@ function testFieldFormAccess() { $field['entity_type'] = $entity_type; $field_name = $field['name']; $instance = $this->instance; - $instance['field_name'] = $field_name; - $instance['entity_type'] = $entity_type; + $instance['field'] = $field; $instance['bundle'] = $entity_type; entity_create('field_config', $field)->save(); entity_create('field_instance_config', $instance)->save(); @@ -590,7 +589,7 @@ function testHiddenField() { $field = $this->field_single; $field['entity_type'] = $entity_type; $field_name = $field['name']; - $this->instance['field_name'] = $field_name; + $this->instance['field'] = $field; $this->instance['default_value'] = array(0 => array('value' => 99)); $this->instance['entity_type'] = $entity_type; $this->instance['bundle'] = $entity_type; diff --git a/core/modules/field/src/Tests/TranslationTest.php b/core/modules/field/src/Tests/TranslationTest.php index b68615b..618d8a5 100644 --- a/core/modules/field/src/Tests/TranslationTest.php +++ b/core/modules/field/src/Tests/TranslationTest.php @@ -96,8 +96,7 @@ function setUp() { $this->field->save(); $this->instance_definition = array( - 'field_name' => $this->field_name, - 'entity_type' => $this->entity_type, + 'field' => $this->field, 'bundle' => 'entity_test', ); $this->instance = entity_create('field_instance_config', $this->instance_definition); @@ -149,10 +148,11 @@ function testTranslatableFieldSaveLoad() { $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); $field_definition = $this->field_definition; $field_definition['name'] = $field_name_default; - entity_create('field_config', $field_definition)->save(); + $field = entity_create('field_config', $field_definition); + $field->save(); $instance_definition = $this->instance_definition; - $instance_definition['field_name'] = $field_name_default; + $instance_definition['field'] = $field; $instance_definition['default_value'] = array(array('value' => rand(1, 127))); $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); diff --git a/core/modules/field/src/Tests/TranslationWebTest.php b/core/modules/field/src/Tests/TranslationWebTest.php index fb52e72..18b9ef2 100644 --- a/core/modules/field/src/Tests/TranslationWebTest.php +++ b/core/modules/field/src/Tests/TranslationWebTest.php @@ -73,8 +73,7 @@ function setUp() { $this->field = entity_load('field_config', $this->entity_type . '.' . $this->field_name); $instance = array( - 'field_name' => $this->field_name, - 'entity_type' => $this->entity_type, + 'field' => $this->field, 'bundle' => $this->entity_type, ); entity_create('field_instance_config', $instance)->save(); diff --git a/core/modules/field/src/Tests/Views/FieldTestBase.php b/core/modules/field/src/Tests/Views/FieldTestBase.php index eefb0d3..e5af4ab 100644 --- a/core/modules/field/src/Tests/Views/FieldTestBase.php +++ b/core/modules/field/src/Tests/Views/FieldTestBase.php @@ -81,8 +81,7 @@ function setUpFields($amount = 3) { function setUpInstances($bundle = 'page') { foreach ($this->fields as $key => $field) { $instance = array( - 'field_name' => $field->getName(), - 'entity_type' => 'node', + 'field' => $field, 'bundle' => 'page', ); $this->instances[$key] = entity_create('field_instance_config', $instance); diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index 5702719..81242db 100644 --- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php @@ -56,10 +56,9 @@ function testReEnabledField() { )); $field->save(); entity_create('field_instance_config', array( - 'field_name' => 'field_telephone', - 'label' => 'Telephone Number', - 'entity_type' => 'node', + 'field' => $field, 'bundle' => 'article', + 'label' => 'Telephone Number', ))->save(); entity_get_form_display('node', 'article', 'default') diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index 505e8a1..f634cb6 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -425,8 +425,7 @@ function testLockedField() { )); $field->save(); entity_create('field_instance_config', array( - 'field_name' => $field->name, - 'entity_type' => 'node', + 'field' => $field, 'bundle' => $this->type, ))->save(); entity_get_form_display('node', $this->type, 'default') diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index 01f7ed7..1a5f155 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -75,8 +75,7 @@ function testURLValidation() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'settings' => array( 'title' => DRUPAL_DISABLED, @@ -200,8 +199,7 @@ function testLinkTitle() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'label' => 'Read more about this entity', 'settings' => array( @@ -320,8 +318,7 @@ function testLinkFormatter() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'label' => 'Read more about this entity', 'bundle' => 'entity_test', 'settings' => array( @@ -463,8 +460,7 @@ function testLinkSeparateFormatter() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'settings' => array( 'title' => DRUPAL_OPTIONAL, diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 38e047b..67e5d90 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -391,8 +391,7 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { } if (empty($instance)) { $instance = entity_create('field_instance_config', array( - 'field_name' => 'body', - 'entity_type' => 'node', + 'field' => $field, 'bundle' => $type->id(), 'label' => $label, 'settings' => array('display_summary' => TRUE), diff --git a/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php index 4ea9fe8..7af2816 100644 --- a/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -68,8 +68,7 @@ public function setUp() { $field_private->save(); entity_create('field_instance_config', array( - 'field_name' => $field_private->name, - 'entity_type' => 'node', + 'field' => $field_private, 'bundle' => 'page', 'widget' => array( 'type' => 'options_buttons', diff --git a/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php b/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php index fc76429..6012dfc 100644 --- a/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php +++ b/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php @@ -61,8 +61,7 @@ public function setUp() { $field_private->save(); entity_create('field_instance_config', array( - 'field_name' => $field_private->name, - 'entity_type' => 'node', + 'field' => $field_private, 'bundle' => 'page', 'widget' => array( 'type' => 'options_buttons', diff --git a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php index bba78c3..272e026 100644 --- a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php +++ b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php @@ -70,8 +70,7 @@ public function setUp() { $this->field->save(); $instance = array( - 'field_name' => $this->fieldName, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', ); $this->instance = entity_create('field_instance_config', $instance); diff --git a/core/modules/options/src/Tests/OptionsWidgetsTest.php b/core/modules/options/src/Tests/OptionsWidgetsTest.php index 53067a7..bcec12c 100644 --- a/core/modules/options/src/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/src/Tests/OptionsWidgetsTest.php @@ -127,8 +127,7 @@ function setUp() { function testRadioButtons() { // Create an instance of the 'single value' field. $instance = entity_create('field_instance_config', array( - 'field_name' => $this->card_1->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->card_1, 'bundle' => 'entity_test', )); $instance->save(); @@ -185,8 +184,7 @@ function testRadioButtons() { function testCheckBoxes() { // Create an instance of the 'multiple values' field. $instance = entity_create('field_instance_config', array( - 'field_name' => $this->card_2->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->card_2, 'bundle' => 'entity_test', )); $instance->save(); @@ -275,8 +273,7 @@ function testCheckBoxes() { function testSelectListSingle() { // Create an instance of the 'single value' field. $instance = entity_create('field_instance_config', array( - 'field_name' => $this->card_1->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->card_1, 'bundle' => 'entity_test', 'required' => TRUE, )); @@ -375,8 +372,7 @@ function testSelectListSingle() { function testSelectListMultiple() { // Create an instance of the 'multiple values' field. $instance = entity_create('field_instance_config', array( - 'field_name' => $this->card_2->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->card_2, 'bundle' => 'entity_test', )); $instance->save(); @@ -496,8 +492,7 @@ function testSelectListMultiple() { function testOnOffCheckbox() { // Create an instance of the 'boolean' field. entity_create('field_instance_config', array( - 'field_name' => $this->bool->getName(), - 'entity_type' => 'entity_test', + 'field' => $this->bool, 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') diff --git a/core/modules/quickedit/src/Tests/QuickEditTestBase.php b/core/modules/quickedit/src/Tests/QuickEditTestBase.php index 9fb217c..08c1a86 100644 --- a/core/modules/quickedit/src/Tests/QuickEditTestBase.php +++ b/core/modules/quickedit/src/Tests/QuickEditTestBase.php @@ -64,8 +64,7 @@ public function createFieldWithInstance($field_name, $type, $cardinality, $label $instance = $field_name . '_instance'; $this->$instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $this->$field, 'bundle' => 'entity_test', 'label' => $label, 'description' => $label, diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 34d78f1..41347e0 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -263,8 +263,7 @@ function testEnableModulesFixedList() { )); $field->save(); entity_create('field_instance_config', array( - 'field_name' => $field->name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => 'entity_test', ))->save(); } diff --git a/core/modules/system/src/Tests/Entity/EntityQueryTest.php b/core/modules/system/src/Tests/Entity/EntityQueryTest.php index b3cb9f7..a3be1e8 100644 --- a/core/modules/system/src/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/src/Tests/Entity/EntityQueryTest.php @@ -85,8 +85,7 @@ function setUp() { entity_test_create_bundle($bundle); foreach ($fields as $field) { entity_create('field_instance_config', array( - 'field_name' => $field->name, - 'entity_type' => 'entity_test_mulrev', + 'field' => $field, 'bundle' => $bundle, ))->save(); } @@ -442,8 +441,7 @@ protected function testCount() { $field->save(); $bundle = $this->randomName(); entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => 'entity_test', + 'field' => $field, 'bundle' => $bundle, ))->save(); diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php index c252acd..e82129e 100644 --- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php @@ -80,8 +80,7 @@ function setUp() { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field_name, - 'entity_type' => $entity_type, + 'field' => $this->field, 'bundle' => $entity_type )); $this->instance->save(); @@ -306,8 +305,7 @@ function testUpdateFieldSchemaWithData() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'decimal52', - 'entity_type' => $entity_type, + 'field' => $field, 'bundle' => $entity_type, )); $instance->save(); @@ -373,8 +371,7 @@ function testFieldUpdateIndexesWithData() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => $field_name, - 'entity_type' => $entity_type, + 'field' => $field, 'bundle' => $entity_type, )); $instance->save(); diff --git a/core/modules/taxonomy/src/Tests/RssTest.php b/core/modules/taxonomy/src/Tests/RssTest.php index 709d0fa..7763080 100644 --- a/core/modules/taxonomy/src/Tests/RssTest.php +++ b/core/modules/taxonomy/src/Tests/RssTest.php @@ -53,8 +53,7 @@ function setUp() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field_name, - 'bundle' => 'article', + 'field' => $this->field, 'entity_type' => 'node', ))->save(); entity_get_form_display('node', 'article', 'default') diff --git a/core/modules/taxonomy/src/Tests/TermFieldTest.php b/core/modules/taxonomy/src/Tests/TermFieldTest.php index f61b91e..c1dfff1 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php @@ -60,8 +60,7 @@ function setUp() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') diff --git a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php index 3357d1d..924525f 100644 --- a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php @@ -76,9 +76,8 @@ function setUp() { $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'entity_type' => $this->entity_type, + 'field_name' => $this->field, 'bundle' => $this->bundle, - 'field_name' => $this->field_name, 'label' => $this->randomName(), 'settings' => $this->instance_settings, )); diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 62a2ed4..84154f3 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -58,8 +58,7 @@ function testTextFieldValidation() { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', ))->save(); @@ -98,8 +97,7 @@ function _testTextfieldWidgets($field_type, $widget_type) { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'label' => $this->randomName() . '_label', 'settings' => array( @@ -165,8 +163,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { )); $this->field->save(); entity_create('field_instance_config', array( - 'field_name' => $this->field_name, - 'entity_type' => 'entity_test', + 'field' => $this->field, 'bundle' => 'entity_test', 'label' => $this->randomName() . '_label', 'settings' => array( diff --git a/core/modules/text/src/Tests/TextWithSummaryItemTest.php b/core/modules/text/src/Tests/TextWithSummaryItemTest.php index c98245e..8928a08 100644 --- a/core/modules/text/src/Tests/TextWithSummaryItemTest.php +++ b/core/modules/text/src/Tests/TextWithSummaryItemTest.php @@ -120,8 +120,7 @@ protected function createField($entity_type) { )); $this->field->save(); $this->instance = entity_create('field_instance_config', array( - 'field_name' => $this->field->name, - 'entity_type' => $entity_type, + 'field' => $this->field, 'bundle' => $entity_type, 'settings' => array( 'text_processing' => 0, diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index a0b205c..6b239b1 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -207,8 +207,7 @@ function testRegistrationWithUserFields() { )); $field->save(); $instance = entity_create('field_instance_config', array( - 'field_name' => 'test_user_field', - 'entity_type' => 'user', + 'field' => $field, 'label' => 'Some user field', 'bundle' => 'user', 'required' => TRUE, diff --git a/core/modules/views/src/Tests/Wizard/TaggedWithTest.php b/core/modules/views/src/Tests/Wizard/TaggedWithTest.php index 175ebcb..40f231a 100644 --- a/core/modules/views/src/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/src/Tests/Wizard/TaggedWithTest.php @@ -74,8 +74,7 @@ function setUp() { // Create an instance of the tag field on one of the content types, and // configure it to display an autocomplete widget. $this->tag_instance = array( - 'field_name' => 'field_views_testing_tags', - 'entity_type' => 'node', + 'field' => $this->tag_field, 'bundle' => $this->node_type_with_tags->type, ); entity_create('field_instance_config', $this->tag_instance)->save();