3

I'm using the Rules module, and I have a rule with these Rules Events:

  • After saving a new user account
  • After updating an existing user account

Within the Rules Conditions, I try to put "Data value is empty" -> account: (I don't found "picture", "image" or any of this)

I have: admin/config/people/accounts user images [check]

Any idea how I can check if the user has used a custom image?

3
  • Please ask one question at a time. This is Q&A, not a forum. If you have another question ask it as another question.
    – Mołot
    Jan 27, 2014 at 9:06
  • Try adding a 'Entity has field' condition to your Rule. Maybe the 'Picture' field shows up then.
    – Jeroen
    Jan 28, 2014 at 17:27
  • It wouldn't show up because $account->picture is not a field.
    – akalata
    Sep 15, 2014 at 17:47

2 Answers 2

3

Here's what I did, using a quick custom module to define and evaluate the condition that a user has uploaded a custom image to the core-provided Picture in the user account.

Module name: mymodule

This goes in mymodule.rules.inc:

/**
 * Implements hook_rules_condition_info()
 */
function mymodule_rules_condition_info() {
  return array(
    'mymodule_condition_user_has_picture' => array(
      'label' => t('User has picture'),
      'parameter' => array(
        'account' => array(
          'type' => 'user',
          'label' => t('User account')
        ),
      ),
      'group' => 'User',
    ),
  );
}

/**
 * Evaluates condition user_has_picture
 */
function mymodule_condition_user_has_picture($account) {
  if ($account->picture == NULL) {
    return false;
  } else {
    return true;
  }
}

Note that I've chosen to make the condition positive (returns TRUE if picture is found). If you want the condition to return true when the picture is NOT found, use the Negate option found in Rules.

0

Another variation for such Rules Condition (to "check if the user has used a custom image"), is to use the technique illustrated in the Community documentation within "Create a Rule to Evaluate If a Logged-in User Has Created Content of Type X". Here is the relevant part of it:

(Bullet 3.) Select the condition to add: "PHP > Execute custom PHP code".

(Bullet 4.) On the Add a new condition page, in the PHP code, Value field, enter ... In this code, the SQL query checks the database for ...

So with that, you've reduced the question to writing the appropriate SQL within that custom PHP code, and ensure the code returns true or false depending on the query result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.