diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index ad3d6ac..c84276a 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -117,7 +117,7 @@ function custom_block_entity_bundle_info() { function custom_block_add_body_field($block_type_id, $label = 'Block body') { // Add or remove the body field, as needed. $field = FieldConfig::loadByName('custom_block', 'body'); - $instance = FieldInstanceConfig::loadByName('custom_block', 'body', $block_type_id); + $instance = FieldInstanceConfig::loadByName('custom_block', $block_type_id, 'body'); if (empty($field)) { $field = entity_create('field_config', array( 'name' => 'body', diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 5c48ac6..ae97a2f 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -866,7 +866,7 @@ function content_translation_save_settings($settings) { // Store whether fields have translation enabled or not. if (!empty($bundle_settings['columns'])) { foreach ($bundle_settings['columns'] as $field_name => $column_settings) { - $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); if ($instance->isTranslatable()) { $instance->settings['translation_sync'] = $column_settings; } diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index e37e5f0..5d59210 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -93,7 +93,7 @@ function entity_reference_field_config_update(FieldConfigInterface $field) { foreach ($field->bundles() as $entity_type => $bundles) { foreach ($bundles as $bundle) { - $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); $instance->settings['handler_settings'] = array(); $instance->save(); } @@ -212,7 +212,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f // Look for or add the specified field to the requested entity bundle. $field = FieldConfig::loadByName($entity_type, $field_name); - $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); if (empty($field)) { $field = array( diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index af24a63..d1c3f26 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -236,7 +236,16 @@ public function __construct(array $values, $entity_type = 'field_instance_config if (isset($values['field_name']) && isset($values['entity_type'])) { $field = FieldConfig::loadByName($values['entity_type'], $values['field_name']); if (!$field) { - throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); + // The field might have been deleted, try to load it based on the UUID + // when present. + if (isset($values['field_uuid']) && isset($values['uuid'])) { + if ($fields = entity_load_multiple_by_properties('field_config', array('uuid' => $values['field_uuid'], 'include_deleted' => TRUE))) { + $field = current($fields); + } + } + if (!$field) { + throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); + } } $values['field_uuid'] = $field->uuid(); } diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index ab76e31..542139e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -177,7 +177,7 @@ function testDeleteFieldInstance() { $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); // Delete the instance. - $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); $instance->delete(); // The instance still exists, deleted. @@ -227,7 +227,7 @@ function testPurgeInstance() { $field = reset($this->fields); // Delete the instance. - $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); $instance->delete(); // No field hooks were called. @@ -286,7 +286,7 @@ function testPurgeField() { // Delete the first instance. $bundle = reset($this->bundles); - $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); $instance->delete(); // Assert that FieldItemInterface::delete() was not called yet. @@ -316,7 +316,7 @@ function testPurgeField() { // Delete the second instance. $bundle = next($this->bundles); - $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); $instance->delete(); // Assert that FieldItemInterface::delete() was not called yet. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 44f6ca6..24b3786 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -335,7 +335,7 @@ function testEntityCreateRenameBundle() { entity_test_rename_bundle($this->instance_definition['bundle'], $new_bundle, $entity_type); // Check that the instance definition has been updated. - $this->instance = FieldInstanceConfig::loadByName($entity_type, $this->field_name, $new_bundle); + $this->instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field->name); $this->assertIdentical($this->instance->bundle, $new_bundle, "Bundle name has been updated in the instance."); // Verify the field data is present on load. 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 7d18b49..ef8f523 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 @@ -252,7 +252,7 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string' $this->assertTrue($field->getSetting('test_field_setting') == $string, 'Field settings were found.'); // Assert instance settings. - $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); $this->assertTrue($instance->getSetting('test_instance_setting') == $string, 'Field instance settings were found.'); } @@ -324,7 +324,7 @@ function testDefaultValue() { $this->drupalPostForm($admin_path, $edit, t('Save settings')); $this->assertText("Saved $field_name configuration", 'The form was successfully submitted.'); field_info_cache_clear(); - $instance = FieldInstanceConfig::loadByName('node', $field_name, $this->type); + $instance = FieldInstanceConfig::loadByName('node', $this->type, $field_name); $this->assertEqual($instance->default_value, array(array('value' => 1)), 'The default value was correctly saved.'); // Check that the default value shows up in the form @@ -336,7 +336,7 @@ function testDefaultValue() { $this->drupalPostForm(NULL, $edit, t('Save settings')); $this->assertText("Saved $field_name configuration", 'The form was successfully submitted.'); field_info_cache_clear(); - $instance = FieldInstanceConfig::loadByName('node', $field_name, $this->type); + $instance = FieldInstanceConfig::loadByName('node', $this->type, $field_name); $this->assertEqual($instance->default_value, NULL, 'The default value was correctly saved.'); // Check that the default widget is used when the field is hidden. @@ -377,7 +377,7 @@ function testDeleteField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(FieldInstanceConfig::loadByName('node', $this->field_name, $this->type), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('node', $this->type, $this->field_name), 'Field instance was deleted.'); // Check that the field was not deleted $this->assertNotNull(FieldConfig::loadByName('node', $this->field_name), 'Field was not deleted.'); @@ -387,7 +387,7 @@ function testDeleteField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(FieldInstanceConfig::loadByName('node', $this->field_name, $type_name2), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('node', $type_name2, $this->field_name), 'Field instance was deleted.'); // Check that the field was deleted too. $this->assertNull(FieldConfig::loadByName('node', $this->field_name), 'Field was deleted.'); } @@ -556,7 +556,7 @@ function testDeleteTaxonomyField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(FieldInstanceConfig::loadByName('taxonomy_term', $this->field_name, 'tags'), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('taxonomy_term', 'tags', $this->field_name), 'Field instance was deleted.'); // Check that the field was deleted too. $this->assertNull(FieldConfig::loadByName('taxonomy_term', $this->field_name), 'Field was deleted.'); } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 1260f0e..644f6f9 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -125,7 +125,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra * Updates an existing file field with new settings. */ function updateFileField($name, $type_name, $instance_settings = array(), $widget_settings = array()) { - $instance = FieldInstanceConfig::loadByName('node', $name, $type_name); + $instance = FieldInstanceConfig::loadByName('node', $type_name, $name); $instance->settings = array_merge($instance->settings, $instance_settings); $instance->save(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 3fcaaae..416ea07 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -209,7 +209,7 @@ function testPrivateFileSetting() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); - $instance = FieldInstanceConfig::loadByName('node', $field_name, $type_name); + $instance = FieldInstanceConfig::loadByName('node', $type_name, $field_name); $test_file = $this->getTestFile('text'); diff --git a/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php index 452db65..4ae1923 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php @@ -81,7 +81,7 @@ public function testImportCreate() { // Check that the content type was created. $node_type = entity_load('node_type', $node_type_id); $this->assertTrue($node_type, 'Import node type from staging was created.'); - $this->assertFalse(FieldInstanceConfig::loadByName('node', 'body', $node_type_id)); + $this->assertFalse(FieldInstanceConfig::loadByName('node', $node_type_id, 'body')); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index e2ef70a..4b6ac42 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -84,7 +84,7 @@ function testNodeTypeEditing() { $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields')); $this->drupalLogin($web_user); - $instance = FieldInstanceConfig::loadByName('node', 'body', 'page'); + $instance = FieldInstanceConfig::loadByName('node', 'page', 'body'); $this->assertEqual($instance->getLabel(), 'Body', 'Body field was found.'); // Verify that title and body fields are displayed. diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 7dfffc7..ceb4d67 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -397,7 +397,7 @@ function node_type_load($name) { function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { // Add or remove the body field, as needed. $field = FieldConfig::loadByName('node', 'body'); - $instance = FieldInstanceConfig::loadByName('node', 'body', $type->id()); + $instance = FieldInstanceConfig::loadByName('node', $type->id(), 'body'); if (empty($field)) { $field = entity_create('field_config', array( 'name' => 'body', diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 8e5c182..a838d2f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -624,7 +624,7 @@ public function testComputedProperties() { */ protected function assertComputedProperties($entity_type) { // Make the test text field processed. - $instance = FieldInstanceConfig::loadByName($entity_type, 'field_test_text', $entity_type); + $instance = FieldInstanceConfig::loadByName($entity_type, $entity_type, 'field_test_text'); $instance->settings['text_processing'] = 1; $instance->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index 66987a9..1d640ae 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -169,7 +169,7 @@ function testTaxonomyVocabularyChangeMachineName() { $this->assertTrue(isset($info[$new_name]), 'The new bundle name appears in entity_get_bundles().'); // Check that the field instance is still attached to the vocabulary. - $this->assertTrue(FieldInstanceConfig::loadByName('taxonomy_term', 'field_test', $new_name), 'The bundle name was updated correctly.'); + $this->assertTrue(FieldInstanceConfig::loadByName('taxonomy_term', $new_name, 'field_test'), 'The bundle name was updated correctly.'); } /**