You are here

workflow_workflow_ng.module in Workflow 5

Same filename and directory in other branches
  1. 5.2 contrib/workflow_workflow_ng/workflow_workflow_ng.module

File

contrib/workflow_workflow_ng/workflow_workflow_ng.module
View source
<?php

function workflow_workflow_ng_event_info() {
  $events = array(
    'workflow_transition_post' => array(
      '#label' => t('Workflow has been updated'),
      '#module' => t('Workflow'),
      '#arguments' => workflow_workflow_ng_events_workflow_arguments(),
    ),
  );
  return $events;
}

/*
 * Returns some arguments suitable for using it with a node
 */
function workflow_workflow_ng_events_workflow_arguments() {
  return array(
    'node' => array(
      '#entity' => 'node',
      '#label' => t('Node'),
    ),
    'state' => array(
      '#entity' => 'workflow',
      '#label' => t('Workflow State'),
      '#handler' => 'workflow_ng_events_argument_workflow_state',
    ),
    'author' => array(
      '#entity' => 'user',
      '#label' => t('Author'),
      '#handler' => 'workflow_ng_events_argument_node_author',
    ),
    'user' => array(
      '#entity' => 'user',
      '#label' => t('acting user'),
      '#handler' => 'workflow_ng_events_argument_global_user',
    ),
  );
}
function workflow_ng_events_argument_workflow_state($node) {
  return $node;
}
function workflow_workflow_ng_workflow($op, $old_state, $new_state, $node) {
  if (!module_exists('workflow_ng')) {
    return;
  }
  if (in_array($op, array(
    'transition pre',
    'transition post',
  ))) {
    $op = str_replace(" ", "_", $op);
    workflow_ng_invoke_event('workflow_' . $op, $node);
  }
}
function workflow_workflow_ng_configuration() {
  $conf['email_author_when_state_changes'] = array(
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'workflow_transition_post',
    '#label' => 'Email Author when workflow state changes',
    '#active' => 0,
    '#module' => 'workflow-ng',
    0 => array(
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_token_compare',
      '#negate' => 1,
      '#settings' => array(
        'text1' => '[state:workflow-current-state-name]',
        'text1_args' => array(
          0 => 'state',
        ),
        'text2' => '[state:workflow-old-state-name]',
        'text2_args' => array(
          0 => 'state',
        ),
        'regex' => 0,
      ),
      '#label' => 'Current State Name == Old state Name',
    ),
    1 => array(
      '#type' => 'action',
      '#name' => 'workflow_ng_action_mail_to_user',
      '#argument map' => array(
        'author' => 'user',
      ),
      '#settings' => array(
        'from' => '[node:site-mail]',
        'from_args' => array(
          0 => 'node',
        ),
        'subject' => 'State of [node:title] Changed',
        'subject_args' => array(
          0 => 'node',
        ),
        'message' => 'It is now [state:workflow-current-state-name]',
        'message_args' => array(
          0 => 'state',
        ),
      ),
      '#label' => 'Send Notification to Author',
    ),
    2 => array(
      '#type' => 'action',
      '#name' => 'workflow_ng_action_drupal_message',
      '#settings' => array(
        'message' => 'Mail has been sent to the author, notifying them of their ownership of [node:title]',
        'message_args' => array(
          0 => 'node',
          1 => 'state',
        ),
        'error' => 0,
      ),
    ),
    '#name' => 'cfg_2',
  );
  return $conf;
}