Rules for User Profiles

Events happening in the community are now at Drupal community events on www.drupal.org.
sj26's picture

I can't seem to find any information or module to do this. Before writing one, is there a simple module for adding rules to deal with normal, core profile.module fields? I'm not interested in Content Profile. Just want to subscribe newly created users to certain groups if profile field values are selected values.

Thanks!

Comments

You can use the PHP

bloke_zero's picture

You can use the PHP evaluation field - there is an $account object that you can query and then use a normal rules action to add role. You might need to load the user profile http://api.drupal.org/api/function/profile_load_profile/6 - profile_load_profile($account) - I'd try that before writing a new module.

I have been trying to do this

scottm316's picture

I have been trying to do this for 2 days. profile_load_profile is not working whatsoever on the $account object, which is supposed to be the one of the updated user. Keeping it simple, I can't get this to load any custom profile fields. Same as mentioned, this is in a custom PHP rule element, under DO. Any help is much appreciated!

$user_account=profile_load_profile($account);
var_dump($user_account);
exit;

I was starting to wonder if it's just not possible.

Got it - I think!

quentinsf's picture

I wanted to do something similar - for the purposes of testing, I wanted to set a role for any new user whose first name was 'Fred'!

Here's what seems to work:

* New rule on 'User account has been created'

* Add a condition 'Check a Truth value'

* Set the truth value to be the following PHP:

 
<?php
 
    $profile
= profile_load_profile($account); echo ($account->profile_firstname == "Fred");

?>

In reality, it will all be on one line. Note that profile_load_profile loads the profile fields into the variable you pass as the argument, not the value it returns!

This seems to work for me.

I ended up using a PHP Code

sj26's picture

I ended up using a PHP Code condition with:

<?php
return stripos(profile_load_profile($account)->profile_field, 'value') !== FALSE;
?>

This is still undesirable as the reason we're using Rules is that non-PHP users will be modifying the logic.

This can be done with token profile

friedman's picture

token_profile exposes all the profile fields to rules. You can write a condition using the token
in a textual comparison (The patterns are viewable on the condition form)
e.g. [account:user:profile_servreq]
The second field can be a regular expression.

see: http://drupal.org/project/token_profile

What about for d7?

BeaPower's picture

What about for d7?

Included!

itangalo's picture

For D7, functionality to deal with user profiles is included from start – users and user information is managed by entities and fields, and Rules can work with these by using Entity API.

I like Drupal 7. :-)

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: