For a "Page" node, I want to add an event that only acts on node edited by users who are not administrator user.

I use the following code, it doesn't work:

<?php [node:user-id] != 1 ? TRUE : FALSE; ?> 

No matter what I change; for Admin the event is getting called. I've checked all permutations and combinations of syntax (including return) but it seems that "Check a truth values" is getting ignored.

link|improve this question

61% accept rate
feedback

2 Answers

up vote 4 down vote accepted

The code you are using is not outputting any value; the PHP code you are writing is supposed to output 1 if the actions associated to the condition need to be executed, and 0 when they don't need to be executed.

The correct condition is the following one:

<?php echo ([node:author-uid] != 1); ?>

Alternatively, you can use the following one:

<?php echo ($author->uid != 1); ?>
  • Verify the token you are using is the correct one; the one I see with Drupal 6 is "[node:author-uid]."
  • The operator != already returns a boolean value; there is no need to convert it to a boolean, as you do with the code you have written. The "Truth value" field accepts also 1 and 0 as values; there is no need to convert a value to a boolean.

The description reported for "PHP Evaluation" is the following one:

PHP code inside of <?php ?> delimiters will be evaluated and replaced by its output. E.g. <? echo 1+1; ?> will be replaced by 2.

screenshot

To notice that the user with ID equal to 1 is a particular user to whom Drupal always give any permission defined from any module; this is the only user account that is treaded in this particular way. Administrator users don't have their user ID always equal to 1; if you are checking the user ID to verify if the user is an administration user, then you are doing it wrong. In Drupal, you usually check the permissions the user has with user_access().

link|improve this answer
feedback

In addition to kiamlaluno's answer describing the appropriate syntax, the other vital clue is that you must turn the PHP Filter module on. Otherwise, Rules interprets your input as plain text, which almost evaluates to TRUE in PHP. Turn the PHP Filter on, use the syntax in the other answer, and you should be all set.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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