Problem/Motivation
This is a follow up to #3324729: User::addRole() and ::removeRole() should be chainable.
Now that User::addRole() and ::removeRole() are chainable, the usages in core can be changed.
Steps to reproduce
Proposed resolution
Find usages of User::addRole() and ::removeRole() and change the code to be chained.
For example, convert
$user1->addRole('administrator');
$user1->activate();
$user1->setLastAccessTime($request_time);
$user1->save();
to
$user1->addRole('administrator')
->activate()
->setLastAccessTime($request_time)
->save();
Remaining tasks
Patch
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
quietone commentedComment #3
_pratik_Patch for replacements on places where "addRole" is used. With some phpcs fixes also.
Thanks
Comment #4
_pratik_Comment #5
xjmThanks for your interest in working on this issue.
Note that we should not mix out-of-scope coding standards fixes into patches because it makes them harder to review and creates merge conflicts. Reference:
https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...
Please remove these changes; they are out of scope and also as far as I know will break the cspell integration, which does not indicate a period should be used: https://cspell.org/configuration/document-settings/
These are out-of-scope changes and should be removed.
The patch also does not apply (but it is more likely to apply and will be easier to reroll if the unneeded hunks are removed).
Thanks!
Comment #8
hardikpandya commentedDone for both addRole and removeRole.
Comment #9
xjmNeeds work for the above test failures. Thanks!
Comment #10
nishtha.pradhan commentedChanged the code to chain usages of User::addRole() and ::removeRole(). A patch created for these changes.
Comment #11
nishtha.pradhan commentedComment #12
nishtha.pradhan commentedComment #13
quietone commentedPatch does not apply.
Comment #14
sahilgidwani commentedComment #15
rishabh vishwakarma commentedModified the code to chain usages of User::addRole() and ::removeRole().
Comment #16
rishabh vishwakarma commentedModified the code to chain usages of User::addRole() and ::removeRole(). Addressed the custom command fail as well.
Comment #17
sahilgidwani commentedCreated a new patch because in the previous patch added by @nishta.pradhan, path of files was starting with /web/core instead /core patch was not applying because of this.
Comment #18
sahilgidwani commentedComment #21
xjm@nishtha.pradhan, why did you create a new patch instead of using the merge request? Also, when you update an existing issue with a patch, please supply an interdiff. Please, read the issue and understand its current status before you add changes.
Why, for that matter, is anyone creating patches? All the latest patches still do not have my feedback from #9 addressed. No one should supply a new patch that does not address that issue.
I am removing credit for all the unnecessary patches, and hiding them. If a MR is already used on an issue, please don't start suddenly creating patches without explanation; this adds noise and confusion. You can still get credit for this issue by implementing my feedback from #9.
Comment #24
pminfI've addressed #9 and made a separate MR based on 10.1.x (previous one has to be rebased).
Comment #26
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #27
rogerpfaffI feel bad that I made that commit accidentally and confused the review bot. How can we make the MR by @pminf the one the bot reacts to?
Comment #28
pminf@rogerpfaff I reverted your commit from #25 and set the issue back to its previous state. Tests will pass and everything will be OK again :)
Comment #29
pminfI made a rebase.
Comment #30
smustgrave commentedBefore reviewing there appear to be some merge conflicts
error: patch failed: core/modules/block_content/tests/src/Kernel/BlockContentAccessHandlerTest.php:116
error: core/modules/block_content/tests/src/Kernel/BlockContentAccessHandlerTest.php: patch does not apply
error: patch failed: core/modules/user/tests/src/Kernel/UserEntityReferenceTest.php:67
error: core/modules/user/tests/src/Kernel/UserEntityReferenceTest.php: patch does not apply
Comment #31
sahil.goyal commentedHi, I applied the patch after rebasing the branch, it seems look good, it is getting applied cleanly without any conflict, Attaching screenshot, Other than that patch look fine, there is no other User role method seen got unchained.
Comment #33
ultimikeI'm going to claim this issue so that I can use it for the DrupalCon Portland core mentoring day.
-mike
Comment #36
axbWork/ed/ing on this issue at First Time Contribution DrupalCon Portland 2024.
We spent 1200 to 1500 May 8 2024 porting the merge request from Drupal 10 to Drupal 11.
Comment #42
ultimikeComment #43
mandclu commentedI reviewed the code and the updated code is all equivalent (but chained) with the exception of adding
willReturn($this->account)statements in theRemoveRoleUserTest. Since the tests continue to pass, these don't appear to be causing issues.Comment #44
zshrestha commentedWorked on the issue with ultimike at DrupalCon Portland 2024.
Comment #45
ultimikeWorked on this with three mentees during DrupalCon Portland 2024 first time contributor workshop: @Zoyace Shrestha, @chadhester,
@alexb7217
-mike
Comment #46
xjmSaving DrupalCon contributor credits from #45.
Comment #47
xjmAnd hiding screenshot. (We only need screenshots when there is a user-facing change to evaluate.) Thanks!
Comment #52
xjmCommitted live! at DrupalCon Portland 2024 to 11.x, 11.0.x, 10.4.x, and 10.3.x. It did not cherry-pick cleanly to 10.2.x. Setting PTBP for a 10.2.x MR.
Thanks everyone!
Comment #53
xjmComment #54
xjm10.2.x has had its final bugfix release, so marking fixed against 10.3.x (which means those credits from Portland will finally show on your profiles.) 😅 Yay!
Comment #55
axbw00t. Thank you.
Comment #57
xjmAmending attribution.