'Show when role is x ' would give an easy way to handle use cases that 'Hide when current user has role' won't manage.
Example A field 'Notes for authors' needs to be shown to users with role 'author', but not shown to other 'authenticated users'. This can't be handled by hiding the field for every role other than 'author' because each author is also an 'authenticated user' and if a user has any role in the 'Hide when...' list the field is hidden.
Alternatives / workaround:
- Add a role 'not-author' (or 'not-[whatever role]') and hide when that role is present - this'll do the job, but adding a role for this purpose seems overkill. It's good practice to avoid role proliferation where possible.
- Create a Rule to handle this case - this'll do the job and requires no change to the module. But it creates a configuration overhead that is (a) a bit onerous and (b) has to be done away from the manage display page (which doesn't seem great).
Views on the merit of this feature suggestion will probably turn on how common / rare you consider the use case mentioned. The case in favour of the feature is that a non-trivial proportion of users who find the 'Hide when current user has role' valuable will find its complement 'Show when current user has role' valuable too.
Code attached to first comment.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1950132-3.patch | 2.47 KB | obliquely |
| #2 | ffc ui.png | 29.63 KB | obliquely |
Comments
Comment #1
obliquely commentedUpdate One downside of initial suggestion is that the conditions drop down already has a good 7 entries and there's a risk of it getting unwieldy. The same end can be achieved by renaming the condition without reference to the action, i.e. 'Current user has role'. In the form, an extra element then defaults to the original behaviour, i.e. 'Hide only when condition is true' but also add an additional option 'Show only when condition is true'. This is cleaner UI.
The same approach could also be used to trim down the current set of conditions, e.g. the pair of entries Hide when target field is empty and Hide when target field is not empty could be collapsed into 'Target field is empty' and then provide the choice of options. (For upgrading users, it would be easier enough to spot the legacy condition and convert to new style.) And, mutatis mutandis, for the string matching condition. So the drop down could move from (at time of comment) 7 entries to 5 while increasing range of options by one.
The code in the patch attached to comment#3 adds the feature as outlined.
Comment #2
obliquely commentedUI looks like this:
Comment #3
obliquely commentedComment #5
jorditr commentedHi Mathew, I find your proposal very smart, thanks!