Download & Extend

Creating an action to do a moderation state transition automatically

Project:Content moderation
Version:6.x-1.9
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hello,

I am trying to set up a workflow using this module to do something like the following
- user updates a node
- if user has a certain role, the moderation state is automatically set to "review"
- if user has a different role, the moderation state is set to "live"

Is it feasable to create a rule action that would automatically run the transition? I am looking for feedback including pros and cons of doing this. If there is another way to do it, I am open. Either way, I need to do this and am willing to write the code.

Thoughts?

Comments

#1

As a followup, since I needed to get this done ASAP for a project, I went ahead and wrote the code using hook_action_info(). I've pasted it below for review from the maintainer / community.

I've done a small amount of testing and so far it is working for me.

It seems like the next natural step would be to add some validation to the action to make sure the state transition is applicable to the current state of the revision, as well as the content type of the node. Perhaps it would be better to change the "from source state to destination state" concept in the action config to simply the destination state.

<?php
function content_moderation_action_info() {
 
$info = array();

 
$info['content_moderation_transition_action'] = array(
     
'type' => 'node',
     
'description' => t('Perform a transition between content moderation states'),
     
'configurable' => TRUE,
     
'hooks' => array(
       
'nodeapi' => array('presave', 'update', 'insert'),
      ),
  );

  return
$info;
}

function
content_moderation_transition_action_form($context) {
  static
$transitions = array();

 
// caching
 
if(count($transitions) == 0) {
   
$states = _content_moderation_states();

    foreach(
$states as $from_state) {
     
$to_states = _content_moderation_next_states($from_state);
       
// Values are translated.
     
$to_states = array_keys($to_states);
      foreach(
$to_states as $to_state) {
       
$transitions["{$from_state}|~|{$to_state}"] =
         
t("@from_state to @to_state", array('@from_state' => $from_state, '@to_state' => $to_state));
      }
    }
  }

 
$form['transition'] = array(
     
'#type' => 'select',
     
'#title' => t('Transition to Perform'),
     
'#description' => t('Choose the state transition to execute on the new node revision'),
     
'#options' => $transitions,
     
'#default_value' => isset($context['transition']) ? $context['transition'] : NULL,
     
'#required' => TRUE,
  );

  return
$form;
}

function
content_moderation_transition_action_submit($form, $form_state) {
  return array(
     
'transition' => $form_state['values']['transition'],
  );
}

function
content_moderation_transition_action($node, $context) {
  list(
$oldstate, $newstate) = explode('|~|', $context['transition']);

 
// Change the revision state.
 
_content_moderation_update_revision_state($node->vid, $node->nid, $newstate);

  if(
$nextstate == 'live') {
   
_content_moderation_set_live($node->vid,$node->nid);
  }

 
// History entry.
 
_content_moderation_save_history($node,$curstate,$nextstate,$user->uid,$comment);
}
?>

#2

Status:active» closed (works as designed)

Hello Noah,

This is sounding like something that would better live in it's own custom stand alone module that exposes the action to the rules/triggers system. The reason I think this is that there's a few other moderation systems out there that use rules and this is something that would compliment any of them.

With this having sat fallow for so long I'm going to close it for the moment. If you want to provide a patch against head and Eugen is okay with it I'll commit it though.

#3

Status:closed (works as designed)» active

Well this is a action / rules integration already, so we could stuff it into a submodule already. Iam full ack to not take this into the core module

@noah. Can you bringt this into a submodule so we can easily test on it?

nobody click here