There's currently no function within the user module to check if a user has been assigned a certain role.
I usually need to do this on most sites that I work on, so I have to write a function within a custom module. As D8 has the User::hasRole method, it would be great to have an equivalent available in D7.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2394517-5-user-has-role.patch | 671 bytes | opdavies |
Comments
Comment #1
opdaviesComment #2
opdaviesComment #3
misc commentedTested and looks ok for me.
Comment #4
opdavies@MiSc: Thanks for the review.
Comment #5
opdaviesUpdated the patch -
isset()is faster.Comment #6
opdaviesSetting back to "needs review" so that the testbot picks it up.
Comment #7
opdaviesThis is once again ready for community review.
Comment #8
opdaviesComment #9
tobiberlinTested and works fine
Comment #10
opdavies@tobiberlin: Thanks for the review!
Comment #11
David_Rothstein commentedSure, why not :) We could have tests for this, but given that it's basically a one-line function and isn't going to change, it's probably fine without them for now.
Committed to 7.x - thanks!
Fixed a couple documentation issues on commit:
Comment #13
opdavies@David_Rothstein: Thanks for committing the patch, and for those documentation changes.
Comment #14
vijaycs85awesome, don't we need a change notice?
Comment #15
David_Rothstein commentedSince it's just a new API function (and not something that means people really need to think about changing their existing code) I figured a release notes mention would be enough.
But if someone wants to write a change notice too, that would certainly be fine and I'd definitely link to it from the release notes.
Comment #16
vijaycs85Added https://www.drupal.org/node/2462411
Comment #17
David_Rothstein commentedLooks good - thanks!
I published the change notice and will make sure it gets linked to from the release notes, etc.
Comment #18
rajab natshahTesting :)
Rewarded work .