drupal-7drupal-rules

How to make a new node with rules in Drupal 7


I had a previous question combining two questions on this subject...but I think I explained a little bit vague...too much story...so I will ask just one question at a time :)

I'm trying to create a node with a rule. Rules needs to create a new "product" node and show it to the user so that they can fill in some detail fields and then save it.

I'm trying to do this with Rules -> Create new entity. As "Entity type" I choose "Node" and as "Content type" I choose my product content type. Then I also need to fill in a title. There is where it goes wrong. I tried to put every type of data or string inside this Value field of Title and Rules accepts it and saves the rule. But every time the rules fails creating the node with the following error message:

Unable to create entity node": Invalid data value given. Be sure it matches the required data type and format.

How can I effectively create a new node of a certain content type and present it to the user for further finishing, all with rules?


Solution

  • You could just do it with code:

    global $user;
    $node = new stdClass;
    $node->type = 'type';
    $node->title = 'A title';
    $node->uid = $user->uid;
    node_object_prepare($node);
    node_save($node);
    
    drupal_goto("node/$node->nid");
    

    Hope that helps