diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php index b0c7cbe..d2196b8 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Controller; use Drupal\comment\CommentManagerInterface; +use Drupal\field\FieldConfigInterface; use Drupal\field\FieldInfo; use Drupal\Component\Utility\String; use Drupal\Core\Controller\ControllerBase; @@ -22,13 +23,6 @@ class AdminController extends ControllerBase { /** - * The field info service. - * - * @var \Drupal\field\FieldInfo - */ - protected $fieldInfo; - - /** * The comment manager service. * * @var \Drupal\comment\CommentManagerInterface @@ -47,7 +41,6 @@ class AdminController extends ControllerBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('field.info'), $container->get('comment.manager'), $container->get('form_builder') ); @@ -56,15 +49,12 @@ public static function create(ContainerInterface $container) { /** * Constructs an AdminController object. * - * @param \Drupal\field\FieldInfo $field_info - * The field info service. * @param \Drupal\comment\CommentManagerInterface $comment_manager * The comment manager service. * @param \Drupal\Core\Form\FormBuilderInterface $form_builder * The form builder. */ - public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager, FormBuilderInterface $form_builder) { - $this->fieldInfo = $field_info; + public function __construct(CommentManagerInterface $comment_manager, FormBuilderInterface $form_builder) { $this->commentManager = $comment_manager; $this->formBuilder = $form_builder; } @@ -105,24 +95,29 @@ public function overviewBundles() { $fields = $this->commentManager->getAllFields(); foreach ($fields as $entity_type => $data) { + $field_storages = $this->entityManager()->getFieldStorageDefinitions($entity_type); foreach ($data as $field_name => $field_info_map) { - $field_info = $this->fieldInfo->getField($entity_type, $field_name); + $field_storage = $field_storages[$field_name]; // Initialize the row. $row = array( - 'class' => $field_info->get('locked') ? array('field-disabled') : array(''), + 'class' => $field_storage->get('locked') ? array('field-disabled') : array(''), ); - $bundles = $field_info->getBundles(); - $sample_bundle = reset($bundles); - $sample_instance = $this->fieldInfo->getInstance($entity_type, $sample_bundle, $field_name); + $label = $field_storage->getLabel(); + if ($field_storage instanceof FieldConfigInterface) { + $bundles = $field_storage->getBundles(); + $sample_bundle = reset($bundles); + $field_definitions = $this->entityManager()->getFieldDefinitions($entity_type, $sample_bundle); + $label = $field_definitions[$field_name]->getLabel(); + } $tokens = array( - '@label' => $sample_instance->label, + '@label' => $label, '@field_name' => $field_name, ); - $row['data']['field_name']['data'] = $field_info->get('locked') ? $this->t('@label (@field_name) (Locked)', $tokens) : $this->t('@label (@field_name)', $tokens); + $row['data']['field_name']['data'] = $field_storage->get('locked') ? $this->t('@label (@field_name) (Locked)', $tokens) : $this->t('@label (@field_name)', $tokens); - $row['data']['description']['data'] = $field_info->getSetting('description'); + $row['data']['description']['data'] = $field_storage->getSetting('description'); $row['data']['usage']['data'] = array( '#theme' => 'item_list', '#items' => array(), @@ -200,7 +195,12 @@ public function bundleInfo($commented_entity_type, $field_name) { // Add a link to manage entity fields if the Field UI module is enabled. $field_ui_enabled = $this->moduleHandler()->moduleExists('field_ui'); - $field_info = $this->fieldInfo->getField($commented_entity_type, $field_name); + $field_storage = $this->entityManager()->getFieldStorageDefinitions($commented_entity_type)[$field_name]; + + if (!($field_storage instanceof FieldConfigInterface)) { + // @todo: Support base fields. + return array(); + } $entity_type_info = $this->entityManager()->getDefinition($commented_entity_type); $entity_bundle_info = $this->entityManager()->getBundleInfo($commented_entity_type); @@ -211,7 +211,7 @@ public function bundleInfo($commented_entity_type, $field_name) { '#items' => array(), ); // Loop over all of bundles to which this comment field is attached. - foreach ($field_info->getBundles() as $bundle) { + foreach ($field_storage->getBundles() as $bundle) { // Add the current instance to the list of bundles. if ($field_ui_enabled && $route_info = FieldUI::getOverviewRouteInfo($commented_entity_type, $bundle)) { // Add a link to configure the fields on the given bundle and entity diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index 8d77a5e..abd7cd1 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -61,7 +61,6 @@ public function __construct(HttpKernelInterface $http_kernel, CommentManagerInte public static function create(ContainerInterface $container) { return new static( $container->get('http_kernel'), - $container->get('entity_manager'), $container->get('comment.manager') ); } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 70f4f77..75473e2 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -207,7 +207,7 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl ->execute(); // Fetch all fields and key them by field name. - $field_instance_configs = entity_load_multiple('field_config', $ids); + $field_instance_configs = entity_load_multiple('field_instance_config', $ids); $result = array(); foreach ($field_instance_configs as $field_instance) { $result[$field_instance->getName()] = $field_instance; diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index df46ff3..af24a63 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -238,6 +238,7 @@ public function __construct(array $values, $entity_type = 'field_instance_config 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.'); @@ -281,6 +282,7 @@ public function toArray() { 'uuid', 'status', 'langcode', + 'field_uuid', 'field_name', 'entity_type', 'bundle', @@ -334,7 +336,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_name != $this->original->field_name) { + if ($this->field_uuid != $this->original->field_uuid) { throw new FieldException("Cannot change an existing instance's field."); } // Set the default instance settings. @@ -427,8 +429,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 name to avoid deleting the same field twice. - $fields_to_delete[$instance->field_name] = $field; + // Key by field UUID to avoid deleting the same field twice. + $fields_to_delete[$instance->field_uuid] = $field; } } if ($fields_to_delete) { diff --git a/core/modules/field/tests/Drupal/field/Tests/FieldInstanceConfigEntityUnitTest.php b/core/modules/field/tests/Drupal/field/Tests/FieldInstanceConfigEntityUnitTest.php index d8a43d4..7ab37dc 100644 --- a/core/modules/field/tests/Drupal/field/Tests/FieldInstanceConfigEntityUnitTest.php +++ b/core/modules/field/tests/Drupal/field/Tests/FieldInstanceConfigEntityUnitTest.php @@ -48,13 +48,6 @@ class FieldInstanceConfigEntityUnitTest extends UnitTestCase { protected $uuid; /** - * The field info provider. - * - * @var \Drupal\field\FieldInfo|\PHPUnit_Framework_MockObject_MockObject - */ - protected $fieldInfo; - - /** * {@inheritdoc} */ public static function getInfo() { @@ -75,14 +68,9 @@ public function setUp() { $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); - $this->fieldInfo = $this->getMockBuilder('\Drupal\field\FieldInfo') - ->disableOriginalConstructor() - ->getMock(); - $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); - $container->set('field.info', $this->fieldInfo); \Drupal::setContainer($container); } @@ -98,9 +86,12 @@ public function testCalculateDependencies() { $field->expects($this->once()) ->method('getConfigDependencyName') ->will($this->returnValue('field.field.test_entity_type.test_field')); - $this->fieldInfo->expects($this->any()) - ->method('getField') - ->with('test_entity_type', 'test_field') + + $field_storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); + $field_storage + ->expects($this->any()) + ->method('load') + ->with('test_entity_type.test_field') ->will($this->returnValue($field)); // Mock the interfaces necessary to create a dependency on a bundle entity. @@ -118,8 +109,10 @@ public function testCalculateDependencies() { $this->entityManager->expects($this->any()) ->method('getStorage') - ->with('bundle_entity_type') - ->will($this->returnValue($storage)); + ->will($this->returnValueMap(array( + array('field_config', $field_storage), + array('bundle_entity_type', $storage), + ))); $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $target_entity_type->expects($this->any()) diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 9d48388..a5c6cc9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -67,7 +67,6 @@ public function __construct(EntityManagerInterface $entity_manager, TypedDataMan public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('field.info'), $container->get('typed_data_manager') ); } diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 6c0edda..62ffa36 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -644,8 +644,9 @@ function file_file_download($uri, $field_type = 'file') { // reference denied access, access is denied. foreach ($references as $field_name => $field_references) { foreach ($field_references as $entity_type => $entities) { + $fields = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type); foreach ($entities as $entity) { - $field = $entity->getFieldDefinition($field_name); + $field = $fields[$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/forum/tests/Drupal/forum/Tests/ForumManagerTest.php b/core/modules/forum/tests/Drupal/forum/Tests/ForumManagerTest.php index e1d4a0a..c49a604 100644 --- a/core/modules/forum/tests/Drupal/forum/Tests/ForumManagerTest.php +++ b/core/modules/forum/tests/Drupal/forum/Tests/ForumManagerTest.php @@ -70,15 +70,10 @@ public function testGetIndex() { ->disableOriginalConstructor() ->getMock(); - $field_info = $this->getMockBuilder('\Drupal\field\FieldInfo') - ->disableOriginalConstructor() - ->getMock(); - $manager = $this->getMock('\Drupal\forum\ForumManager', array('getChildren'), array( $config_factory, $entity_manager, $connection, - $field_info, $translation_manager, )); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php index ab1db7d..41a370c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\String; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\field\FieldInfo; use Drupal\taxonomy\TermStorageInterface; @@ -33,33 +34,23 @@ class TermAutocompleteController implements ContainerInjectionInterface { protected $termEntityQuery; /** - * Field info service. + * Entity manager. * - * @var \Drupal\field\FieldInfo + * @var \Drupal\Core\Entity\EntityManagerInterface */ - protected $fieldInfo; - - /** - * Term storage. - * - * @var \Drupal\taxonomy\TermStorageInterface - */ - protected $termStorage; + protected $entityManager; /** * Constructs a new \Drupal\taxonomy\Controller\TermAutocompleteController object. * * @param \Drupal\Core\Entity\Query\QueryInterface $term_entity_query * The entity query service. - * @param \Drupal\field\FieldInfo $field_info - * The field info service. - * @param \Drupal\taxonomy\TermStorageInterface $term_storage - * The term storage. + * @param \Drupal\Core\Entity\EntityManagerInterface + * The entity manager. */ - public function __construct(QueryInterface $term_entity_query, FieldInfo $field_info, TermStorageInterface $term_storage) { + public function __construct(QueryInterface $term_entity_query, EntityManagerInterface $entity_manager) { $this->termEntityQuery = $term_entity_query; - $this->fieldInfo = $field_info; - $this->termStorage = $term_storage; + $this->entityManager = $entity_manager; } /** @@ -69,7 +60,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('entity.query')->get('taxonomy_term'), $container->get('field.info'), - $container->get('entity.manager')->getStorage('taxonomy_term') + $container->get('entity.manager') ); } @@ -110,11 +101,14 @@ public function autocomplete(Request $request, $entity_type, $field_name) { $tags_typed = $request->query->get('q'); // Make sure the field exists and is a taxonomy field. - if (!($field = $this->fieldInfo->getField($entity_type, $field_name)) || $field->getType() !== 'taxonomy_term_reference') { + $field_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type); + + if (!isset($field_definitions[$field_name]) || $field_definitions[$field_name]->getType() !== 'taxonomy_term_reference') { // Error string. The JavaScript handler will realize this is not JSON and // will display it as debugging information. return new Response(t('Taxonomy field @field_name not found.', array('@field_name' => $field_name)), 403); } + $field = $field_definitions[$field_name]; // The user enters a comma-separated list of tags. We only autocomplete the // last tag. @@ -193,7 +187,7 @@ protected function getMatchingTerms($tags_typed, array $vids, $tag_last) { $prefix = count($tags_typed) ? Tags::implode($tags_typed) . ', ' : ''; if (!empty($tids)) { - $terms = $this->termStorage->loadMultiple(array_keys($tids)); + $terms = $this->entityManager->getStorage('taxonomy_term')->loadMultiple(array_keys($tids)); foreach ($terms as $term) { // Term names containing commas or quotes must be wrapped in quotes. $name = Tags::encode($term->getName());