Basic Drupal module building

Primary tabs

Learned from

http://buildamodule.com/video/drupal-7-development-core-concepts-welcome-to-module-building-our-module-recreated-in-2-minutes-and-next-steps

  • cd sites/all/modules
  • mkdir <modulename>
  • cd <modulename>
  • edit <modulename>.info
    • name
    • description
    • package
    • core
    • files[]
  • edit <modulename>.module
    • edit function <modulename>_menu() (creates URL)
    • add “$items['<modulename>-<something>']”
    • add “page callback = '<modulename>_<something>' “
    • edit function <modulename>_<something>()
    • return content to be shown on screen
  • enable module
  • go to <drupalsite>/<modulename>-<something>

 

Learned from

http://buildamodule.com/video/drupal-7-development-core-concepts-how-to-build-module-scaffolding-setting-up-the-module-file-structure etc.

http://buildamodule.com/video/drupal-7-development-core-concepts-how-hooks-work-and-how-to-use-them-what-hooks-are-and-a-demo-of-our-final-module etc.

  • edit <modulename>.info
    • ; $Id$
    • configure = admin/config/<modulename>
    • dependencies[] = <some_other_module>
  • edit <modulename>.module
    • // $Id:$
    • Info about file
      • /**
      • * @file
      • * <text>
      • */
    • Info about functions
      • /**
      • * Implements hook_menu().
      • */
    • Content in <modulename>_menu()
      • $items['admin/config/<modulename>']
      • 'page arguments' => array('<modulename>-<stuff>')
      • <modulename>-<stuff>()
  • edit README.txt

Example:

example.info:

; $Id$
 
name = example
description = Example module
core = 7.x

example.module:

<?php
function example_menu(){
  $items['example'] = array(
    'title'            => t('Example module'),
    'page callback'    => 'example_output',
    'access arguments' => array('access content'),
  );

  return $items;
}

/*
* Display output
*/
function example_output() {
  return 'This is an example';
}

Other cool stuff

  • example.admin.inc: contains code needed for administration and configuration, is not needed on every page load.
  • white screen of death: tail /var/log/apache2/error.log (or something similar)
  • where is the tmp directory? check admin/config/media/file-system (d7)
  • when defining a page / menu item, a lot of times you don't define "access callback", so "user_access" will be called by default

This module is not perfect for me, what do I do?

  • The changes are very specific to us: Find the right hook, and create an extra module using that.
  • The changes are generic: Patch the module and upload the patch to drupal.org
  • I have a lot of time on my hands, and this module is important to me: Become a maintainer.
  • 75% functionality needs to be added, and I don't care about maintenance of the 25% already there: Make a copy of the module.

Choices: