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

Drupal example source code file (module_test.module)

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

access, array, dependency, elseif, file, function, hook, if, modules, php, poll, return, title, type

The module_test.module Drupal example source code

<?php
// $Id: module_test.module,v 1.10 2010/11/27 20:41:38 dries Exp $

/**
 * Implements hook_permission().
 */
function module_test_permission() {
  return array(
    'module_test perm' => t('example perm for module_test module'),
  );
}

/**
 * Implements hook_system_info_alter().
 *
 * Manipulate module dependencies to test dependency chains.
 */
function module_test_system_info_alter(&$info, $file, $type) {
  if (variable_get('dependency_test', FALSE) == 'missing dependency') {
    if ($file->name == 'forum') {
      // Make forum module depend on poll.
      $info['dependencies'][] = 'poll';
    }
    elseif ($file->name == 'poll') {
      // Make poll depend on a made-up module.
      $info['dependencies'][] = 'foo';
    }
  }
  elseif (variable_get('dependency_test', FALSE) == 'dependency') {
    if ($file->name == 'forum') {
      // Make the forum module depend on poll.
      $info['dependencies'][] = 'poll';
    }
    elseif ($file->name == 'poll') {
      // Make poll depend on php module.
      $info['dependencies'][] = 'php';
    }
  }
  if ($file->name == 'seven' && $type == 'theme') {
    $info['regions']['test_region'] = t('Test region');
  }
}

/**
 * Implements hook_hook_info().
 */
function module_test_hook_info() {
  $hooks['test_hook'] = array(
    'group' => 'file',
  );
  return $hooks;
}

/**
 * Implements hook_menu().
 */
function module_test_menu() {
  $items['module-test/hook-dynamic-loading-invoke'] = array(
    'title' => 'Test hook dynamic loading (invoke)',
    'page callback' => 'module_test_hook_dynamic_loading_invoke',
    'access arguments' => array('access content'),
  );
  $items['module-test/hook-dynamic-loading-invoke-all'] = array(
    'title' => 'Test hook dynamic loading (invoke_all)',
    'page callback' => 'module_test_hook_dynamic_loading_invoke_all',
    'access arguments' => array('access content'),
  );
  return $items;
}

/**
 * Page callback for 'hook dynamic loading' test.
 *
 * If the hook is dynamically loaded correctly, the menu callback should
 * return 'success!'.
 */
function module_test_hook_dynamic_loading_invoke() {
  $result = module_invoke('module_test', 'test_hook');
  return $result['module_test'];
}

/**
 * Page callback for 'hook dynamic loading' test.
 *
 * If the hook is dynamically loaded correctly, the menu callback should
 * return 'success!'.
 */
function module_test_hook_dynamic_loading_invoke_all() {
  $result = module_invoke_all('test_hook');
  return $result['module_test'];
}

/**
 * Implements hook_modules_enabled().
 */
function module_test_modules_enabled($modules) {
  // Record the ordered list of modules that were passed in to this hook so we
  // can check that the modules were enabled in the correct sequence.
  variable_set('test_module_enable_order', $modules);
}

/**
 * Implements hook_modules_disabled().
 */
function module_test_modules_disabled($modules) {
  // Record the ordered list of modules that were passed in to this hook so we
  // can check that the modules were disabled in the correct sequence.
  variable_set('test_module_disable_order', $modules);
}

/**
 * Implements hook_modules_uninstalled().
 */
function module_test_modules_uninstalled($modules) {
  // Record the ordered list of modules that were passed in to this hook so we
  // can check that the modules were uninstalled in the correct sequence.
  variable_set('test_module_uninstall_order', $modules);
}

Other Drupal examples (source code examples)

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