Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create "draft" programmatically with Drupal Workbench Moderation?

I've created a module to edit node content automatically. And the site is using the "Workbench Moderation" module.

But I can't figure out how to get the node to duplicate into a new revision (in "draft" status). My edited content always appears in the "published" version of the node.

Does anyone know what the API calls should be to make this happen?

like image 922
Douglas Choma Avatar asked Aug 29 '14 19:08

Douglas Choma


1 Answers

I was just having this issue myself. Key things:

  • The content type is under moderation via the workbench moderation module
  • Set the new moderation state
  • Set the node as being a new revision

Drupal takes care of the rest.

<?php
$node = node_load($nid);
$node->body[LANGUAGE_NONE][0]['value'] = 'My new body content';
// We're wanting drupal to create a new revision
$node->revision = 1;
// We want workbench moderation to treat the new revision as a new draft
$node->workbench_moderation_state_new = workbench_moderation_state_none();
node_save($node);

This is currently working in my codebase.

like image 125
Gold Avatar answered Oct 27 '22 09:10

Gold