You are here

function workflow_actions_trigger_info in Workflow 7

Same name and namespace in other branches
  1. 7.2 workflow_actions/workflow_actions.module \workflow_actions_trigger_info()

Implements hook_hook_info(). Expose each transition as a hook.

1 call to workflow_actions_trigger_info()
workflow_actions_action_info_alter in workflow_actions/workflow_actions.module
Implementation of hook_drupal_alter().

File

workflow_actions/workflow_actions.module, line 15
Provide actions and triggers for workflows. Why it's own module? Some sites prefer rules, some prefer actions, all prefer a lower code footprint and better performance. Additional credit to gcassie ( http://drupal.org/user/80260 ) for the initial…

Code

function workflow_actions_trigger_info() {
  $states = array();
  foreach (workflow_get_workflow_states() as $data) {
    $states[$data->sid] = check_plain($data->state);
  }
  if (empty($states)) {
    return array();
  }
  $trigger_page = drupal_substr($_GET['q'], 0, 32) == 'admin/structure/trigger/workflow';

  // TODO these should be pulled into their own DB function calls.
  if ($trigger_page && ($wid = arg(4))) {
    $result = db_query('SELECT tm.type, w.wid, w.name, ws.state, wt.tid, wt.sid, wt.target_sid ' . 'FROM {workflow_type_map} tm ' . 'LEFT JOIN {workflows} w ON tm.wid = w.wid ' . 'LEFT JOIN {workflow_states} ws ON w.wid = ws.wid ' . 'LEFT JOIN {workflow_transitions} wt ON ws.sid = wt.sid ' . 'WHERE w.wid = :wid AND ws.status = 1 AND wt.target_sid IS NOT NULL ' . 'ORDER BY tm.type, ws.weight', array(
      ':wid' => $wid,
    ));
  }
  else {
    $result = db_query('SELECT tm.type, w.wid, w.name, ws.state, wt.tid, wt.sid, wt.target_sid ' . 'FROM {workflow_type_map} tm ' . 'LEFT JOIN {workflows} w ON tm.wid = w.wid ' . 'LEFT JOIN {workflow_states} ws ON w.wid = ws.wid ' . 'LEFT JOIN {workflow_transitions} wt ON ws.sid = wt.sid ' . 'WHERE ws.status = 1 AND wt.target_sid IS NOT NULL ' . 'ORDER BY tm.type, ws.weight');
  }
  $creation_state = t('(creation)');
  foreach ($result as $data) {
    $creation_flag = FALSE;
    if ($states[$data->sid] == $creation_state) {
      $creation_flag = TRUE;
    }
    $pseudohooks['workflow-' . $data->type . '-' . $data->tid] = array(
      'label' => t('When %type moves from %state to %target_state', array(
        '%type' => $data->type,
        '%state' => $states[$data->sid],
        '%target_state' => $states[$data->target_sid],
      )),
      'workflow_creation_state' => $creation_flag,
    );
  }

  // $pseudohooks will not be set if no workflows have been assigned
  // to node types.
  if (isset($pseudohooks)) {
    return array(
      'workflow' => $pseudohooks,
    );
  }
  if ($trigger_page) {
    drupal_set_message(t('Either no transitions have been set up or this workflow has not yet been ' . 'assigned to a content type. To enable the assignment of actions, edit the workflow to assign ' . 'permissions for roles to do transitions. After that is completed, transitions will appear here ' . 'and you will be able to assign actions to them.'));
  }
}