Problem/Motivation
\Drupal\Core\Entity\EntityManager says this:
/**
* Provides a wrapper around many other services relating to entities.
*
* Deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. We cannot
* use the deprecated PHPDoc tag because this service class is still used in
* legacy code paths. Symfony would fail test cases with deprecation warnings.
*
* @todo Enforce the deprecation of each method once
* https://www.drupal.org/node/2578361 is in.
*/
class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
#2578361: Discuss how to leverage E_USER_DEPRECATED is not in, but it's a dupe of #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases which has been implemented.
Let's trigger E_USER_DEPRECATED, either in the methods as it suggests, or for the class, as we would with any other.
Proposed resolution
@trigger_error() is now added to all remaining methods of EntityManager that didn't have it already added in child issues. The class/service is not yet deprecated as there are still cases that instantiating/injecting it, we could look at that in a follow-up issue if we can get rid of it completely (tricky due to setter-based injection for example)
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | rip-entity-manager-2886622-36-interdiff.txt | 6.97 KB | berdir |
| #36 | rip-entity-manager-2886622-36.patch | 285.42 KB | berdir |
| #33 | interdiff-2886622-28-33.txt | 18.62 KB | martin107 |
| #33 | 2886622-33.patch | 284.73 KB | martin107 |
| #25 | rip-entity-manager-2886622-25.patch | 283.9 KB | berdir |
Comments
Comment #2
mile23Comment #3
mile23This patch triggers
E_USER_DEPRECATEDwithinEntityManagerInterface.Comment #5
martin107 commented+1 on the idea behind the issue...
@Mile23
Is you plan to fix the test fails in other issues ... or sort out the 67 fails here.... I want to help out where I can
Comment #6
mile23Well it's a bit of a problem because if we trigger_error() for EntityManager, then all code that uses EntityManager will end up triggering and failing tests. Which is pretty much all of core. :-)
That's why I started on #2782833: Remove usages of deprecated EntityManager from Entity class which might remove at least some of these usages. We might also work on entity base classes like ContentEntityBase and ConfigEntityBase. But only after #2782833: Remove usages of deprecated EntityManager from Entity class because it will require a lot of rerolls otherwise.
Comment #9
tim.plunkettAlso note that the deprecation message is incorrect.
"EntityManager has been split into 11 classes" -> https://www.drupal.org/node/2549139
It was not replaced solely by EntityTypeManager
Comment #10
berdirAlso, shouldn't this use a service-level deprecation instead?
Actually, even that would be impossible to get rid of in core as we have to support something like \Drupal\Core\Entity\EntityFormInterface::setEntityManager() which will always require us to instantiate and inject that service until Drupal 9.
So maybe we need to add @trigger_errors() to all the methods so we can trigger it when it is actually called?
Comment #11
tim.plunkettI think a method-level deprecation makes sense for both of those reasons.
Comment #12
berdirYeah, I think so too. That might also allow us to split things up, e.g. per replacement service or even methods in specific ones?
Comment #14
berdirPinging the followers her for #3006409: Update deprecated usages of Entity::getEntityManager(), fairly simple part that should be ready if it still applies, just started a retest.
Comment #15
berdirStarting with method deprecations: #3023799: Add @trigger_error() to deprecated EntityManager::clearCachedDefinitions() method
Comment #16
berdirNext chunk is #3023981: Add @trigger_error() to deprecated EntityManager->EntityRepository methods, but already postponed on #2691675: Replace deprecated entityManager() in ControllerBase descendents, overlaps too much with that and also the module service one I guess.
Comment #17
berdirThe next one is up: #3025427: Add @trigger_error() to deprecated EntityManager->EntityTypeBundleInfo methods, EntityRepository above is now green and ready for reviews.
This counts all method calls on entity_manager, entityManager, entityManager():
grep -ir 'entity_\?manager(\?)\?-' core/ | wc -l
8.6.x: 1327
HEAD: 1059
With the 3 pending patches applied: 797
Comment #18
berdirOk, the clearCachedDefinitions() issue is in, updated #3023981: Add @trigger_error() to deprecated EntityManager->EntityRepository methods which should be pretty much ready (but is very big).
Also created two new issues which are smaller: #3028656: Add @trigger_error() to deprecated EntityManager listener methods and #3028671: Add @trigger_error() to deprecated and already (almost) unused EntityManager methods.
Comment #20
berdirStatus report for those following along:
* the form classes patch got in
* Created #3038926: Add @trigger_error() to deprecated EntityManager->EntityDisplayRepository methods, that should be ready for reviews, it's pretty small.
* Also created #3035953: Add @trigger_error() to deprecated EntityManager->EntityFieldManager methods a while ago, but is postponed on #3035383: Replace deprecated usages of entityManager in list builder classes, which is RTBC.
With those, all conversions to all services except EntityTypeManager should be done, that seems like a nice goal for 8.7, lets see :)
After applying the 3 patches, we're done to 592 usages. about 370 of those are in tests, most of the others are in module and include files, there's also a quite a bit in deprecated code and legacy tests like EntityManager and EntityManagerTest that we won't update.
Once the issues above are in, I will likely start doing the remaining ones per method or possibly a few rarely used methods grouped.
Comment #21
berdirComment #22
berdir#3035953: Add @trigger_error() to deprecated EntityManager->EntityFieldManager methods is ready I think, cleaning up the remaining injected entity managers in #3042545: Update last injected entity managers.
With those two patches:
After that, I'll switch to search & replace patches for each of the remaining methods.
Comment #23
martin107 commentedPlaying around with the rules module ... suggests to me that for contrib modules which create lots of plugins - that this becomes relevant.
#3045525: EntityDeriver: deprecate entityManager.
Sorry if this is a cross post ... I was looking for a meta issue talking about how we prioritize fixing deprecated entityManager issues.
Comment #24
berdirEnded up being a bit more than I expected, but this should be close. Did also quite a bit of cleanups, leftovers in unit tests and so on, so that blew up the patch a bit in the end, but I hope it's not too hard to review, just long.
What's left is mostly from legacy tests, already deprecated code and stuff like that.
Noticed a considerable amount of construction injections where we updated the type hint but still inject the entity.manager service, not quite sure where that happened ;)
Comment #25
berdirMissed a very prominent one, didn't look for service('entity.manager')..
Comment #27
berdirThat went better than I expected.
Comment #28
martin107 commentedremoved the smallest of problems
Comment #29
martin107 commentedThis look great.
A) Sat down with a pot of coffee and visually scanned this patch
1) All trigger messages follow the approved pattern.
2) All create/constructor changes look correct.
3) Line by line - all other changes look OK.
3) Its is good to see so many $entityManager properties of test classes go away.
4) Nothing extraneous to the issues objectives.
B) Visually inspected the EntityManagerTest class in isolation because this is where the new code is.
in short all looks correct and justified.
C) Inspected the test results .. no additional coding standard violations.
Berdir++
My patch did not really contribute to this work in any meaningful way.I Just moved a linting banana peel out the way. So I am bending the rules and moving this to RTBC
Comment #30
berdirComment #31
jonathan1055 commentedWith reference to #29.1 just thought I should point out that the trigger_error standard is not actually being checked in core tests yet. The texts used do broadly follow the pattern, but there is one small difference:
"will be removed before" should be chaged to "is removed from" to align with the standard agreed on #2908391: Add a rule for expected format of @deprecated and @trigger_error() text and which will soon be checked in Coder.
Comment #32
martin107 commentedI see that as my mistake...
I will fix this tonight.
Comment #33
martin107 commentedA little later than advertised. sorry for that...
Note to self: Nothing but a search and replace inside of the original patch file. I had to prevent one 'replace' from functioning because that would have been fixing an existing error in core not associated with the changes here.
Comment #34
martin107 commentedComment #35
mikelutzWhew, that's a lot of changed files. I only found a couple things that need to be adjusted, and a few styling nits here and there that we might as well fix while we are in there.
At the top of the entityManager class, there is a @todo that needs to be removed
nit: we usually break the arguments to new static() onto separate lines in factory methods when they are over 80 characters. lets do that here since we are touching this line.
It's interesting here we pass the EntityTypeManager to the constructor and then extract the block storage from it and throw the manager away, while in other places we need storage, we pass the storage directly from the factory method. Probably fine for purposes of this patch, but what's the best practice/standard for injecting storage when the manager is not otherwise needed?
Leaving deprecated getMock in here is fine, many other usages around it and out of scope for this patch.
s/enitty/entity/
This can just be combined into one line.
nit: we really don't need the variable here.
In some places we changed the name of the storage variable from $controller to $storage and in other places we didn't. I feel like it should be done, but looking at how many instances there are, it probably shouldn't be done in this patch.
nit: Don't really need the $entity_type_manager variable here.
And here.
Does the comment refer to the entityManager specifically? Should it be removed too, or is state also stale after updates?
nit: would be more readable to split arguments onto separate lines
and here
Couple more
This just feels off to me. The method mocks the getEntityType and the entityTypeBundleInfo() which is not mentioned in the doc, but doesn't actually mock the return value of entityTypeManager like the documentation suggests. I think the documentation needs to be adjusted.
Comment #36
berdir1. Removed the @todo, not quite sure what to do about the rest of the docblock, the todo kind of belonged to that.
2. Fixed.
3. As discussed, I prefer injecting and keeping the entity type manager, not the storage, but way out of scope.
5. Fixed.
6. / 7. / 9. There are lot of these cases, I'd rather not change that here.
8. Yeah, weird but IMHO also out of scope. controller is actually unused. But it's a base class, there might be more subclasses of that in contrib? Should have don that when adding a new base class for phpunit tests ;)
10. / 11. I think it technically applies to both, state also has a static cache that could interfere so I kept it.
12. / 13. / 14. Fixed.
15. Yes, removed entityTypeManager() and updated the comment to mention entityTypeBundleInfo()
Comment #37
mikelutzAll my feedback has been addressed, RTBC from me pending green tests.
Comment #38
alexpottCommitted 408c540 and pushed to 8.8.x. Thanks!
Note I ignored the changes
core/modules/comment/src/Form/CommentTypeDeleteForm.phpto because I committed #2509652: Remove unused and deprecated entity.manager service injection in CommentTypeDeleteForm first.Fixed some coding standards on commit.