diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php index e58947a..2033d88 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php @@ -90,13 +90,12 @@ public function setMapperDefinition($mapper_definition) { * {@inheritdoc} */ public function load() { - $entities = array(); // It is not possible to use the standard load method, because this needs // all field instance entities only for the given baseEntityType. - foreach (Field::fieldInfo()->getInstances($this->baseEntityType) as $fields) { - $entities = array_merge($entities, array_values($fields)); - } - return $entities; + $ids = \Drupal::entityQuery('field_instance_config') + ->condition('entity_type', $this->baseEntityType) + ->execute(); + return $this->storage->loadMultiple($ids); } /** diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 38b5b41..3dfc334 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -14,6 +14,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\node\NodeInterface; /** @@ -865,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 = field_info_instance($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName(($entity_type, $field_name, $bundle); if ($instance->isTranslatable()) { $instance->settings['translation_sync'] = $column_settings; } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index dd1bfa0..a5a9b15 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Field; /** @@ -164,7 +165,7 @@ public function calculateDependencies() { // Create dependencies on both hidden and visible fields. $fields = $this->content + $this->hidden; foreach ($fields as $field_name => $component) { - $field_instance = Field::fieldInfo()->getInstance($this->targetEntityType, $this->bundle, $field_name); + $field_instance = FieldInstanceConfig::loadByName($this->targetEntityType, $this->bundle, $field_name); if ($field_instance) { $this->addDependency('entity', $field_instance->getConfigDependencyName()); } diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index ba83ec8..e37e5f0 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -11,6 +11,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\FieldConfigInterface; /** @@ -92,7 +93,7 @@ function entity_reference_field_config_update(FieldConfigInterface $field) { foreach ($field->bundles() as $entity_type => $bundles) { foreach ($bundles as $bundle) { - $instance = field_info_instance($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); $instance->settings['handler_settings'] = array(); $instance->save(); } @@ -211,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 = field_info_instance($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); if (empty($field)) { $field = array( diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php index f035f37..9dd19fc 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php @@ -7,6 +7,8 @@ namespace Drupal\entity_reference\Tests; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\field\Field; @@ -88,9 +90,8 @@ public function setUp() { array('target_bundles' => array($this->bundle)) ); - $this->field = Field::fieldInfo()->getField($this->entityType, $this->fieldName); - $instances = Field::fieldInfo()->getBundleInstances($this->entityType, $this->bundle); - $this->instance = $instances[$this->fieldName]; + $this->field = FieldConfig::loadByName($this->entityType, $this->fieldName); + $this->instance = FieldInstanceConfig::loadByName($this->entityType, $this->bundle, $this->fieldName); } /** diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 029db41..70f4f77 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -200,9 +200,19 @@ function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface */ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { if ($entity_type->isFieldable()) { - // Configurable fields, which are always attached to a specific bundle, are - // added 'by bundle'. - return Field::fieldInfo()->getBundleInstances($entity_type->id(), $bundle); + // Query by filtering on the ID as this is more efficient than filtering + // on the entity_type property directly. + $ids = \Drupal::entityQuery('field_instance_config') + ->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH') + ->execute(); + + // Fetch all fields and key them by field name. + $field_instance_configs = entity_load_multiple('field_config', $ids); + $result = array(); + foreach ($field_instance_configs as $field_instance) { + $result[$field_instance->getName()] = $field_instance; + } + return $result; } } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index e40ff6e..df46ff3 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -232,26 +232,12 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi * @ingroup field_crud */ public function __construct(array $values, $entity_type = 'field_instance_config') { - // Field instances configuration is stored with a 'field_uuid' property - // unambiguously identifying the field. We only take it into account if a - // 'uuid' entry is present too, so that leftover 'field_uuid' entries - // present in config files imported as "default module config" are ignored. - if (isset($values['field_uuid']) && isset($values['uuid'])) { - $field = Field::fieldInfo()->getFieldById($values['field_uuid']); - if (!$field) { - throw new FieldException(format_string('Attempt to create an instance of unknown field @uuid', array('@uuid' => $values['field_uuid']))); - } - $values['field_name'] = $field->getName(); - } - // Alternatively, accept incoming 'field_name' instead of 'field_uuid', for - // easier DX on creation of new instances (either through programmatic - // creation / or through import of default config files). - elseif (isset($values['field_name']) && isset($values['entity_type'])) { - $field = Field::fieldInfo()->getField($values['entity_type'], $values['field_name']); + // Load the corresponding field. + 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']))); } - $values['field_uuid'] = $field->uuid(); } else { throw new FieldException('Attempt to create an instance of an unspecified field.'); @@ -295,7 +281,6 @@ public function toArray() { 'uuid', 'status', 'langcode', - 'field_uuid', 'field_name', 'entity_type', 'bundle', @@ -349,7 +334,7 @@ public function preSave(EntityStorageInterface $storage) { if ($this->bundle != $this->original->bundle && empty($this->bundle_rename_allowed)) { throw new FieldException("Cannot change an existing instance's bundle."); } - if ($this->field_uuid != $this->original->field_uuid) { + if ($this->field_name != $this->original->field_name) { throw new FieldException("Cannot change an existing instance's field."); } // Set the default instance settings. @@ -442,8 +427,8 @@ public static function postDelete(EntityStorageInterface $storage, array $instan foreach ($instances as $instance) { $field = $instance->getField(); if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($field->getBundles()) == 0) { - // Key by field UUID to avoid deleting the same field twice. - $fields_to_delete[$instance->field_uuid] = $field; + // Key by field name to avoid deleting the same field twice. + $fields_to_delete[$instance->field_name] = $field; } } if ($fields_to_delete) { diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 2b74370..ab76e31 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityDatabaseStorage; use Drupal\Core\Entity\EntityInterface; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\FieldConfigInterface; @@ -176,7 +177,7 @@ function testDeleteFieldInstance() { $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); $instance->delete(); // The instance still exists, deleted. @@ -226,7 +227,7 @@ function testPurgeInstance() { $field = reset($this->fields); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); $instance->delete(); // No field hooks were called. @@ -285,7 +286,7 @@ function testPurgeField() { // Delete the first instance. $bundle = reset($this->bundles); - $instance = field_info_instance($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); $instance->delete(); // Assert that FieldItemInterface::delete() was not called yet. @@ -315,7 +316,7 @@ function testPurgeField() { // Delete the second instance. $bundle = next($this->bundles); - $instance = field_info_instance($this->entity_type, $field->name, $bundle); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $field->name, $bundle); $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 efb6ae8..44f6ca6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\field\Tests; +use Drupal\field\Entity\FieldInstanceConfig; /** * Unit test class for storage-related field behavior. @@ -334,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 = field_info_instance($entity_type, $this->field_name, $new_bundle); + $this->instance = FieldInstanceConfig::loadByName($entity_type, $this->field_name, $new_bundle); $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/lib/Drupal/field/Tests/FieldImportCreateTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php index f248fdc..e7faf06 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php @@ -60,13 +60,20 @@ function testImportCreateDefault() { $this->assertTrue($instance->bundle, 'test_bundle', 'The second field instance was created on bundle test_bundle.'); $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. - $instances = Field::fieldInfo()->getInstances('entity_test'); - $this->assertEqual(count($instances['entity_test']), 2); - $this->assertTrue(isset($instances['entity_test']['field_test_import'])); - $this->assertTrue(isset($instances['entity_test']['field_test_import_2'])); - $this->assertEqual(count($instances['test_bundle']), 1); - $this->assertTrue(isset($instances['test_bundle']['field_test_import_2'])); + // Tests field instances. + $ids = \Drupal::entityQuery('field_instance_config') + ->condition('entity_type', 'entity_test') + ->condition('bundle', 'entity_test') + ->execute(); + $this->assertEqual(count($ids), 2); + $this->assertTrue(in_array('field_test_import', $ids)); + $this->assertTrue(in_array('field_test_import_2', $ids)); + $ids = \Drupal::entityQuery('field_instance_config') + ->condition('entity_type', 'entity_test') + ->condition('bundle', 'entity_test') + ->execute(); + $this->assertEqual(count($ids), 1); + $this->assertTrue(in_array('field_test_import_2', $ids)); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 4317a4e..515301e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\FieldException; class FieldInstanceCrudTest extends FieldUnitTestBase { @@ -189,8 +190,8 @@ function testDeleteFieldInstanceCrossDeletion() { entity_create('field_instance_config', $this->instance_definition)->save(); entity_create('field_instance_config', $instance_definition_2)->save(); $field->delete(); - $this->assertFalse(field_info_instance('entity_test', $this->instance_definition['bundle'], $field->name)); - $this->assertFalse(field_info_instance('entity_test', $instance_definition_2['bundle'], $field->name)); + $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $this->instance_definition['bundle'], $field->name)); + $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $instance_definition_2['bundle'], $field->name)); // Chack that deletion of the last instance deletes the field. $field = entity_create('field_config', $this->field_definition); 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 f65663c..7d18b49 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 @@ -11,6 +11,7 @@ use Drupal\Core\Language\Language; use Drupal\Component\Utility\String; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; /** * Tests the functionality of the 'Manage fields' screen. @@ -251,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 = field_info_instance($entity_type, $field_name, $bundle); + $instance = FieldInstanceConfig::loadByName($entity_type, $field_name, $bundle); $this->assertTrue($instance->getSetting('test_instance_setting') == $string, 'Field instance settings were found.'); } @@ -323,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 = field_info_instance('node', $field_name, $this->type); + $instance = FieldInstanceConfig::loadByName('node', $field_name, $this->type); $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 @@ -335,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 = field_info_instance('node', $field_name, $this->type); + $instance = FieldInstanceConfig::loadByName('node', $field_name, $this->type); $this->assertEqual($instance->default_value, NULL, 'The default value was correctly saved.'); // Check that the default widget is used when the field is hidden. @@ -376,7 +377,7 @@ function testDeleteField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(field_info_instance('node', $this->field_name, $this->type), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('node', $this->field_name, $this->type), 'Field instance was deleted.'); // Check that the field was not deleted $this->assertNotNull(FieldConfig::loadByName('node', $this->field_name), 'Field was not deleted.'); @@ -386,7 +387,7 @@ function testDeleteField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(field_info_instance('node', $this->field_name, $type_name2), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('node', $this->field_name, $type_name2), 'Field instance was deleted.'); // Check that the field was deleted too. $this->assertNull(FieldConfig::loadByName('node', $this->field_name), 'Field was deleted.'); } @@ -555,7 +556,7 @@ function testDeleteTaxonomyField() { // Reset the fields info. field_info_cache_clear(); // Check that the field instance was deleted. - $this->assertNull(field_info_instance('taxonomy_term', $this->field_name, 'tags'), 'Field instance was deleted.'); + $this->assertNull(FieldInstanceConfig::loadByName('taxonomy_term', $this->field_name, 'tags'), '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/file.module b/core/modules/file/file.module index f11c557..6c0edda 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -5,7 +5,10 @@ * Defines a "managed_file" Form API field and a "file" field for Field module. */ +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\FieldConfigInterface; use Drupal\file\Entity\File; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\Unicode; @@ -1848,9 +1851,10 @@ function file_icon_map(File $file) { * * @param \Drupal\file\File $file * A file entity. - * @param $field - * (optional) A field array to be used for this check. If given, limits the + * @param \Drupal\field\FieldConfigInterface $field + * (optional) A field definition to be used for this check. If given, limits the * reference check to the given field. + * @todo This should use FieldDefinitionInterface instead. * @param $age * (optional) A constant that specifies which references to count. Use * EntityStorageInterface::FIELD_LOAD_REVISION to retrieve all @@ -1867,7 +1871,7 @@ function file_icon_map(File $file) { * A multidimensional array. The keys are field_name, entity_type, * entity_id and the value is an entity referencing this file. */ -function file_get_file_references(File $file, $field = NULL, $age = EntityStorageInterface::FIELD_LOAD_REVISION, $field_type = 'file') { +function file_get_file_references(File $file, FieldConfigInterface $field = NULL, $age = EntityStorageInterface::FIELD_LOAD_REVISION, $field_type = 'file') { $references = &drupal_static(__FUNCTION__, array()); $field_columns = &drupal_static(__FUNCTION__ . ':field_columns', array()); @@ -1929,7 +1933,7 @@ function file_get_file_references(File $file, $field = NULL, $age = EntityStorag if ($field || $field_type) { foreach ($return as $field_name => $data) { foreach (array_keys($data) as $entity_type_id) { - $current_field = field_info_field($entity_type_id, $field_name); + $current_field = FieldConfig::loadByName($entity_type_id, $field_name); if (($field_type && $current_field->getType() != $field_type) || ($field && $field->uuid() != $current_field->uuid())) { unset($return[$field_name][$entity_type_id]); } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php index 6426304..0c46256 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php @@ -311,18 +311,18 @@ public static function validateMultipleCount($element, &$form_state, $form) { array_pop($parents); $current = count(Element::children(NestedArray::getValue($form, $parents))) - 1; - $field = Field::fieldInfo()->getField($element['#entity_type'], $element['#field_name']); + $field = \Drupal::entityManager()->getFieldStorageDefinitions($element['#element_type'])[$element['#field_name']]; $uploaded = count($values['fids']); $count = $uploaded + $current; - if ($count > $field->cardinality) { - $keep = $uploaded - $count + $field->cardinality; + if ($count > $field->getCardinality()) { + $keep = $uploaded - $count + $field->getCardinality(); $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { $file = file_load($fid); $removed_names[] = $file->getFilename(); } - $args = array('%field' => $field->getFieldName(), '@max' => $field->cardinality, '@count' => $keep, '%list' => implode(', ', $removed_names)); + $args = array('%field' => $field->getFieldName(), '@max' => $field->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); drupal_set_message($message, 'warning'); $values['fids'] = array_slice($values['fids'], 0, $keep); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 723b9b3..1260f0e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; @@ -124,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 = field_info_instance('node', $name, $type_name); + $instance = FieldInstanceConfig::loadByName('node', $name, $type_name); $instance->settings = array_merge($instance->settings, $instance_settings); $instance->save(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index b85b187..1eb9088 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Field; /** @@ -32,7 +33,7 @@ function testRequired() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $field = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); - $instance = Field::fieldInfo()->getInstance('node', $type_name, $field_name); + $instance = FieldInstanceConfig::loadByName('node', $type_name, $field_name); $test_file = $this->getTestFile('text'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index bf80c17..3fcaaae 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\file\Tests; +use Drupal\field\Entity\FieldInstanceConfig; /** * Tests file field widget. @@ -208,7 +209,7 @@ function testPrivateFileSetting() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); - $instance = field_info_instance('node', $field_name, $type_name); + $instance = FieldInstanceConfig::loadByName('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 5facc3c..8f0c57d 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Utility\String; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field; /** @@ -109,7 +110,7 @@ function forum_menu_local_tasks(&$data, $route_name) { $vid = \Drupal::config('forum.settings')->get('vocabulary'); $links = array(); // Loop through all bundles for forum taxonomy vocabulary field. - $field = Field::fieldInfo()->getField('node', 'taxonomy_forums'); + $field = FieldConfig::loadByName('node', 'taxonomy_forums'); foreach ($field->getBundles() as $type) { if (\Drupal::entityManager()->getAccessController('node')->createAccess($type)) { $links[$type] = array( 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 1d59ca1..452db65 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests\Config; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\simpletest\DrupalUnitTestBase; /** @@ -80,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(field_info_instance('node', 'body', $node_type_id)); + $this->assertFalse(FieldInstanceConfig::loadByName('node', 'body', $node_type_id)); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 6cfc32f..e2ef70a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\node\Tests; +use Drupal\field\Entity\FieldInstanceConfig; /** * Tests related to node types. @@ -83,7 +84,7 @@ function testNodeTypeEditing() { $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields')); $this->drupalLogin($web_user); - $instance = field_info_instance('node', 'body', 'page'); + $instance = FieldInstanceConfig::loadByName('node', 'body', 'page'); $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 1b79537..7dfffc7 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -13,6 +13,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; @@ -396,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 = field_info_instance('node', 'body', $type->id()); + $instance = FieldInstanceConfig::loadByName('node', 'body', $type->id()); if (empty($field)) { $field = entity_create('field_config', array( 'name' => 'body', diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index a2fcbb7..80aaa09 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -7,6 +7,7 @@ namespace Drupal\path\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field; /** @@ -67,9 +68,7 @@ function setUp() { ); $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save')); - // Ensure configuration changes are picked up in the host environment. - Field::fieldInfo()->flush(); - $field = Field::fieldInfo()->getField('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $this->assertTrue($field->isTranslatable(), 'Node body is translatable.'); } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index b470ae6..25c35b6 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -8,6 +8,7 @@ namespace Drupal\search\Tests; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Field; /** @@ -61,7 +62,7 @@ function testSearchResultsComment() { $comment_body = 'Test comment body'; // Make preview optional. - $instance = Field::fieldInfo()->getInstance('node', 'article', 'comment'); + $instance = FieldInstanceConfig::loadByName('node', 'article', 'comment'); $instance->settings['preview'] = DRUPAL_OPTIONAL; $instance->save(); // Enable check_plain() for 'Basic HTML' text format. @@ -138,7 +139,7 @@ function testSearchResultsCommentAccess() { // Create a node. // Make preview optional. - $instance = Field::fieldInfo()->getInstance('node', 'article', 'comment'); + $instance = FieldInstanceConfig::loadByName('node', 'article', 'comment'); $instance->settings['preview'] = DRUPAL_OPTIONAL; $instance->save(); $this->node = $this->drupalCreateNode(array('type' => 'article')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchLanguageTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchLanguageTest.php index 8dcec89..3e9c5f8 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchLanguageTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchLanguageTest.php @@ -8,6 +8,7 @@ namespace Drupal\search\Tests; use Drupal\Core\Language\Language; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field; /** @@ -47,7 +48,7 @@ function setUp() { // Make the body field translatable. The title is already translatable by // definition. The parent class has already created the article and page // content types. - $field = Field::fieldInfo()->getField('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $field->translatable = TRUE; $field->save(); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php index 7a54b58..e597679 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php @@ -8,6 +8,7 @@ namespace Drupal\search\Tests; use Drupal\Core\Language\Language; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field; /** @@ -58,7 +59,7 @@ function setUp() { // Make the body field translatable. The title is already translatable by // definition. The parent class has already created the article and page // content types. - $field = Field::fieldInfo()->getField('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $field->translatable = TRUE; $field->save(); 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 4a05431..8e5c182 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -17,6 +17,7 @@ use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\Type\StringInterface; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\field\Entity\FieldInstanceConfig; /** * Tests Entity API base functionality. @@ -623,7 +624,7 @@ public function testComputedProperties() { */ protected function assertComputedProperties($entity_type) { // Make the test text field processed. - $instance = field_info_instance($entity_type, 'field_test_text', $entity_type); + $instance = FieldInstanceConfig::loadByName($entity_type, 'field_test_text', $entity_type); $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 ae757f3..66987a9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\taxonomy\Tests; +use Drupal\field\Entity\FieldInstanceConfig; /** * Tests for taxonomy vocabulary functions. @@ -168,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(field_info_instance('taxonomy_term', 'field_test', $new_name), 'The bundle name was updated correctly.'); + $this->assertTrue(FieldInstanceConfig::loadByName('taxonomy_term', 'field_test', $new_name), 'The bundle name was updated correctly.'); } /**