Another child of #2886622: Deprecate all EntityManager methods with E_USER_DEPRECATED, this time the various methods on EntityFieldManagerInterface.

There seem to be fewer calls to that left than I expected, quite a few were already covered elsewhere.

A handful are left in some form classes and another in a list builder class, these will be covered by #2969109: Replace deprecated usages of entityManager in form classes and #3035383: Replace deprecated usages of entityManager in list builder classes

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new109.47 KB

Still another 100kb, though. As before, in a few places I updated all uses of entityManager, almost no constructor changes this time though. A bunch of migrate classes (including unit test updates) and pseudo-injection in Tables.php as well as the usage in ModuleInstaller.

berdir’s picture

Bunch of unused use statements fixed.

berdir’s picture

+++ b/core/modules/views/src/EntityViewsData.php
@@ -71,19 +86,22 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
     $this->storage = $storage_controller;
     $this->moduleHandler = $module_handler;
     $this->setStringTranslation($translation_manager);
+    $this->entityFieldManager = $entity_field_manager;
   }
 

this one needs the NULL treatment, forgot about it.

The last submitted patch, 2: entity-field-manager-methods-3035953-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 3: entity-field-manager-methods-3035953-3.patch, failed testing. View results

andypost’s picture

looking on replaced usage in field tests I think it makes sense to provide protected EFM property to not abuse container and \Drupal instead of now "mostly unused" $this->entityTypeManager property

  1. +++ b/core/modules/content_translation/content_translation.admin.inc
    @@ -95,11 +95,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
    -  $entity_manager = Drupal::entityManager();
    +  $entity_type_manager = Drupal::entityTypeManager();
    

    needs \

  2. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php
    @@ -171,9 +171,9 @@ public function testSettingsUI() {
    -      \Drupal::entityManager()->clearCachedFieldDefinitions();
    +      \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    ...
    -      $definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
    +      $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'article');
    

    could use local var

  3. +++ b/core/modules/file/file.module
    @@ -1726,7 +1726,7 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
         foreach ($return as $field_name => $data) {
           foreach (array_keys($data) as $entity_type_id) {
    -        $field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type_id);
    +        $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
    

    makes sense to move local var out of loop

  4. +++ b/core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
    @@ -364,7 +364,7 @@ protected function getUpdatedEntityTypeDefinition($revisionable = FALSE, $transl
    -    $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test_update');
    +    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');
    

    is there a way to inject it?

  5. +++ b/core/modules/views/src/FieldAPIHandlerTrait.php
    @@ -23,6 +23,13 @@
    +  protected $entityFieldManager;
    
    @@ -52,7 +59,7 @@ protected function getFieldDefinition() {
       protected function getFieldStorageDefinition() {
         if (!$this->fieldStorageDefinition) {
    -      $field_storage_definitions = $this->getEntityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
    +      $field_storage_definitions = $this->getEntityFieldManager()->getFieldStorageDefinitions($this->definition['entity_type']);
    
    @@ -71,4 +78,17 @@ protected function getEntityManager() {
    +  protected function getEntityFieldManager() {
    +    if (!isset($this->entityFieldManager)) {
    +      $this->entityFieldManager = \Drupal::service('entity_field.manager');
    

    probably private visibility better?

  6. +++ b/core/modules/views/views.views.inc
    @@ -257,7 +257,7 @@ function views_entity_field_label($entity_type, $field_name) {
       // Count the amount of fields per label per field storage.
       foreach (array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type)) as $bundle) {
    -    $bundle_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
    +    $bundle_fields = array_filter(\Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
    

    makes sense to use local var and move out of loop

  7. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php
    @@ -298,7 +298,7 @@ public function testModifyingTranslatableColumnSchema() {
         foreach ($fields as $field_name) {
    -      $original_definition = $this->entityManager->getBaseFieldDefinitions('entity_test')[$field_name];
    +      $original_definition = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('entity_test')[$field_name];
    
    +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php
    @@ -712,11 +712,11 @@ public function testFieldDefinitions() {
         foreach ($translatable_fields as $name => $translatable) {
           $this->state->set('entity_test.field_definitions.translatable', [$name => $translatable]);
    -      $this->entityManager->clearCachedFieldDefinitions();
    +      \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
           $message = format_string('Field %field cannot be translatable.', ['%field' => $name]);
     
           try {
    -        $this->entityManager->getBaseFieldDefinitions($entity_type);
    +        \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type);
    

    looks local var makes sense here as well

vacho’s picture

StatusFileSize
new109.77 KB
new9.85 KB

Patch rerolled. Solving merge problems. File FileFieldWidgetTest.php move to new path in 8.7.x

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new108.79 KB

another reroll.

This is still technically postponed on #3035383: Replace deprecated usages of entityManager in list builder classes, just checking how much is left other than that.

Status: Needs review » Needs work

The last submitted patch, 10: entity-field-manager-methods-3035953-10.patch, failed testing. View results

berdir’s picture

Status: Needs work » Postponed
berdir’s picture

Status: Postponed » Needs review
StatusFileSize
new109.44 KB

Ok, the blocker is in, rerolled, lets see what I missed.

Status: Needs review » Needs work

The last submitted patch, 13: entity-field-manager-methods-3035953-13.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new122.25 KB
new15.71 KB

Fixing a few more cases and updating some kernel and unit tests.

andypost’s picture

It has collision with #2897015: EntityManager class/method @deprecation is incomplete but is more complete, as I checked few references in `@see` needs updates

andypost’s picture

StatusFileSize
new3.5 KB
new125.75 KB

Fixes

berdir’s picture

berdir’s picture

Status: Postponed » Needs review
StatusFileSize
new119.22 KB
new10.76 KB

Reroll. Also finally addressing the review from #7.

1. Done
2. Done
3. Done
4. There would be ways, sure, but it is a test trait, so no reason to.
5. private in traits isn't really private: https://3v4l.org/O2aPl, so it wouldn't really be private anyway and making it protected makes conceptually more senes to me, as it would allow a class to inject the service.
6. Done.
7. Done.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks polished

berdir’s picture

Rerolled, only conflict was this, so leaving at RTBC. Actually conflicted with #2908271: Replace deprecated \Drupal::entityManager() in EntityReferenceItem.

@@@ -99,9 -93,8 +108,14 @@@
      $this->entityStorage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
        ->disableOriginalConstructor()
        ->getMock();
++<<<<<<< ours
 +    $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
 +    $this->entityFieldManager = $this->getMock('Drupal\Core\Entity\EntityFieldManagerInterface');
 +    $this->entityTypeManager = $this->getMock('Drupal\Core\Entity\EntityTypeManagerInterface');
++=======
+     $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
+     $this->entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
++>>>>>>> theirs
  
      $typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
      $typed_data_manager->expects($this->any())
@@@ -151,9 -144,8 +165,14 @@@
  
      $container = new ContainerBuilder();
      $container->set('plugin.manager.field.field_type', $field_type_manager);
++<<<<<<< ours
 +    $container->set('entity.manager', $this->entityManager);
 +    $container->set('entity_field.manager', $this->entityFieldManager);
 +    $container->set('entity_type.manager', $this->entityTypeManager);
++=======
+     $container->set('entity_type.manager', $this->entityTypeManager);
+     $container->set('entity_field.manager', $this->entityFieldManager);
++>>>>>>> theirs
      $container->set('typed_data_manager', $typed_data_manager);
      $container->set('state', $state->reveal());
      \Drupal::setContainer($container);
larowlan’s picture

+++ b/core/modules/views/src/FieldAPIHandlerTrait.php
@@ -71,4 +78,17 @@ protected function getEntityManager() {
+   * Returns the entity manager.
...
+   *   The entity manager service.

nit: this isn't really true

berdir’s picture

berdir’s picture

Reroll, also injected the entity field manager into the node wizard plugin like the entity get display issue did.

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed a98b587 and pushed to 8.8.x. Thanks!

  • larowlan committed a98b587 on 8.8.x
    Issue #3035953 by Berdir, andypost, vacho: Add @trigger_error() to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jidrone’s picture

Hi everyone,

Do you know why this is causing the following error on custom entity types extending EntityViewsData:

PHP Fatal error: Uncaught Error: Call to a member function getBaseFieldDefinitions() on null in /app/webroot/core/modules/views/src/EntityViewsData.php:287

Looks like the entity_field.manager service in not injected for the custom entity type.

kristiaanvandeneynde’s picture