diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index bfe5a39..ad3d6ac 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -7,6 +7,8 @@ use Drupal\custom_block\Entity\CustomBlockType; use Drupal\custom_block\Entity\CustomBlock; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldInstanceConfig; /** * Implements hook_help(). @@ -114,8 +116,8 @@ 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 = field_info_field('custom_block', 'body'); - $instance = field_info_instance('custom_block', 'body', $block_type_id); + $field = FieldConfig::loadByName('custom_block', 'body'); + $instance = FieldInstanceConfig::loadByName('custom_block', 'body', $block_type_id); if (empty($field)) { $field = entity_create('field_config', array( 'name' => 'body', diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 3002006..b08e787 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -232,7 +232,7 @@ protected function actions(array $form, array &$form_state) { /* @var \Drupal\comment\CommentInterface $comment */ $comment = $this->entity; $entity = $comment->getCommentedEntity(); - $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name]; + $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()]; $preview_mode = $field_definition->getSetting('preview'); // No delete action on the comment form. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 139bf73..260834f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; /** @@ -74,7 +75,7 @@ function setUp() { $this->container->get('comment.manager')->addDefaultField('node', 'article'); // Make comment body translatable. - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $field->translatable = TRUE; $field->save(); $this->assertTrue($field->isTranslatable(), 'Comment body is translatable.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index 5e5b4de..119b06d 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -9,6 +9,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\content_translation\Tests\ContentTranslationUITest; +use Drupal\field\Entity\FieldConfig; /** * Tests the Comment Translation UI. @@ -77,7 +78,7 @@ protected function getTranslatorPermissions() { */ function setupTestFields() { parent::setupTestFields(); - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $field->translatable = TRUE; $field->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentUninstallTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentUninstallTest.php index 6127552..5be58c8 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentUninstallTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentUninstallTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; /** @@ -43,14 +44,14 @@ protected function setUp() { */ function testCommentUninstallWithField() { // Ensure that the field exists before uninstallation. - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $this->assertNotNull($field, 'The comment_body field exists.'); // Uninstall the comment module which should trigger field deletion. $this->container->get('module_handler')->uninstall(array('comment')); // Check that the field is now deleted. - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $this->assertNull($field, 'The comment_body field has been deleted.'); } @@ -60,12 +61,12 @@ function testCommentUninstallWithField() { */ function testCommentUninstallWithoutField() { // Manually delete the comment_body field before module uninstallation. - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $this->assertNotNull($field, 'The comment_body field exists.'); $field->delete(); // Check that the field is now deleted. - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $this->assertNull($field, 'The comment_body field has been deleted.'); // Ensure that uninstallation succeeds even if the field has already been diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php index a8e1a0c..509fd0b 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php @@ -8,6 +8,7 @@ namespace Drupal\content_translation\Tests; use Drupal\Core\Language\Language; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field as FieldService; use Drupal\simpletest\WebTestBase; @@ -95,7 +96,7 @@ function testSettingsUI() { ); $this->assertSettings('comment', 'node__comment_article', TRUE, $edit); field_info_cache_clear(); - $field = field_info_field('comment', 'comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); $this->assertTrue($field->isTranslatable(), 'Comment body is translatable.'); // Test that language settings are correctly stored. diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 846a723..ba83ec8 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; +use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldConfigInterface; /** @@ -209,7 +210,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 = field_info_field($entity_type, $field_name); + $field = FieldConfig::loadByName($entity_type, $field_name); $instance = field_info_instance($entity_type, $field_name, $bundle); if (empty($field)) { diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index da29536..7d61db0 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -770,4 +770,18 @@ protected function getFieldItemClass() { return $type_definition['class']; } + /** + * Loads a field config entity based on the entity type and field name. + * + * @param string $entity_type_id + * ID of the entity type. + * @param string $field_name + * Name of the field. + * + * @return static + */ + public static function loadByName($entity_type_id, $field_name) { + return \Drupal::entityManager()->getStorage('field_config')->load($entity_type_id . '.' . $field_name); + } + } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index ff6217d..e40ff6e 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -808,4 +808,20 @@ public function isDeleted() { return $this->deleted; } + /** + * Loads a field config entity based on the entity type and field name. + * + * @param string $entity_type_id + * ID of the entity type. + * @param string $bundle + * Bundle name. + * @param string $field_name + * Name of the field. + * + * @return static + */ + public static function loadByName($entity_type_id, $bundle, $field_name) { + return \Drupal::entityManager()->getStorage('field_instance_config')->load($entity_type_id . '.' . $bundle . '.' . $field_name); + } + } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php b/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php index 2f0cadb..c948bcb 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php @@ -34,7 +34,7 @@ class FieldList extends Numeric { public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); - $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $field = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; $this->allowed_values = options_allowed_values($field); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php b/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php index a257cad..14f7a8f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php @@ -34,7 +34,7 @@ class ListString extends String { public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); - $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $field = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; $this->allowed_values = options_allowed_values($field); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 030bd50..1428cfd 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -316,7 +316,7 @@ public function clickSort($order) { } $this->ensureMyTable(); - $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $field = $this->entityManager->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; $column = ContentEntityDatabaseStorage::_fieldColumnName($field, $this->options['click_sort_column']); if (!isset($this->aliases[$column])) { // Column is not in query; add a sort on it (without adding the column). @@ -329,7 +329,7 @@ protected function defineOptions() { $options = parent::defineOptions(); // defineOptions runs before init/construct, so no $this->field_info - $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $field = $this->entityManager->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; $field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType()); $column_names = array_keys($field->getColumns()); $default_column = ''; diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/filter/FieldList.php b/core/modules/field/lib/Drupal/field/Plugin/views/filter/FieldList.php index 6b0b153..d1d007f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/filter/FieldList.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/filter/FieldList.php @@ -19,7 +19,7 @@ class FieldList extends ManyToOne { public function getValueOptions() { - $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $field = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; $this->value_options = list_allowed_values($field); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php b/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php index 46db003..383ab40 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php @@ -52,7 +52,7 @@ public static function create(ContainerInterface $container, array $configuratio public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); - $this->field_info = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $this->field_info = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type'])[$this->definition['field_name']]; } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index 36a2770..4644b2c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -8,6 +8,7 @@ namespace Drupal\field\Tests; use Drupal\Core\Entity\EntityStorageException; +use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldException; class CrudTest extends FieldUnitTestBase { @@ -312,7 +313,7 @@ function testDeleteField() { // Test that the first field is not deleted, and then delete it. $field = current(entity_load_multiple_by_properties('field_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); - field_info_field('entity_test', $this->field['name'])->delete(); + FieldConfig::loadByName('entity_test', $this->field['name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index f8a02ab..4317a4e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -8,6 +8,7 @@ namespace Drupal\field\Tests; use Drupal\Core\Entity\EntityStorageException; +use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldException; class FieldInstanceCrudTest extends FieldUnitTestBase { @@ -199,9 +200,9 @@ function testDeleteFieldInstanceCrossDeletion() { $instance_2 = entity_create('field_instance_config', $instance_definition_2); $instance_2->save(); $instance->delete(); - $this->assertTrue(field_info_field('entity_test', $field->name)); + $this->assertTrue(FieldConfig::loadByName('entity_test', $field->name)); $instance_2->delete(); - $this->assertFalse(field_info_field('entity_test', $field->name)); + $this->assertFalse(FieldConfig::loadByName('entity_test', $field->name)); // Check that deletion of all instances of the same field simultaneously // deletes the field. @@ -213,7 +214,7 @@ function testDeleteFieldInstanceCrossDeletion() { $instance_2->save(); $instance_storage = $this->container->get('entity.manager')->getStorage('field_instance_config'); $instance_storage->delete(array($instance, $instance_2)); - $this->assertFalse(field_info_field('entity_test', $field->name)); + $this->assertFalse(FieldConfig::loadByName('entity_test', $field->name)); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 958d15a..fb4a3b3 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -421,7 +421,7 @@ public function submitForm(array &$form, array &$form_state) { if (!empty($form_values['_add_existing_field']['field_name'])) { $values = $form_values['_add_existing_field']; $field_name = $values['field_name']; - $field = field_info_field($this->entity_type, $field_name); + $field = FieldConfig::loadByName($this->entity_type, $field_name); if (!empty($field->locked)) { drupal_set_message($this->t('The field %label cannot be added because it is locked.', array('%label' => $values['label'])), 'error'); } @@ -528,16 +528,17 @@ protected function getExistingFieldOptions() { * Checks if a field machine name is taken. * * @param string $value - * The machine name, not prefixed with 'field_'. + * The machine name, not prefixed. * * @return bool * Whether or not the field machine name is taken. */ public function fieldNameExists($value) { - // Prefix with 'field_'. - $field_name = 'field_' . $value; + // Prefix with the configured prefix.. + $field_name = \Drupal::config('field_ui.settings')->get('field_prefix') . $value; - return (bool) field_info_field($this->entity_type, $field_name); + $fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); + return isset($fields[$field_name]); } } 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 8fd993f..f65663c 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 @@ -10,6 +10,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\Component\Utility\String; +use Drupal\field\Entity\FieldConfig; /** * Tests the functionality of the 'Manage fields' screen. @@ -246,7 +247,7 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string' // Reset the fields info. field_info_cache_clear(); // Assert field settings. - $field = field_info_field($entity_type, $field_name); + $field = FieldConfig::loadByName($entity_type, $field_name); $this->assertTrue($field->getSetting('test_field_setting') == $string, 'Field settings were found.'); // Assert instance settings. @@ -377,7 +378,7 @@ function testDeleteField() { // Check that the field instance was deleted. $this->assertNull(field_info_instance('node', $this->field_name, $this->type), 'Field instance was deleted.'); // Check that the field was not deleted - $this->assertNotNull(field_info_field('node', $this->field_name), 'Field was not deleted.'); + $this->assertNotNull(FieldConfig::loadByName('node', $this->field_name), 'Field was not deleted.'); // Delete the second instance. $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$this->field_name", $this->field_label, $type_name2); @@ -387,7 +388,7 @@ function testDeleteField() { // Check that the field instance was deleted. $this->assertNull(field_info_instance('node', $this->field_name, $type_name2), 'Field instance was deleted.'); // Check that the field was deleted too. - $this->assertNull(field_info_field('node', $this->field_name), 'Field was deleted.'); + $this->assertNull(FieldConfig::loadByName('node', $this->field_name), 'Field was deleted.'); } /** @@ -556,7 +557,7 @@ function testDeleteTaxonomyField() { // Check that the field instance was deleted. $this->assertNull(field_info_instance('taxonomy_term', $this->field_name, 'tags'), 'Field instance was deleted.'); // Check that the field was deleted too. - $this->assertNull(field_info_field('taxonomy_term', $this->field_name), 'Field was deleted.'); + $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 2543616..f11c557 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -642,7 +642,7 @@ function file_file_download($uri, $field_type = 'file') { foreach ($references as $field_name => $field_references) { foreach ($field_references as $entity_type => $entities) { foreach ($entities as $entity) { - $field = field_info_field($entity_type, $field_name); + $field = $entity->getFieldDefinition($field_name); // Check if access to this field is not disallowed. if (!$entity->get($field_name)->access('view')) { $denied = TRUE; diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index a7df01d..723b9b3 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; @@ -159,7 +160,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, } // Attach a file to the node. - $field = field_info_field('node', $field_name); + $field = FieldConfig::loadByName('node', $field_name); $name = 'files[' . $field_name . '_0]'; if ($field->getCardinality() != 1) { $name .= '[]'; diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 7f975e9..dafedba 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -4,6 +4,7 @@ * @file * Install, update, and uninstall functions for the Forum module. */ +use Drupal\field\Entity\FieldConfig; /** * Implements hook_install(). @@ -20,7 +21,7 @@ function forum_install() { // Create the 'taxonomy_forums' field if it doesn't already exist. If forum // is being enabled at the same time as taxonomy after both modules have been // enabled, the field might exist but still be marked inactive. - if (!field_info_field('node', 'taxonomy_forums')) { + if (!FieldConfig::loadByName('node', 'taxonomy_forums')) { entity_create('field_config', array( 'name' => 'taxonomy_forums', 'entity_type' => 'node', @@ -92,15 +93,15 @@ function forum_install() { * Implements hook_uninstall(). */ function forum_uninstall() { - if ($field = field_info_field('node', 'taxonomy_forums')) { + if ($field = FieldConfig::loadByName('node', 'taxonomy_forums')) { $field->delete(); } - if ($field = field_info_field('node', 'comment_forum')) { + if ($field = FieldConfig::loadByName('node', 'comment_forum')) { $field->delete(); } - if ($field = field_info_field('taxonomy_term', 'forum_container')) { + if ($field = FieldConfig::loadByName('taxonomy_term', 'forum_container')) { $field->delete(); } diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php index 1e4e9bd..130143f 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -9,6 +9,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; /** @@ -36,7 +37,7 @@ public static function getInfo() { */ function testForumUninstallWithField() { // Ensure that the field exists before uninstallation. - $field = field_info_field('node', 'taxonomy_forums'); + $field = FieldConfig::loadByName('node', 'taxonomy_forums'); $this->assertNotNull($field, 'The taxonomy_forums field exists.'); // Create a taxonomy term. @@ -82,7 +83,7 @@ function testForumUninstallWithField() { $this->assertResponse(200); // Check that the field is now deleted. - $field = field_info_field('node', 'taxonomy_forums'); + $field = FieldConfig::loadByName('node', 'taxonomy_forums'); $this->assertNull($field, 'The taxonomy_forums field has been deleted.'); } @@ -92,12 +93,12 @@ function testForumUninstallWithField() { */ function testForumUninstallWithoutField() { // Manually delete the taxonomy_forums field before module uninstallation. - $field = field_info_field('node', 'taxonomy_forums'); + $field = FieldConfig::loadByName('node', 'taxonomy_forums'); $this->assertNotNull($field, 'The taxonomy_forums field exists.'); $field->delete(); // Check that the field is now deleted. - $field = field_info_field('node', 'taxonomy_forums'); + $field = FieldConfig::loadByName('node', 'taxonomy_forums'); $this->assertNull($field, 'The taxonomy_forums field has been deleted.'); // Ensure that uninstallation succeeds even if the field has already been diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index b49a4ac..dd9ae7c 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -8,6 +8,7 @@ namespace Drupal\image\Tests; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\field\Entity\FieldConfig; /** * Test class to check that formatters and display settings are working. @@ -271,7 +272,7 @@ function testImageFieldDefaultImage() { $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.$field_name/field", $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. field_info_cache_clear(); - $field = field_info_field('node', $field_name); + $field = FieldConfig::loadByName('node', $field_name); $default_image = $field->getSetting('default_image'); $file = file_load($default_image['fid']); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); @@ -309,7 +310,7 @@ function testImageFieldDefaultImage() { $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.$field_name/field", $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. field_info_cache_clear(); - $field = field_info_field('node', $field_name); + $field = FieldConfig::loadByName('node', $field_name); $default_image = $field->getSetting('default_image'); $this->assertFalse($default_image['fid'], 'Default image removed from field.'); // Create an image field that uses the private:// scheme and test that the @@ -326,7 +327,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); - $private_field = field_info_field('node', $private_field_name); + $private_field = FieldConfig::loadByName('node', $private_field_name); $default_image = $private_field->getSetting('default_image'); $file = file_load($default_image['fid']); $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php index 67b34e7..fd83b93 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; @@ -60,7 +61,7 @@ function setUp() { $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); // Make node body translatable. - $field = field_info_field('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $field->translatable = TRUE; $field->save(); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 564f4c5..1b79537 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -12,6 +12,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Render\Element; use Drupal\Core\Url; +use Drupal\field\Entity\FieldConfig; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; @@ -394,7 +395,7 @@ function node_type_load($name) { */ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { // Add or remove the body field, as needed. - $field = field_info_field('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $instance = field_info_instance('node', 'body', $type->id()); if (empty($field)) { $field = entity_create('field_config', array( diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index dd6d13e..d4f99ec 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -7,6 +7,7 @@ namespace Drupal\options\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Tests\FieldTestBase; /** @@ -231,7 +232,7 @@ function testOptionsAllowedValuesBoolean() { $this->drupalGet($this->admin_path); $this->assertFieldByName('on', $on, t("The 'On' value is stored correctly.")); $this->assertFieldByName('off', $off, t("The 'Off' value is stored correctly.")); - $field = field_info_field('node', $this->field_name); + $field = FieldConfig::loadByName('node', $this->field_name); $this->assertEqual($field->getSetting('allowed_values'), $allowed_values, 'The allowed value is correct'); $this->assertNull($field->getSetting('on'), 'The on value is not saved into settings'); $this->assertNull($field->getSetting('off'), 'The off value is not saved into settings'); @@ -295,7 +296,7 @@ function assertAllowedValuesInput($input_string, $result, $message) { } else { field_info_cache_clear(); - $field = field_info_field('node', $this->field_name); + $field = FieldConfig::loadByName('node', $this->field_name); $this->assertIdentical($field->getSetting('allowed_values'), $result, $message); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index 46b81bf..8c0288e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; @@ -102,10 +103,10 @@ function testEntityFormLanguage() { $this->assertTrue($node, 'Node found in database.'); // Make body translatable. - $field = field_info_field('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $field->translatable = TRUE; $field->save(); - $field = field_info_field('node', 'body'); + $field = FieldConfig::loadByName('node', 'body'); $this->assertTrue($field->isTranslatable(), 'Field body is translatable.'); // Create a body translation and check the form language. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php index 82e63b2..8549d99 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php @@ -445,7 +445,7 @@ function testFieldSqlStorageForeignKeys() { $schema = $field->getSchema(); // Retrieve the field definition and check that the foreign key is in place. - $field = field_info_field('entity_test', $field_name); + $field = FieldConfig::loadByName('entity_test', $field_name); $this->assertEqual($schema['foreign keys'][$foreign_key_name]['table'], $foreign_key_name, 'Foreign key table name modified after update'); $this->assertEqual($schema['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', 'Foreign key column name modified after update'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index afac0db..8ec55e7 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -8,6 +8,7 @@ namespace Drupal\taxonomy\Tests; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\field\Entity\FieldConfig; /** * Tests a taxonomy term reference field that allows multiple vocabularies. @@ -122,7 +123,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->assertNoText($term2->getName(), 'Term 2 name is not displayed.'); // Verify that field and instance settings are correct. - $field = field_info_field('entity_test', $this->field_name); + $field = FieldConfig::loadByName('entity_test', $this->field_name); $this->assertEqual(count($field->getSetting('allowed_values')), 1, 'Only one vocabulary is allowed for the field.'); // The widget should still be displayed. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 1dd0aab..f61b91e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\taxonomy\Tests; +use Drupal\field\Entity\FieldConfig; /** * Tests for taxonomy term field and formatter. @@ -170,7 +171,7 @@ function testTaxonomyTermFieldChangeMachineName() { $this->vocabulary->save(); // Check that the field instance is still attached to the vocabulary. - $field = field_info_field('entity_test', $this->field_name); + $field = FieldConfig::loadByName('entity_test', $this->field_name); $allowed_values = $field->getSetting('allowed_values'); $this->assertEqual($allowed_values[0]['vocabulary'], $new_name, 'Index 0: Machine name was updated correctly.'); $this->assertEqual($allowed_values[1]['vocabulary'], $new_name, 'Index 1: Machine name was updated correctly.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index d07ab4a..8863c42 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Tags; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Component\Utility\String; +use Drupal\field\Entity\FieldConfig; /** * Tests for taxonomy term functions. @@ -235,7 +236,7 @@ function testNodeTermCreationAndDeletion() { $field_name = $this->randomName(); $tag = $this->randomName(); $message = t("Taxonomy field @field_name not found.", array('@field_name' => $field_name)); - $this->assertFalse(field_info_field('node', $field_name), format_string('Field %field_name does not exist.', array('%field_name' => $field_name))); + $this->assertFalse(FieldConfig::loadByName('node', $field_name), format_string('Field %field_name does not exist.', array('%field_name' => $field_name))); $this->drupalGet('taxonomy/autocomplete/node/' . $field_name, array('query' => array('q' => $tag))); $this->assertRaw($message, 'Autocomplete returns correct error message when the taxonomy field does not exist.'); } diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index ca14056..930c569 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -225,7 +225,7 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { if ($tags = $element['#value']) { // Get the machine names of the vocabularies we will search, keyed by the // vocabulary IDs. - $field = field_info_field($element['#entity_type'], $element['#field_name']); + $field = \Drupal::entityManager()->getFieldStorageDefinitions($element['#entity_type'])[$element['#field_name']]; $vocabularies = array(); $allowed_values = $field->getSetting('allowed_values'); if (!empty($allowed_values)) {