Login

Module Development in Drupal 7 - Presentation Outline

What Are Modules
  • Customize, change and extend Drupal business functions.
    • You don't change the distributed Drupal source code. You add computer instructions in a module.

Community Modules versus Custom Modules

  • Community modules are generalized solutions.
  • Use Custom Modules for very specialized, narrowly scoped solutions. Modules are not required to be downloaded from Drupal.org.

Drupal 7 Runtime Requirments

  • PDO  -  Drupal 7 requires PDO enabled in your PHP environment.
    • PDO provides transaction support
    • PDO supports prepared statements
      • Prepared statements are faster (database engine caches the exection plan).
      • Prepared satements are safer, much less vulnerable to sql injection attacks.

Module Requirements

  • ".install" files now support implicit database table installation (and table drop). All you need to do is include schema expression.
  • ".info" files now allow you to declare file listings that are dynamically loaded. You don't need to use a PHP "include" expression for Drupal to find methods and objects provided in the dynamic load files. Dynamic loading allows Drupal to reduce your module's memory footprint (usage).

 Drupal Form API

  • Redirect moved from the $form object to the $form_state object.
  • Drupal 7 adds a set of "ajax" attributes that peform some partial page repaint.
    • drupal_set_message() and form_set_error() invoke full page paint. Therefore, we moved our validation and message notification in to our ajax response.
    • ajax response can be either a:

 Drupal Theme

  • Arguments to theme_table() are now required
    • Current version requires a minimum of 2 rows (a bug).

Drupal's Database Abstraction Layer

  • db_insert() is new to Drupal 7.
    • Closest relative in Drupal 6 is the drupal_write_record() method.
    • Both methods return the database autogen (serial) field values.
    • Db_Insert is a more elegant solution (easier to read, has an implicit return value -- drupal_write_record stores response in an object passed by reference).
  • db_query() in Drupal 7 returns a prepared statement
    • Drupal 6 db_query() returned a database query result object.
  • Method Chaining -- Since PDO is an Object Oriented Library it allows for method chaining. One exression can invoke many methods. Note! You may want to alter how much chaining you are using to control granularity of your exception handling.