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

Drupal example source code file (trigger.install)

This example Drupal source code file (trigger.install) 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

actions, aid, array, default, description, function, hook, key, null, php, the, true, type

The trigger.install Drupal example source code

<?php
// $Id: trigger.install,v 1.17 2010/08/22 13:55:53 dries Exp $

/**
 * @file
 * Install, update and uninstall functions for the trigger module.
 */

/**
 * Implements hook_schema().
 */
function trigger_schema() {
  $schema['trigger_assignments'] = array(
    'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
    'fields' => array(
      'hook' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
      ),
      'aid' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "Primary Key: Action's {actions}.aid.",
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The weight of the trigger assignment in relation to other triggers.',
      ),
    ),
    'primary key' => array('hook', 'aid'),
    'foreign keys' => array(
      'action' => array(
        'table' => 'actions',
        'columns' => array('aid' => 'aid'),
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function trigger_install() {
  // Do initial synchronization of actions in code and the database.
  actions_synchronize();
}

/**
 * Adds operation names to the hook names and drops the "op" field.
 */
function trigger_update_7000() {
  $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");

  foreach ($result as $record) {
    db_update('trigger_assignments')
      ->fields(array('hook' => $record->hook . '_' . $record->op))
      ->condition('hook', $record->hook)
      ->condition('op', $record->op)
      ->condition('aid', $record->aid)
      ->execute();
  }
  db_drop_field('trigger_assignments', 'op');
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal trigger.install 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.