Download & Extend

Allow modifying of allowable transitions

Project:Workflow
Version:6.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Jaza
Status:closed (won't fix)

Issue Summary

I'm using Workflow with OG, and I want particular workflow transitions to be available only to users with OG admin privileges over particular nodes.

I was looking at the workflow_allowable_transitions() function, to see if there was any way to alter the results it returns. The only possibility seems to be via hook_db_rewrite_sql(); but considering the complex UNION SQL query that this function performs, even that is probably not possible (and anyway modifying the DB query directly is not ideal).

Attached patch adds a hook_workflow_allowable_transitions_alter(), via a simple one-line drupal_alter() call.

AttachmentSize
workflow_transitions_alter.patch331 bytes

Comments

#1

FYI, here is my implementation of the new alter hook:

<?php
/**
* Implementation of hook_workflow_allowable_transitions_alter().
*/
function mymodule_workflow_allowable_transitions_alter(&$transitions, $sid, $dir, $roles) {
 
// List of 'to' transition states to check.
 
$sids = array(2, 3);

  if (
$dir == 'to' && in_array($sid, $sids)) {
   
// Get the node object for the current page (first param set to FALSE
    // means we don't have to be on a node view page, can also be on e.g. a
    // node editing or node workflow page).
   
$node = mymodule_get_curr_page_node(FALSE);

   
// If we're on a node page, and user is not a global admin, and user
    // is also not an OG admin for the current node, make certain transitions
    // unavailable.
   
if (!empty($node->nid) && !mymodule_check_role_access('administer nodes', $roles) && !og_is_group_admin($node)) {
     
// List of 'from' transitions to unset.
     
$unset_tids = array(4, 7, 8, 11);

      foreach (
$unset_tids as $tid) {
        unset(
$transitions[$tid]);
      }
    }
  }
}
?>

#2

Oops, my hook implementation above doesn't work (teach me to test before posting snippets!). og_is_group_admin() needs to be passed the node of the group, not the node of the current page (which is assigned to the group). Once again, this is just FYI, for people who want to achieve the same OG to Workflow integration that I've set up:

<?php
/**
* Implementation of hook_workflow_allowable_transitions_alter().
*/
function mymodule_workflow_allowable_transitions_alter(&$transitions, $sid, $dir, $roles) {
 
// List of 'to' transition states to check.
 
$sids = array(2, 3);

  if (
$dir == 'to' && in_array($sid, $sids)) {
   
// Get the node object for the current page (first param set to FALSE
    // means we don't have to be on a node view page, can also be on e.g. a
    // node editing or node workflow page).
   
$node = mymodule_get_curr_page_node(FALSE);
    if (!empty(
$node->og_groups) && is_array($node->og_groups)) {
     
reset($node->og_groups);
     
$og_nid = key($node->og_groups);
     
$group_node = node_load($og_nid);

     
// If we're on a node page, and user is not a global admin, and user
      // is also not an OG admin for the current node, make certain transitions
      // unavailable.
     
if (!empty($group_node->nid) && !mymodule_check_role_access('administer nodes', $roles) && !og_is_group_admin($group_node)) {
       
// List of 'from' transitions to unset.
       
$unset_tids = array(4, 7, 8, 11);

        foreach (
$unset_tids as $tid) {
          unset(
$transitions[$tid]);
        }
      }
    }
  }
}
?>

#3

Status:needs review» closed (won't fix)

Since this request is over 2 years old, I'm going to assume a solution was found or you've moved on. If not, please get updated to the latest versions of all modules and make a patch for it against Drupal 7 and I'll be glad to take a look at it.