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
A follow-through task after #2030151: Convert entity_get_bundles to a method on the entity manager
Dependency-injected code should not rely on a global method in a module for services.
Let's remove the use of entity_get_bundles()
in DI code.
Proposed resolution
Remaining tasks
User interface changes
API changes
Beta phase evaluation
Issue category | Task because it doesn't solve an existing problem, other than inelegance. |
---|---|
Unfrozen changes | Improves DX, solidifies the API. |
Disruption | Not disruptive. |
Comment | File | Size | Author |
---|---|---|---|
#46 | interdiff.txt | 2.91 KB | Mile23 |
#46 | 2427637_46.patch | 20.04 KB | Mile23 |
#44 | interdiff.txt | 3.03 KB | Mile23 |
#44 | 2427637_44.patch | 18.99 KB | Mile23 |
#42 | 2427637_42.patch | 16.27 KB | Mile23 |
Comments
Comment #1
Mile23And a patch.
Within classes, we change occurrences of
entity_get_bundles()
to either the injected entity manager or container where such injection exists or the\Drupal
container access where it doesn't.In procedural code, as in
.inc
and.module
files, we leaveentity_get_bundles()
calls, since modules can declare their dependence on each other.Comment #2
Mile23Comment #3
Mile23Comment #4
Mile23Golly. #1 still applies.
Comment #5
Mile23Needed a re-roll.
Comment #6
Mile23Comment #7
Mile23If we're not deprecating, who cares? :-)
#2526462: Mark entity_get_bundles() as @deprecated for 9.x.
Comment #8
Mile23#2526462: Mark entity_get_bundles() as @deprecated for 9.x. is marked fixed, so onward.
Comment #9
Mile23Converted to
\Drupal
for non-injected code, some coding standards and documentation improvements.This removes all usages of
entity_get_bundles()
from Drupal core.Comment #10
Mile23Still applies. Retesting passing patch.
Comment #12
Mile23Still applies. Still removes all usages of entity_get_bundles(), other than the function itself and some @sees. Retesting.
Comment #14
Mile23Reroll.
Comment #16
Mile23Foiled by a patch that went in *today*. :-) #2172843: Remove ability to update entity bundle machine names
Comment #20
keopxI passed local test,
Testbot passed.
Looks fine.
Comment #21
alexpottWe are we pointing back to the deprecated code - that seems odd.
Comment #22
keopxNew patch
Comment #23
keopxCorrect last patch
Mistake in previous patch #2427637-22: Remove usages of deprecated entity_get_bundles(): remove deprecated function entity_get_bundles()
Not remove this code
Comment #28
keopxComment #29
Mile23Reroll of #23.
Comment #30
keopxLooks nice, so if test passed I think that is RTBC
Comment #31
keopxComment #33
naveenvalechastraight Reroll from #2427637-23: Remove usages of deprecated entity_get_bundles()
Edit : Ehhh That was with 8.1.x. Please ignore.
Comment #34
naveenvalechahiding #33 as it was against version 8.1.x
Comment #35
Mile238.0.x is bug fixes only, and this isn't a bug fix. You're right to patch 8.1.x. :-)
I'd set back to 'needs review' but I don't know how to unhide a file. Sigh.
Comment #36
naveenvalechaunhide the file #33
Did review own by own and have some open questions as well.
Add a new line
Should not we use the entityTypeManager instead of entityManager b/c entitymanager is already deprecated ?
Comment #37
naveenvalechawe also have a issue filed for removing the deprecated use of entityManager #2653196: Replace usage of deprecated EntityManager, So what's the scope of this one ? Same question #36.2 ?
Addressing #36.1
Comment #38
naveenvalechaattaching updated interdiff
Comment #39
BerdirNot entity type manager but the new entity bundle info service.
Comment #40
Berdire.g. \Drupal::service('('entity_type.bundle.info')->getBundleInfo($entity_type) or the injected version of it.
Comment #42
Mile23I redid the work rather than re-rolling, due to version bump and time lapse.
Comment #44
Mile23Let's chase around some tests! :-)
Comment #45
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedWhy \Drupal and not the injected version ?
Comment #46
Mile23Oh yeah, I missed getting back to that one due to the basic panic involving all the failing tests for the other changes.
Comment #47
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedHave reviewed the patch, can't see any problems.
Comment #49
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedComment #50
xjmThanks @Mile23!
There are still a couple docs references we should remove as well:
Comment #52
xjm@catch and I crossposted, so I just rolled #2776369: Remove docs references to entity_get_bundles() as a followup.
Comment #55
klausiThis broke the Rules tests, filed #2780255: Replace incorrect EntityTypeBundleInfo type hints with interface.
Remember: always type hint to interfaces, never to concrete classes!