Part of meta-issue #2225347: [META] Replace calls to ENTITY_TYPE_load() and ENTITY_TYPE_load_multiple() with static method calls
Problem/Motivation
Replacing old API function calls with static method calls.
Proposed resolution
- All occurences of user_role_load() and entity_load('user_role') need to be changed to Role::load()
- All occurences of entity_load_multiple('user_role') need to be replaced with Role::loadMultiple()
- If entity_load() or entity_load_multiple() were used with $reset = TRUE, reset the role cache with \Drupal::entityManager()->getStorage('user_role')->resetCache();
Remaining tasks
There is a patch in comment 21 that needs review
Create or update a change record related to this. Might have to be done on the meta issue?
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | interdiff-2322233-14-21.txt | 1.3 KB | Mirroar |
| #21 | drupal8-entity_system-user-role-load-2322233-21.patch | 15.58 KB | Mirroar |
| #19 | drupal8-entity_system-user-role-load-2322233-19.patch | 15.64 KB | Mirroar |
| #14 | drupal8-entity_system-user-role-load-2322233-14.patch | 15.4 KB | estoyausente |
| #11 | interdiff-9-11.txt | 511 bytes | temoor |
Comments
Comment #1
temoor commentedComment #2
Michael Hodge Jr commentedNot sure if this is accurate or not, but I applied the patch and grepped the code for these occurrences. Everything looks good except for finding one instance of entity_load_multiple('user_role').
It was located in the User.module file around line 1174. It's contained in the user_roles function. Is this a false positive? I'm assigning back to needs work, but if this should still be there, then feel free to set it to RTBC. The code for reference is below
Comment #3
temoor commentedThanks, @Michael Hodge Jr.
Removed remaining call in attached patch.
Comment #4
Michael Hodge Jr commentedMuch better. Thanks!
Comment #8
ohthehugemanatee commentedIs this a duplicate of #2322195: Replace all instances of user_load(), user_load_multiple(), entity_load('user') and entity_load_multiple('user') with static method calls?
Edit: no it isn't, I just skimmed over the word "role" in the title. Feelin' clever.
Comment #9
temoor commentedUsed User instead of Role class in user_role_revoke_permissions()
Comment #10
dawehnerWe still use user_role_load in
though you can easily replace this with
['\Drupal\user\Entity\Role', 'load']Comment #11
temoor commentedThanks, I should pay attention to d8 FAPI
Comment #14
estoyausenteRerolled
Comment #15
estoyausenteComment #17
estoyausenteComment #18
Mirroar commentedWe'll take a look at it, sprinting at DC Amsterdam.
Comment #19
Mirroar commentedOkay, so the reason the previous patch failed testing is because within UserRoleAdminTest.php calls to
entity_load('user_role', $id, TRUE)were replaced withRole::load($id). However, this does not reset the cache of loaded roles, unlike the old call.We added the code from entity_load to reset the cache before loading the Roles again. Not sure if this is the best way to reset the entity cache, but it seems to be working.
Comment #20
estoyausenteHi, @Mirroar, thank for the help. I debugged it and I haven't found the fail (F*** cache grrr).
It seems that now is correct. I think that someone with more experience have to review it, but I think that it's correct anyway.
Comment #21
Mirroar commentedIt seems the more widely used pattern here is something along the lines of
\Drupal::entityManager()->getStorage('user_role')->resetCache(array($role->id()));(user.module does something along those lines, and the Meta Issue also suggests this pattern). So I updated the patch to do that instead. Also adding an interdiff to #14 so the changes are easier to review.I've also run a grep for any of the functions mentioned in the issue title, and can't find any other references in the codebase. So as far as I know, we got all of them.
Comment #22
Mirroar commentedUpdated the issue summary
Comment #23
Mirroar commentedComment #24
mradcliffeThe changes in the interdiff make sense.
Reviewing the code in the entire patch. There does not seem to be any changes that do not correspond to the meta issue. I think this is RTBC if it passes tests.
We also need to create or update a change record related to this. Is this done on the meta issue?
Comment #25
Mirroar commentedSetting RTBC and updating the issue summary again. But I have no Idea how to create a change record for this, so this will need to be done by somebody else, probably.
Comment #26
Mirroar commentedComment #27
alexpottCommitted 331f287 and pushed to 8.0.x. Thanks!