I am reading Drupal 7 Module Development by
Matt Butcher, Greg Dunlap, Matt Farnia, Larry Garfield, Ken Rickard and Jon Albin Wilkins.
Inspired by the book, some Interesting Facts on Drupal Module Development that I wanted to share
- What is the hook implementation in Drupal?
EVENT Triggers in drupal: The Hook implementation is a function that follows a certain naming pattern in order to indicatie to Drupal that it should be used as a callback for a particular event in the Drupal System.
In most cases ensure the hook implementations reside within the main .module file.
- Placing your Custom modules:
OPTION1: The convention that we follow is to place both Contributed and Custom modules under sites/all/modules directory. All the custom modules are placed with in sites/all/modules/custom.
OPTION2: The second approach could be to have all Contributed modules under
sites/all/modules/contrib and any Custom modules under sites/all/modules/custom. This may not be a good solution as in Drupal 7 when you use Drush, the modules are automatically installed under sites/all/modules.
sites/all/modules/contrib and any Custom modules under sites/all/modules/custom. This may not be a good solution as in Drupal 7 when you use Drush, the modules are automatically installed under sites/all/modules.
OPTION3: The approach I read in the book seems really neat. Place all Contrib modules under sites/all/modules and all custom modules under sites/default/modules.
The main advantage being, it brings a clear separation between the modules maintained by us and those by the community.
The main advantage being, it brings a clear separation between the modules maintained by us and those by the community.
But in the case of a multisite installation where there is a need to share the custom modules across installations choose OPTION1
- The .info file in any module always starts with a $Id$. Have you wondered why?
This is a placeholder for the Version control system to store information about the file. ( When the file was last checked in and by who)
With the new GIT integration alive, this should be on the way out.
- Follow Doxygen-style commenting (/** */)
@file decorator for doc-block should be the first doc block of any module
Syntax: Begin with a single sentence Description of the module, followed by a blank line and then followed by a one or more paragraph description of the module.
ALL DOCS MUST BE WRITTEN IN GRAMATICALLY CORRECT AND PUNCTUATED SENTENCES.
$variable = ‘This is a string’ ;
t($variable) ;
Why wouldn’t translation system work above?
Automated Translation run, the code doesnot execute it only simply reads.
- Once a module is installed, Drupal caches the content of the .info file. Revisit the module page to force Durpal to refresh this information.
- Drupal arrays - terminate large multiline arrays with a comma: This is to help in avoiding syntax errors while adding or removing from a large array.
This can not be extended to drupal js arrays.
- 2 Most powerful Enhancements in Drupal 7
- PDI – PHP Data Object library integration in Durpal 7: This library is an abstraction layer that supports numerous database layer. This provides the capability for Drupal 7 to support beyond MYsql. Postgre-sql to Oracle and
- Fields and Entities
i. Field system: Bring with it CCKs functionality in the core
ii. Entity System: make sit possible to define structures data types that are not NODES!