When I add a user role condition to a Rule, it renders as the rid in the overview:

However, when I select it, I'm selecting it based on the role name. It would be better for this to render using role names as well, but for the life of me I couldn't figure out where to do this. ; )

CommentFileSizeAuthor
#5 rules.patch998 bytesvasike
#3 rules.patch2.21 KBvasike

Comments

rszrama’s picture

Title: Show role titles instead of IDs on render » Show role names instead of IDs on render

Ooops, it's name, not title. : )

fago’s picture

Issue tags: +Novice

Makes sense. For that we have to fix the data type's UI class's render() method to take the options list into account.

vasike’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB

there's a solution, patch attached.

1. new definition in rules core data info -> modules/rules_core.rules.inc
list with 'ui class' => 'RulesDataUIListUserRoles',

2. new interface for user roles -> ui.data.inc
RulesDataUIListUserRoles extends RulesDataUIListText which use the names of roles

3. finally, the type of the "roles" parameter changed in user.rules.inc
from 'type' => 'list<integer>' to 'type' => 'list<userroles>'

fago’s picture

Status: Needs review » Needs work

It's not valid to introduce a new type name for integers, we have to stay with list. However, the role names should be already available in the 'options list' of the property - as seen in the form generation code. As described in #2, we can just use that information in render() to print the label instead of the key.

vasike’s picture

StatusFileSize
new998 bytes

ok. you know best the "rules"
other solution (or maybe just an ideea to solve this issue)
changed the element settings in buildcontent from ui/ui.core.inc

        if (is_array($this->element->settings[$name]) && $parameter['options list']) {
          $this->element->settings[$name] = array_intersect_key(call_user_func($parameter['options list']), $this->element->settings[$name]);
        }
fago’s picture

oh, I see render() has insufficient parameters. However, I don't think it is a good idea to pass in the label as $value, as it's just not the value (and the data type might be different). Let's better do a small API change and add pass the parameters $name, $info, $element to render() just as for form().

Fannon’s picture

Stumbled over this issue too.

Strangely it offers me 2 Options: [account:user-role-names] - [account:user-role-ids]

But both give me just the ID's which are quiet useless if you want to use them in emails etc.

Great Module by the way!

Simon

fago’s picture

Status: Needs work » Fixed

I've just committed a fix for that. Please re-open if it doesn't work for you with the next dev snapshot.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mitchell’s picture

Component: Provided Rules integration » Provided Module Integrations

Updated component.