home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (trigger_test.module)

This example Drupal source code file (trigger_test.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

action, array, configurable, context, function, label, php, return, system, test, triggers, true, type, user

The trigger_test.module Drupal example source code

<?php
// $Id: trigger_test.module,v 1.8 2010/06/29 18:24:10 dries Exp $

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

/**
 * Implements hook_action_info().
 */
function trigger_test_action_info() {
  // Register an action that can be assigned to the trigger "cron".
  return array(
    'trigger_test_system_cron_action' => array(
      'type' => 'system',
      'label' => t('Cron test action'),
      'configurable' => FALSE,
      'triggers' => array('cron'),
    ),
    'trigger_test_system_cron_conf_action' => array(
      'type' => 'system',
      'label' => t('Cron test configurable action'),
      'configurable' => TRUE,
      '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',
        '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(
        'label' => t('A test trigger is fired'),
      ),
    ),
    'trigger_test' => array(
      'trigger_test_triggertest' => array(
        'label' => t('Another test trigger is fired'),
      ),
    ),
  );
}

/**
 * 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);
}

/**
 * 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;
}

/**
 * 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', variable_get('trigger_test_generic_any_action', 0) + 1);
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal trigger_test.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.