trigger_test.module 3.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php
// $Id$

/**
 * @file
 * Mock module to aid in testing trigger.module.
 */

/**
 * Implementation of hook_action_info().
 */
function trigger_test_action_info() {
13
  // Register an action that can be assigned to the trigger "cron".
14 15 16
  return array(
    'trigger_test_system_cron_action' => array(
      'type' => 'system',
17
      'label' => t('Cron test action'),
18
      'configurable' => FALSE,
19
      'triggers' => array('cron'),
20
    ),
21 22
    'trigger_test_system_cron_conf_action' => array(
      'type' => 'system',
23
      'label' => t('Cron test configurable action'),
24
      'configurable' => TRUE,
25 26 27 28 29 30 31 32 33 34 35 36 37
      'triggers' => array('cron'),
    ),
    'trigger_test_generic_action' => array(
      'type' => 'system',
      'label' => t('Generic test action'),
      'configurable' => FALSE,
      'triggers' => array(
        'taxonomy_term_insert',
        'taxonomy_term_update',
        'taxonomy_delete',
        'comment_insert',
        'comment_update',
        'comment_delete',
38
        'user_presave',
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        'user_insert',
        'user_update',
        'user_delete',
        'user_login',
        'user_logout',
        'user_view',
      ),
    ),
    'trigger_test_generic_any_action' => array(
      'type' => 'system',
      'label' => t('Generic test action for any trigger'),
      'configurable' => FALSE,
      'triggers' => array('any'),
    ),
  );
}

/**
 * Implements hook_trigger_info().
 */
function trigger_test_trigger_info() {
  // Register triggers that this module provides. The first is an additional
  // node trigger and the second is our own, which should create a new tab
  // on the trigger assignment page.
  return array(
    'node' => array(
      'node_triggertest' => array(
        'runs when' => t('A test trigger is fired'),
      ),
    ),
    'trigger_test' => array(
      'trigger_test_triggertest' => array(
        'runs when' => t('Another test trigger is fired'),
72 73
      ),
    ),
74 75 76 77 78 79 80 81 82 83
  );
}

/**
 * Action fired during the "cron run" trigger test.
 */
function trigger_test_system_cron_action() {
  // Indicate successful execution by setting a persistent variable.
  variable_set('trigger_test_system_cron_action', TRUE);
}
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

/**
 * Implement a configurable Drupal action.
 */
function trigger_test_system_cron_conf_action($object, $context) {
  // Indicate successful execution by incrementing a persistent variable.
  $value = variable_get('trigger_test_system_cron_conf_action', 0) + 1;
  variable_set('trigger_test_system_cron_conf_action', $value);
}

/**
 * Form for configurable test action.
 */
function trigger_test_system_cron_conf_action_form($context) {
  if (!isset($context['subject'])) {
    $context['subject'] = '';
  }
  $form['subject'] = array(
    '#type' => 'textfield',
    '#default_value' => $context['subject'],
  );
  return $form;
}

/**
 * Form submission handler for configurable test action.
 */
function trigger_test_system_cron_conf_action_submit($form, $form_state) {
  $form_values = $form_state['values'];
  // Process the HTML form to store configuration. The keyed array that
  // we return will be serialized to the database.
  $params = array(
    'subject' => $form_values['subject'],
  );
  return $params;
}
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

/**
 * Action fired during the "taxonomy", "comment", and "user" trigger tests.
 */
function trigger_test_generic_action($context) {
  // Indicate successful execution by setting a persistent variable.
  variable_set('trigger_test_generic_action', TRUE);
}

/**
 * Action fired during the additional trigger tests.
 */
function trigger_test_generic_any_action($context) {
  // Indicate successful execution by setting a persistent variable.
  variable_set('trigger_test_generic_any_action', TRUE);
}