how to programmatically change a node state from X to Y?

Events happening in the community are now at Drupal community events on www.drupal.org.
capcase's picture

i have a workflow associated with a particular node. how could I programmatically change
the node state from X to Y. because my node is also programmatically created via drupal_execute(...)

thanks!

Comments

actions_do() maybe

crashtest_'s picture

I am trying to do the same thing, as I want the state to always go from draft -> review when edited by the author of the node, so that the author and the reviewer can toss the node back and forth.

Currently I have created a custom action that will place the node in 'review' state and force it, however I am having a hard time figuring out the syntax for activating this via actions_do() in my form submit.

Any help on this? My code is like this currently (though bound to change in about 30 seconds :) ):

<?php
function library_node_form_submit($form, &$form_state) {
  if (
$user->uid == $node->uid) {
   
$context['target_sid'] = 3;
   
actions_do(10, $node, $context);
  }

?>

workflow_execute_transition($

nguyendhex@drupal.org's picture

workflow_execute_transition($node, $sid, $comment = NULL, $force = FALSE) may help you.

creating a new node with an initial state

liquidcms's picture

i would have thought this would work by simply setting something in the $node object prior to drupal_execute - but haven't stumbled upon the trick yet.

your method does work though

  drupal_execute('registration_node_form', $form_state, (object)$node);
 
  // now lets get our new node and set the state - since can't figure out how to do this any other way
  $node = node_load($form_state['nid']);
  workflow_execute_transition($node, $sid, NULL, true);

Works no more

manoj.surala's picture

Both the functions doesn't work anymore...

$node= node_load(nid);
workflow_transition($node, $sid);

$node= node_load(nid);
workflow_execute_transition($node, $sid, NULL, true);

Workflow

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: