3

I have a very simple rule with Event "Before saving content" and Elements "Content is of type (page)" and would like the action to be something similar to "Change node author to UID X", which would be the UID I want.

I can't seem to be able to achieve that with the actions exposed. To test my rule I've been trying to display a message on the site when triggering the rule and it works just fine.

Any idea how to do that without having to write code?

This is on Drupal 7 (latest) with latest stable Rules version.

0

2 Answers 2

5

I think you can do this by adding a new action - "Fetch entity by ID", then selecting users and using that to update the node.

3
  • I've been trying the "Fetch entity by ID" and while it's promising since it does expose "User" and asks for an identifier, I'm not sure how to manipulate that data next to actually tell Rules I want to change the node author?
    – vanz
    Commented Sep 18, 2012 at 10:47
  • I think I made it work. Create "Fetch entity by ID" action with Entity type valye = User and identifier value = my_ID, then create another action "Set a data value" with selected data "node:author" and data selector "entity-fetched". Voila!
    – vanz
    Commented Sep 18, 2012 at 10:56
  • Glad you got it working :) Commented Sep 18, 2012 at 12:09
1

I have a suggestion for you for achieve this.(Its tested by myself).
create a new rule and in create node event(or every event you want ) , in action use Php(Execute custom PHP code)(make sure you php filter module installed).
and in there write this

 $mynode=node_load($node->nid);
 $mynode->uid='user_id_want';
 node_save($mynode);

-------------update------------
put your user id instead 'user_id_want'; as example

   $mynode=node_load($node->nid);
   $mynode->uid=20;
   node_save($mynode);
4
  • This PHP code is throwing the following message: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7562 of docroot/includes/common.inc).
    – vanz
    Commented Sep 18, 2012 at 10:43
  • which event you choosed?
    – Yuseferi
    Commented Sep 18, 2012 at 10:49
  • @vanz I choose After saving new content event and test it again, work charmly.
    – Yuseferi
    Commented Sep 18, 2012 at 10:53
  • as I said in my initial question, my goal is to make this work without code, which I was able to achieve just now (see my other comment). The method you are suggesting might probably work but I couldn't get around it. Thanks for the suggestion anyway.
    – vanz
    Commented Sep 18, 2012 at 11:13

Your Answer

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

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