You are here

function workflow_tab_access in Workflow 7

Same name and namespace in other branches
  1. 7.2 workflow.module \workflow_tab_access()

Menu access control callback. Determine access to Workflow tab.

@todo: this function is called several times per page. (for every menu path/menu trail) Use a page cache.

2 calls to workflow_tab_access()
workflow_node_tab_access in ./workflow.node.inc
Wrapper function for workflow_tab_access after renaming workflow_node_tab_access() to workflow_tab_access(), since *_tab_access() is a Workflow functionality, not Node API.
workflow_tab_form in ./workflow.pages.inc
Form builder. Allow workflow state change and scheduling from workflow tab. N.B. This function is only used for Node API, not Field API.
1 string reference to 'workflow_tab_access'
workflow_menu in ./workflow.module
Implements hook_menu().

File

./workflow.module, line 85
Support workflows made up of arbitrary states.

Code

function workflow_tab_access($node = NULL) {
  global $user;
  static $access = array();
  $entity_type = 'node';

  // @todo: support entity API in workflow_tab_access().
  $node_type = $node->type;
  if ($workflow = workflow_get_workflows_by_type($node_type, $entity_type)) {
    $nid = isset($node->nid) ? $node->nid : 0;

    // new nodes do not have a nid.
    if (isset($access[$user->uid][$nid])) {
      return $access[$user->uid][$nid];
    }
    $roles = array_keys($user->roles);
    if ($node->uid == $user->uid) {
      $roles = array_merge(array(
        'author',
      ), $roles);
    }
    $allowed_roles = $workflow->tab_roles ? explode(',', $workflow->tab_roles) : array();
    if (user_access('administer nodes') || array_intersect($roles, $allowed_roles)) {
      $access[$user->uid][$nid] = TRUE;
    }
    else {
      $access[$user->uid][$nid] = FALSE;
    }
    return $access[$user->uid][$nid];
  }
  return FALSE;
}