You are here

function workflow_menu in Workflow 5

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_menu()
  2. 6.2 workflow.module \workflow_menu()
  3. 6 workflow.module \workflow_menu()
  4. 7 workflow.module \workflow_menu()

Implementation of hook_menu().

File

./workflow.module, line 33

Code

function workflow_menu($may_cache) {
  $items = array();
  $access = user_access('administer workflow');
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/build/workflow',
      'title' => t('Workflow'),
      'access' => $access,
      'callback' => 'workflow_overview',
      'description' => t('Allows the creation and assignment of arbitrary workflows to node types.'),
    );
    $items[] = array(
      'path' => 'admin/build/workflow/edit',
      'title' => t('Edit workflow'),
      'type' => MENU_CALLBACK,
      'callback' => 'workflow_edit_page',
    );
    $items[] = array(
      'path' => 'admin/build/workflow/list',
      'title' => t('List'),
      'weight' => -10,
      'callback' => 'workflow_page',
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/workflow/add',
      'title' => t('Add workflow'),
      'weight' => -8,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_add_form',
      ),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/workflow/state',
      'title' => t('Add state'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_state_add_form',
      ),
    );
    $items[] = array(
      'path' => 'admin/build/workflow/state/delete',
      'title' => t('Delete State'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_state_delete_form',
      ),
    );
    $items[] = array(
      'path' => 'admin/build/workflow/delete',
      'title' => t('Delete workflow'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_delete_form',
      ),
    );
    $items[] = array(
      'path' => 'admin/build/workflow/actions',
      'title' => t('Workflow actions'),
      'type' => MENU_CALLBACK,
      'callback' => 'workflow_actions_page',
    );
    $items[] = array(
      'path' => 'admin/build/workflow/actions/remove',
      'title' => t('Workflow actions'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_actions_remove_form',
      ),
    );
  }
  else {
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      $wid = workflow_get_workflow_for_type($node->type);
      if ($wid) {

        // workflow exists for this type
        global $user;
        $roles = array_keys($user->roles);
        if ($node->uid == $user->uid) {
          $roles = array_merge(array(
            'author',
          ), $roles);
        }
        $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid));
        $allowed_roles = $workflow->tab_roles ? explode(',', $workflow->tab_roles) : array();
        $items[] = array(
          'path' => "node/{$node->nid}/workflow",
          'title' => t('Workflow'),
          'access' => array_intersect($roles, $allowed_roles) || user_access('administer nodes'),
          'type' => MENU_LOCAL_TASK,
          'weight' => 2,
          'callback' => 'workflow_tab_page',
          'callback arguments' => arg(1),
        );
      }
    }
  }
  return $items;
}