Active
Project:
Role Reference
Version:
7.x-1.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Jun 2012 at 17:10 UTC
Updated:
4 Dec 2017 at 01:40 UTC
Jump to comment: Most recent
It appears that this module does not work with rules. I am trying to setup a coupon type on drupal commerce that has a role reference field with the intention to have the coupon be limited to the roles selected. This was originally discussed here: http://drupal.org/node/1466622
Having tried this now, I am unable to get the role reference field to be available when setting up a rules condition to check which roles have been selected using this field. My assumption, seeing as there are no other issues addressing rules integration with this module is that it simply hasn't happened. Thus the feature request.
Any help is appreciated. Thanks!
Comments
Comment #1
Jorrit commentedThe fix is very simple:
edit rolereference.module, and insert the following piece of code in
rolereference_field_info():'property_type' => 'integer',Such that it becomes:
Now clear your caches. Rules will now detect your field to be a list of integers (if cardinality > 1) or an integer (if cardinality = 1). I am now able to use the roles reference field as input for the "Add user role" action.
If you don't want to edit a contributed module, you can add the following code in your own module:
Comment #2
RyanPrice commentedThanks Jorrit,
I can confirm this does the trick and is already rolled into the 7.x-1.x-dev version.
Comment #3
RyanPrice commentedClosing as its already been rolled.
Comment #4
Jorrit commentedOK, sorry I hadn't seen that. Could a new release be created?
Comment #5
RyanPrice commentedI only saw it because I was going to submit a patch with your solution only to find it was already there in the dev release.
I have no idea what the maintainer's plan is for a release schedule.
Comment #6
gregsomers commentedThis doesn't seem to be working. In the database, the type of this field is stored as rolereference. Rules is looking for type list_integer to assign roles..
The data selector does not allow me to use a rolereference field to assign a user roles.
Thoughts?
EDIT: on further inspection, it fails the rules type check RulesData::typesMatch
Comment #7
juliakoelsch commentedHi, I ran into this issue also, and there is an issue in the Rules issue queue that can help fix this. Once you apply the patch, you will need to create an action called "Generate a list from an integer". Choose your rolereference field and create a variable. Then, create a second action to assign roles, refer to the variable created in the first action. The Rules issue containing the patch is here: https://drupal.org/node/1525582
I'm not sure if there is something that RuleReference can change to prevent the need for having to manually create a list from the field value, so leaving the issue open.
Comment #8
rjbrown99 commentedThanks for this, although it didn't help in my case. Rules was still unable to see rolereference integer values and the Rules patch (referenced in #7) created a list of ALL roles (starting with 0) instead of just picking up one single role.
In my case, I wanted to read the single role value from a source node and use it to built access to a destination node. My solution was:
Step 1. Add a variable
- Type integer
- value: node:nid (the source node that has the rolereference field)
- php evaluation (where my node's rolereference field is called field_webform_role)
That left me with a variable with the integer role # of the role in question. Secondly:
Step 2. Add a variable
- List of integer
- (no value, just create the list)
Step 3. Add an item to a list
- Use the list created above in step 2.
- Use the data selector created in step 1.
In my case I'm using this content access patch: https://www.drupal.org/project/content_access/issues/1464948
I was then able to use my list as input to that rule to set the appropriate permissions on the created node.
Step 1 is non-ideal but rules won't pick up or allow me to use the value here because it's not stored as an integer. The patch from #7 would create a list such as (1,2,3,4,5,6,7) if your original role ID was 7. In my case that would grant access to all roles #1-7 when used, which is not what I wanted.
Hope that helps someone else.