[英]Add user role based on Profile2 Field Using Rules
What I am trying to achieve is: 1) I have a Profile2 field in the user registration form called: "Firm Type" 2) I need to assign the new user a Role based on the selection in this field. 我想要达到的目的是:1)我在用户注册表单中有一个Profile2字段,名称为:“ Firm Type” 2)我需要根据此字段中的选择为新用户分配一个Role。
I have tried the following: 我尝试了以下方法:
Event: After saving a new account Condition: Data Comparison: account:profile-additional-registration-info:field-profile-firm-type Action: Add a user role 事件:保存新帐户后条件:数据比较:account:profile-additional-registration-info:field-profile-firm-type 操作:添加用户角色
The above Rule works fine when I remove the condition. 当我删除条件时,上述规则可以正常工作。 As soon as I add the condition the rule does not work. 添加条件后,该规则将不起作用。 Digging into this I found out that Rule gets executed after Account is saved and before Profile2 is saved. 对此进行研究,我发现在保存帐户之后和保存Profile2之前将执行规则。
I looked online to find these 2 links helpful: https://www.drupal.org/node/1872384 https://www.drupal.org/node/2009878 我在网上寻找以下两个有用的链接: https : //www.drupal.org/node/1872384 https://www.drupal.org/node/2009878
1 suggestion was: Event: After saving a new profile Condition: Data Comparison: Profile2:field Action: Heres where the problem is -- I cannot get to the account level because its on a profile event. 一个建议是: 事件:保存新的配置文件后条件:数据比较:Profile2:field 操作:这是问题所在–我无法进入帐户级别,因为它在配置文件事件中。
Could you please help me figure this out. 你能帮我解决这个问题吗? Any help would be really appreaciated! 任何帮助将不胜感激! Thanks! 谢谢!
Here are the steps: 步骤如下:
Rules Event : After adding a new profile After updating an existing profile 规则事件 :添加新配置文件后更新现有配置文件后
Rules Condition : Negate User Has Roles: Check all roles other than a Public Role Data Comparison: profile2:field 规则条件 :否定用户具有角色:检查公共角色以外的所有角色数据比较:profile2:field
Rules Action : Set a Data Value: site:current-user:roles
规则操作 :设置数据值: site:current-user:roles
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.