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.

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.

  • 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 Sep 18 '12 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 Sep 18 '12 at 10:56
  • Glad you got it working :) – Aram Boyajyan Sep 18 '12 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);
  • 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 Sep 18 '12 at 10:43
  • which event you choosed? – Yusef Mohamadi Sep 18 '12 at 10:49
  • @vanz I choose After saving new content event and test it again, work charmly. – Yusef Mohamadi Sep 18 '12 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 Sep 18 '12 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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