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

Drupal example source code file (contact.install)

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

array, category, contact, default, description, function, list, not, null, php, true, type, weight

The contact.install Drupal example source code

<?php
// $Id: contact.install,v 1.26 2011/01/02 17:26:39 webchick Exp $

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

/**
 * Implements hook_schema().
 */
function contact_schema() {
  $schema['contact'] = array(
    'description' => 'Contact form category settings.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique category ID.',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Category name.',
        'translatable' => TRUE,
      ),
      'recipients' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Comma-separated list of recipient e-mail addresses.',
      ),
      'reply' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Text of the auto-reply message.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => "The category's weight.",
      ),
      'selected' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)',
      ),
    ),
    'primary key' => array('cid'),
    'unique keys' => array(
      'category' => array('category'),
    ),
    'indexes' => array(
      'list' => array('weight', 'category'),
    ),
  );

  return $schema;
}

/**
 * Implements hook_install().
 */
function contact_install() {
  // Insert a default contact category.
  db_insert('contact')
    ->fields(array(
      'category' => 'Website feedback',
      'recipients' => variable_get('site_mail', ini_get('sendmail_from')),
      'selected' => 1,
      'reply' => '',
    ))
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function contact_uninstall() {
  variable_del('contact_default_status');
  variable_del('contact_threshold_limit');
  variable_del('contact_threshold_window');
}

/**
 * @addtogroup updates-6.x-to-7.x
 * @{
 */

/**
 * Rename the threshold limit variable.
 */
function contact_update_7000() {
  variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
  variable_del('contact_hourly_threshold');
}

/**
 * Rename the administer contact forms permission.
 */
function contact_update_7001() {
  db_update('role_permission')
    ->fields(array('permission' => 'administer contact forms'))
    ->condition('permission', 'administer site-wide contact form')
    ->execute();
}

/**
 * Enable the 'access user contact forms' for registered users by default.
 */
function contact_update_7002() {
  // Do not use user_role_grant_permission() since it relies on
  // hook_permission(), which will not run for contact module if it is
  // disabled.
  db_merge('role_permission')
    ->key(array(
      'rid' => DRUPAL_AUTHENTICATED_RID,
      'permission' => 'access user contact forms',
      'module' => 'contact',
    ))
    ->execute();
}

/**
 * Change the weight column to normal int.
 */
function contact_update_7003() {
  db_drop_index('contact', 'list');
  db_change_field('contact', 'weight', 'weight', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => "The category's weight.",
  ), array(
    'indexes' => array(
      'list' => array('weight', 'category'),
    ),
  ));
}

/**
 * @} End of "addtogroup updates-6.x-to-7.x"
 */

Other Drupal examples (source code examples)

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