You are here

function workflow_menu in Workflow 5.2

Same name and namespace in other branches
  1. 5 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 34

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 content types.'),
    );
    $items[] = array(
      'path' => 'admin/build/workflow/edit',
      'title' => t('Edit workflow'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'workflow_edit_form',
      ),
    );
    $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',
      ),
    );

    // Add triggers page with multilevel local tasks.
    $items[] = array(
      'path' => 'admin/build/trigger/workflow',
      'title' => t('Workflow'),
      'callback' => 'actions_assign',
      'callback arguments' => array(
        'workflow',
      ),
      'access' => $access,
      'type' => MENU_LOCAL_TASK,
    );
    if (workflow_get_states()) {

      // Add a subtab for each workflow.
      $result = db_query("SELECT wid, name FROM {workflows}");
      $default_assigned = FALSE;
      while ($data = db_fetch_object($result)) {
        $items[] = array(
          'path' => 'admin/build/trigger/workflow/' . $data->wid,
          'title' => check_plain($data->name),
          'callback' => 'actions_assign',
          'callback arguments' => array(
            'workflow',
          ),
          'access' => $access,
          'type' => MENU_LOCAL_TASK,
        );
        $default_assigned = TRUE;
      }
    }
  }
  else {
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      $wid = workflow_get_workflow_for_type($node->type);

      // If a workflow has been assigned to this node type.
      if ($wid) {
        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;
}