How to create "draft" programmatically with Drupal Workbench Moderation?
Asked Answered
G

1

6

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?

Goodall answered 29/8, 2014 at 19:56 Comment(0)
G
7

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.

Grim answered 4/9, 2014 at 21:37 Comment(2)
Thank you so much! I was getting hung up on the idea that Workbench Moderation was responsible for the revisioning. But it's the $node->revision = 1; that is the magic I was looking for.Goodall
That was the thing that caught me out too. :)Grim

© 2022 - 2024 — McMap. All rights reserved.