Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The EntityManager is @deprecated, and there are lots of usages of \Drupal::entityManager() in core.
Proposed resolution
As a step to remove usages, but keep things manageable,
- \Drupal::entityManager()->foo();
+ $this->container->get('the_proper_entity_service.manager')->foo();
just in *Test.php, which is about ~230 usages, but only comprising a handful of patterns.
Remaining tasks
TBD.
User interface changes
None.
API changes
None.
Data model changes
None.
Original Report
Replaced with \Drupal::entityTypeManager() instead of \Drupal::entityManager() in date time.
Comment | File | Size | Author |
---|---|---|---|
#17 | 2721791--17.patch | 47.3 KB | tuutti |
#17 | interdiff-2721791--17.txt | 3.77 KB | tuutti |
#14 | 2721791-14.patch | 43.4 KB | tuutti |
#14 | interdiff-2721791-14.txt | 723 bytes | tuutti |
#12 | 2721791-12.patch | 43.4 KB | tuutti |
|
Comments
Comment #3
mpdonadioThat method is on the EntityFieldManager, not the EntityTypeManager.
Does this patch catch all of the uses in datetime? Are there any injected uses of the EntityManager service directly?
This will need a proper Issue Summary; I stubbed out the template.
Comment #4
Nikhilesh Gupta CreditAttribution: Nikhilesh Gupta as a volunteer and at Melity commentedComment #5
mpdonadioPatch doesn't apply, so can't add interdiff. Reroll + fixes. Passes locally. Did some searches, and think this covers all uses of the EntityManager service.
Comment #6
jhedstromI verified there are no additional uses of the deprecated entity manager in the datetime module once this patch is applied. I think it's good to go.
Comment #7
alexpottI think we have issues around scope here... for example,
We could do a find and replace on the entire code base for this.
See https://www.drupal.org/core/scope for guidelines and examples for Drupal core issue scope.
Comment #8
mpdonadioHad quick chat with @alexpott in IRC. We want to increase the scope of this. Few things to consider for the new scope.
There are a boatload of \Drupal::entityManager() calls in core.
We can do search/replace like in the above, but in a lot of cases it may not be the best thing to do. For example, this issue should probably have done
to eliminate the use of \Drupal global. However, there are a lot of place where the \Drupal::entityManager() is used where either the container isn't available, or dependencies aren't injected.
PhpStorm is telling me that \Drupal::entityManager() is used 230 times in *Test.php. These should all be kernel or web tests, where the $this->container is available. In addition, it looks like in tests there are only a handful of usage patterns, so search/replace is a viable option to get most usages. So, I am proposing to rescope this to replace \Drupal::entityManager() with calls to the appropriate service via the container provided by the test.
Comment #9
alexpott@mpdonadio I think we should focus on
\Drupal::entityManager()
with\Drupal::service('entity_field.manager');
(or the best equivalent) is a good scope. We should have an issue per new service.Comment #10
mpdonadioIssue per service sounds like a good plan.
Comment #12
tuutti CreditAttribution: tuutti as a volunteer commentedSearch/replaced. Let's see if tests pass.
Comment #14
tuutti CreditAttribution: tuutti as a volunteer and at KWD Digital commentedComment #15
tuutti CreditAttribution: tuutti as a volunteer and at KWD Digital commentedComment #17
tuutti CreditAttribution: tuutti as a volunteer and at KWD Digital commentedShould we use \Drupal::entityManager() on
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem
rather than mocking the entityManager->getBaseFieldDefinitions() calls twice onDrupal\Tests\views\Unit\EntityViewsDataTest
?This is happening due to two different services calling getBaseFieldDefinitions() (entity.manager and entity_field.manager) on EntityViewsData and EntityReferenceItem classes.
Seems like fixing the tests "properly" would require a lot refactoring on
Drupal\views\EntityViewsData
and on all the classes extending it.Comment #23
TR CreditAttribution: TR commentedPatch no longer applies.
Comment #24
BerdirForgot about this, this is a duplicate of #3035953: Add @trigger_error() to deprecated EntityManager->EntityFieldManager methods at this point, which is more up to date.