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.
Posted by capcase on February 9, 2009 at 7:52pm

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

Posted by crashtest_ on May 18, 2009 at 10:59pm

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($

Posted by nguyendhex@drup... on July 23, 2009 at 10:49am

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

creating a new node with an initial state

Posted by liquidcms on November 3, 2010 at 6:39pm

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

Posted by manoj.surala on May 7, 2017 at 5:35am

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:

AltStyle によって変換されたページ (->オリジナル) /