Drupal Training




Module Building
Preparing for
Development
Preparing for
       Development
• Have a clear development workflow
Preparing for
        Development
• Have a clear development workflow
• Learn (and adopt) Drupal’s coding
  standards
Preparing for
         Development
• Have a clear development workflow
• Learn (and adopt) Drupal’s coding
  standards
• Take time to invest in your tools
Drupal’s Extenisbility
Drupal’s Extenisbility

• Drupal’s goal is “infinite extensibility” - this
  is what Drupal is generally optimizing for
Drupal’s Extenisbility

• Drupal’s goal is “infinite extensibility” - this
  is what Drupal is generally optimizing for
• The same APIs that define Drupal’s core
  functionality are available to you as a
  module developer
Drupal’s Extenisbility

• Drupal’s goal is “infinite extensibility” - this
  is what Drupal is generally optimizing for
• The same APIs that define Drupal’s core
  functionality are available to you as a
  module developer
• The hook system!
The Anatomy of a
    Module
The Anatomy of a
        Module

• my_module.info
The Anatomy of a
       Module

• my_module.info
• my_module.module
The Anatomy of a
        Module

• my_module.info
• my_module.module
• my_module.install
Database Abstraction
       Layer
Database Abstraction
        Layer
• Drupal provides a procedural wrapper to
  provide support for multiple types of
  databases (essentially MySQL and
  PostgreSQL)
Database Abstraction
        Layer
• Drupal provides a procedural wrapper to
  provide support for multiple types of
  databases (essentially MySQL and
  PostgreSQL)
• A thin (and somewhat outdated) wrapper
  around the underlying SQL
Database Abstraction
        Layer
• Drupal provides a procedural wrapper to
  provide support for multiple types of
  databases (essentially MySQL and
  PostgreSQL)
• A thin (and somewhat outdated) wrapper
  around the underlying SQL
• On it’s way out (Drupal 7 introduces a new
  db layer based on PDO)
db_query()
db_query()
• run a basic query in the active database
db_query()
• run a basic query in the active database
• any number of arguments are substituted
  into the query using printf() syntax.
db_fetch_result()
db_fetch_result()

• Return an individual result (not row) from
  the previous query
db_fetch_result()

• Return an individual result (not row) from
  the previous query
db_fetch_object
db_fetch_array
db_fetch_object
     db_fetch_array
• db_fetch_object() and db_fetch_array()
  fetch a row from the previous query as an
  object or array, respectively
db_fetch_object
     db_fetch_array
• db_fetch_object() and db_fetch_array()
  fetch a row from the previous query as an
  object or array, respectively
drupal_write_record()
drupal_write_record()
• Write or update a record in the database
  based upon the schema starting with an
  object or array
drupal_write_record()
• Write or update a record in the database
  based upon the schema starting with an
  object or array
The Hook System
The Hook System

• both core and contrib provide a set of
  “hooks” that your module can implement
  to add functionality to existing operations
The Hook System

• both core and contrib provide a set of
  “hooks” that your module can implement
  to add functionality to existing operations
• your module registers to be notified of a
  particular operation by implementing a
  hook
The Hook System
• sample hook:
• sample implementation:
• called by:
The Anatomy of the
php template engine
The Anatomy of the
  php template engine
• Files
The Anatomy of the
  php template engine
• Files
 • .info
The Anatomy of the
 php template engine
• Files
 • .info
 • .template
The Anatomy of the
 php template engine
• Files
 • .info
 • .template
 • .tpl.php
The Anatomy of the
  php template engine
• Files
 • .info
 • .template
 • .tpl.php
 • javascript/css/images
Anatomy cont.
Theme Registry
Theme Registry
• modules must implement hook_theme to
  declare their themable functions and
  templates
Theme Registry
• modules must implement hook_theme to
  declare their themable functions and
  templates
• these functions must be titled
  theme_function_name
Theme Registry
• modules must implement hook_theme to
  declare their themable functions and
  templates
• these functions must be titled
  theme_function_name
• theme(‘function_name’, $param) is then
  used to call the function
Implementing
hook_theme()
Providing a default
 theme function
Providing a default
    template

Modules Building Presentation