0

I am using Workbench Moderation module for moderation on nodes. I notice that it creates revision of the nodes.

I have a node which is in live/publish state therefore it is available for the site visitors. Then when an editor edit that node, I programmatically put that node in needs review state and create a new revision for that node.

After that the site visitors are not able to access that node until its state change to publish.

I want that the new revision should be needs review state and the previous publish revision of the node should be available to site visitors.

The code which I am using for setting the state of the node is as following.

$node->status = 0;
$node->revision = 1;
node_save($node);
workbench_moderation_moderate($node, 'needs_review');
  • Why are you re-inventing the wheel? You should configure it so that editors can create new drafts. Then on the node view page a local task tab 'New Draft' becomes available, and they can edit the published revision to create a new draft, whilst the published revision remains intact. And if you then want to you can move a newly saved draft to needs review through Rules (or Action). I don't see the need for any custom code when out of the box you can configure it to your exact use case. – J. Reynolds Aug 6 '14 at 10:13
  • I have a different use case therefore I am using custom code. – Ahmad Aug 6 '14 at 11:56
0

I solved it.

Before the revisioning I loaded the original node first. Then first save the new revision and then save the original node.

My code now looks like this.

$original_node = node_load($nid);
$node = node_load($nid);
$node->revision = 1;
$node->workbench_moderation_state_new = 'needs_review';
node_save($node);
node_save($original_node);

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.