Successfully reported this slideshow.
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
• Ta...
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
• T...
Drupal’s Extenisbility

• Drupal’s goal is “infinite extensibility” - this
  is what Drupal is generally optimizing for
• T...
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
  dat...
Database Abstraction
        Layer
• Drupal provides a procedural wrapper to
  provide support for multiple types of
  dat...
Database Abstraction
        Layer
• Drupal provides a procedural wrapper to
  provide support for multiple types of
  dat...
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 pri...
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
 ...
db_fetch_object
     db_fetch_array
• db_fetch_object() and db_fetch_array()
  fetch a row from the previous query as an
 ...
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 ...
The Hook System

• both core and contrib provide a set of
  “hooks” that your module can implement
  to add functionality ...
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...
Theme Registry
• modules must implement hook_theme to
  declare their themable functions and
  templates
• these functions...
Implementing
hook_theme()
Providing a default
 theme function
Providing a default
    template
Upcoming SlideShare
Loading in …5
×

Modules Building Presentation

824 views

Published on

  • Be the first to comment

  • Be the first to like this

Modules Building Presentation

  1. 1. Drupal Training Module Building
  2. 2. Preparing for Development
  3. 3. Preparing for Development • Have a clear development workflow
  4. 4. Preparing for Development • Have a clear development workflow • Learn (and adopt) Drupal’s coding standards
  5. 5. Preparing for Development • Have a clear development workflow • Learn (and adopt) Drupal’s coding standards • Take time to invest in your tools
  6. 6. Drupal’s Extenisbility
  7. 7. Drupal’s Extenisbility • Drupal’s goal is “infinite extensibility” - this is what Drupal is generally optimizing for
  8. 8. 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
  9. 9. 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!
  10. 10. The Anatomy of a Module
  11. 11. The Anatomy of a Module • my_module.info
  12. 12. The Anatomy of a Module • my_module.info • my_module.module
  13. 13. The Anatomy of a Module • my_module.info • my_module.module • my_module.install
  14. 14. Database Abstraction Layer
  15. 15. Database Abstraction Layer • Drupal provides a procedural wrapper to provide support for multiple types of databases (essentially MySQL and PostgreSQL)
  16. 16. 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
  17. 17. 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)
  18. 18. db_query()
  19. 19. db_query() • run a basic query in the active database
  20. 20. db_query() • run a basic query in the active database • any number of arguments are substituted into the query using printf() syntax.
  21. 21. db_fetch_result()
  22. 22. db_fetch_result() • Return an individual result (not row) from the previous query
  23. 23. db_fetch_result() • Return an individual result (not row) from the previous query
  24. 24. db_fetch_object db_fetch_array
  25. 25. 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
  26. 26. 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
  27. 27. drupal_write_record()
  28. 28. drupal_write_record() • Write or update a record in the database based upon the schema starting with an object or array
  29. 29. drupal_write_record() • Write or update a record in the database based upon the schema starting with an object or array
  30. 30. The Hook System
  31. 31. The Hook System • both core and contrib provide a set of “hooks” that your module can implement to add functionality to existing operations
  32. 32. 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
  33. 33. The Hook System • sample hook: • sample implementation: • called by:
  34. 34. The Anatomy of the php template engine
  35. 35. The Anatomy of the php template engine • Files
  36. 36. The Anatomy of the php template engine • Files • .info
  37. 37. The Anatomy of the php template engine • Files • .info • .template
  38. 38. The Anatomy of the php template engine • Files • .info • .template • .tpl.php
  39. 39. The Anatomy of the php template engine • Files • .info • .template • .tpl.php • javascript/css/images
  40. 40. Anatomy cont.
  41. 41. Theme Registry
  42. 42. Theme Registry • modules must implement hook_theme to declare their themable functions and templates
  43. 43. Theme Registry • modules must implement hook_theme to declare their themable functions and templates • these functions must be titled theme_function_name
  44. 44. 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
  45. 45. Implementing hook_theme()
  46. 46. Providing a default theme function
  47. 47. Providing a default template

×