Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BramDriesen created an issue. See original summary.

BramDriesen’s picture

Assigned: BramDriesen » Unassigned
Status: Active » Needs review
FileSize
970 bytes
BramDriesen’s picture

Title: Replace depricated \Drupal::entityManager() in EntityReferenceItem » Replace deprecated \Drupal::entityManager() in EntityReferenceItem

Status: Needs review » Needs work

The last submitted patch, 2: replace_depricated-2908271-2.patch, failed testing. View results

swati.nuna’s picture

Status: Needs work » Needs review
FileSize
5.94 KB

hi,

I have added the updated patch file.

Here in the EntityReferenceItem.php file I have found 11 occurrences of entityManager() which i updated.

Please review.

Status: Needs review » Needs work

The last submitted patch, 5: replace_depricated-2908271-5.patch, failed testing. View results

swati.nuna’s picture

Status: Needs work » Needs review
FileSize
4.37 KB

Here is new updated patch file.

Please review.

Status: Needs review » Needs work

The last submitted patch, 7: replace_depricated-2908271-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

swati.nuna’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

Here is a new patch file.

Hope it will work.

jofitz’s picture

Corrected coding standards error: removed unused use statement.

BramDriesen’s picture

@Jo Fitzgerald Looks good, but what about the entityManager I replaced in my initial patch (that failed)? :)

jofitz’s picture

Put back the changes from the patch in #2 that were inexplicably excluded from the patch in #9 (and #10).

a.dmitriiev’s picture

Why then not to replace all other calls to entityManager() method? Here is the patch #12 re-roll with replacing all other calls with appropriate services.

Status: Needs review » Needs work

The last submitted patch, 13: remove-deprecated-entity-manager-2908271-13.patch, failed testing. View results

a.dmitriiev’s picture

Re-rolled patch with correct line endings.

a.dmitriiev’s picture

Status: Needs work » Needs review
Mile23’s picture

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -414,14 +414,14 @@ public function hasNewEntity() {
    +    $manager = \Drupal::entityTypeManager();
    
    @@ -463,14 +463,14 @@ public static function calculateStorageDependencies(FieldStorageDefinitionInterf
    +    $entity_manager = \Drupal::entityTypeManager();
    

    Let's consistently call these $entity_type_manager

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -414,14 +414,14 @@ public function hasNewEntity() {
    +          $entity = \Drupal::service('entity.repository')->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
    
    @@ -463,14 +463,14 @@ public static function calculateStorageDependencies(FieldStorageDefinitionInterf
    +          $entity = \Drupal::service('entity.repository')->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
    

    Resolve the service outside the foreach() loops.

  3. +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
    @@ -408,6 +417,12 @@ protected function setupFieldStorageDefinition() {
               ['user', TRUE, static::userEntityInfo()],
             ]
           );
    +    $this->entityTypeManager->expects($this->any())
    +      ->method('getDefinition')
    +      ->willReturnMap([
    +          ['user', TRUE, static::userEntityInfo()],
    +        ]
    +      );
    

    I didn't look very closely at this test, but if we're truly deprecating entity.manager out of the code then we should not mock it in the test. I'm not sure if this test is specific enough one way or another, but if we can remove the entity.manager mock, then we should.

Mile23’s picture

Status: Needs review » Needs work
jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Novice
FileSize
7.03 KB
12.26 KB

Addressed the test failures by mocking the entity_field.manager service.

  1. Consistently used $entity_type_manager.
  2. Assigned the entity.repository service outside the loop.
  3. entity.manager still needs to be mocked because it is needed elsewhere, e.g. EntityViewsData, while the scope of this issue only covers EntityReferenceItem.

Removed Novice tag because this is quite complicated.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

TR’s picture

Version: 8.6.x-dev » 8.8.x-dev
FileSize
11.36 KB
1.25 KB

Re-rolled patch against 8.8.x.

Mostly just offsets, but I had to remove one hunk from the patch and change another because those lines were already fixed by out-of-scope changes in #3028671: Add @trigger_error() to deprecated and already (almost) unused EntityManager methods and #3025427: Add @trigger_error() to deprecated EntityManager->EntityTypeBundleInfo methods

BramDriesen’s picture

Status: Needs review » Reviewed & tested by the community

Looks good from my perspective, also the tests are passing so that's great. Maybe some one else can also have a look at it?

RTBC for me.

larowlan’s picture

issue credits

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 37d2299 and pushed to 8.8.x. Thanks!

  • larowlan committed 37d2299 on 8.8.x
    Issue #2908271 by Jo Fitzgerald, swati.nuna, a.dmitriiev, TR,...

Status: Fixed » Closed (fixed)

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