SlideShare a Scribd company logo
Drupal Module Development
“Hands-on”
Amit Vyas
http://drupal.org/user/246119
Rachit Gupta
https://drupal.org/user/403301
Overview
• Drupal Architecture
• Types of Drupal Modules
• Module Architecture
• Hooks 
• Hands On Module
Drupal Architecture
Technology Stack L(/W)AMP
Code Base (Drupal 7)
Database
Operating
System
Web Server
Language
Database Abstraction Layer
Technology Stack
Database
4
Types of Drupal Modules
Core Modules
Contributed Modules
Custom Modules
Core Modules
• Block:
Restricted to web administrator access only.
• Filter:
Authorized users and web administrators can choose from either
Filtered or Full HTML Input formats.
• Node:
Responsible for content.
• System:
Responsible for cron and caching.
Primary Web Site Admin. only.
• User:
User Management, Roles, Permissions.
Web administrator access only.
6
Contributed Modules
There are very high chances that what you are
looking for has already been developed 
 http://drupal.org/project/Modules
 http://drupalmodules.com/module-finder
 Google -> site:drupal.org/project <search
keywords> -cvs
No Luck!! 
Time to get hands dirty !!

How?
Custom Modules
• To extend functionality of contributed modules.
• To build features that are specific to your site.
• To build features that are not available through core or
contributed modules.
10
Make sure to look inside
related modules
Related =>
Modules that do things which are only
slightly different or slightly similar to the
things that you wound want your
module to do.
Module Architecture
“The building blocks of a module”
The .info file The .install file
The .module
file
The .inc file
.info file
• Drupal uses .info files (aka, "dot info files") to store metadata
about themes and modules. Various Drupal components use the
information in this file for module management.
• The .info file should have the same name as the .module file
and reside in the same directory. For example, if our module is
named drupal_training.module then your .info file should be
named drupal_training.info.
13
example.info File
name = “Drupal Training”
description = “Module for Drupal Training Day”
core = 7.x
package = “Training”
name (Required) The displayed name of your module. It should follow
the Drupal capitalization standard: only the first letter of the first word is
capitalized ("Example module"). Spaces are allowed as the name is used
mainly for the display purposes.
description (Required) A short, preferably one line description that will tell the
administrator what this module does on the module administration page.
core (Required) The version of Drupal that your module is for. For Drupal 6 this would
be 6.x, Drupal 7 would be 7.x, etc.
14
.inc file
• When Drupal loads a page, it loads all the .modules files of all
the active/enabled modules.
• If you have .inc (aka dot inc) file then .module will be loaded
when page loads BUT the inc file will not be loaded
• .inc file will be loaded for the specific page/path
• .inc file helps to reduce code loaded on a specific page/path
• hook_menu allows you to specify a .inc file for a specific path
15
Introduction to Hooks
What are hooks?
Why should I care?
16
What are hooks?
• A hook is really nothing more than a function that matches the
pattern of a call to the module functions .
• You can say that hook is a simple callback function that is called
on specific events.
• Pattern modulename_hookname()
• For example, if you want to do some operation on user
login, say sending an email to administrator on user logins into
the site, then no need to change the code in user module.
• Implement hook_user on your own module say “alert” by
defining function in your module file called alert_user and write
code to send an email to administrator here.
17
Why should I care?
• Modules Extends it’s functionality through hook system.
• One module communicates through other module through
hooks.
• The Hooks API provides a common naming standard for
hooks, allowing developers to implement them in custom
modules without needing to engage in extensive programming.
• The Hooks API allows developers to create their own hooks that
other modules can access, that leverage the same techniques
used in core Drupal.
• Many hooks are state aware, and operate differently depending
on what Drupal is actually doing when the hook is triggered.
18
Permissions, Access Control
hook_permission
hook_menu
Define menu items and page
callbacks.
Modify an existing form
hook_form_alter
Node operations
“The king of all hooks”
hook_nodeapi
Major hooks
 http://api.drupal.org/api/function/hook_user
 Gotcha: Not implementing the case delete.
Especially dangerous when modules own
tables have user related data. Just do it in the
memory of node/8
 http://api.drupal.org/api/function/hook_cron
 http://api.drupal.org/api/function/hook_block
Tools we can use…
 DATABASE API
 http://api.drupal.org/api/function/drupal_write_records
 http://api.drupal.org/api/function/user_roles
 http://api.drupal.org/api/function/format_interval
 http://api.drupal.org/api/function/user_multiple_role_edit
 http://api.drupal.org/api/function/user_load
 http://api.drupal.org/api/function/drupal_mail
 http://api.drupal.org/api/function/watchdog
 ~ 2200 more
25
Amit Vyas
http://drupal.org/user/246119
Rachit Gupta
https://drupal.org/user/403301

More Related Content

PPTX
Drupal Introduction - Why enterprises should use it
PDF
Showcasing drupal
PDF
Drupal 7
PPTX
Drupal Training Topics
PPTX
Introducing Joomla! CMS
PPTX
Microsoft Web Technology Stack
PPTX
Drupal7 an introduction by ayushiinfotech
PDF
WordPress as a CMS - Case Study of an Organizational Intranet
Drupal Introduction - Why enterprises should use it
Showcasing drupal
Drupal 7
Drupal Training Topics
Introducing Joomla! CMS
Microsoft Web Technology Stack
Drupal7 an introduction by ayushiinfotech
WordPress as a CMS - Case Study of an Organizational Intranet

What's hot (20)

PPTX
Leveraging Open Source Library Guides: Integrating Koha and SubjectsPlus
PPT
Open Source Content Management Systems
PDF
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
PDF
Drupal Performance Audit and Optimization
PDF
Brian Campo, DoD JCS, Content.gov Presentation
PPTX
Open source wordpress and drupal
PPTX
10reasons to choose_drupal
PDF
10reasons to choose_drupal
PPTX
MongoDB and MongoMK Source Event
PPTX
You Can Be an Open Source Library
PDF
Moving from PHP to a nodejs full stack CMS
PDF
Keystone.js 101
PPTX
Content Management System - CMS
PPTX
Static Site Generators - Developing Websites in Low-resource Condition
PPTX
Melbourne User Group OAK and MongoDB
PPTX
Customising civicrm
ODP
PPTX
Multisite wp in education wc philly2011
PPTX
Drupal Skils Lab 302Labs
PPTX
Leveraging Open Source Library Guides: Integrating Koha and SubjectsPlus
Open Source Content Management Systems
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
Drupal Performance Audit and Optimization
Brian Campo, DoD JCS, Content.gov Presentation
Open source wordpress and drupal
10reasons to choose_drupal
10reasons to choose_drupal
MongoDB and MongoMK Source Event
You Can Be an Open Source Library
Moving from PHP to a nodejs full stack CMS
Keystone.js 101
Content Management System - CMS
Static Site Generators - Developing Websites in Low-resource Condition
Melbourne User Group OAK and MongoDB
Customising civicrm
Multisite wp in education wc philly2011
Drupal Skils Lab 302Labs
Ad

Viewers also liked (16)

PPTX
Presentación Baby (miniempresa)
PDF
Coursera Human-Computer Interaction
PPTX
Presentation1.PPTX
PDF
Filme3
PPTX
Characteristics of living things
DOCX
Lista de aprendizajes esp.erados
PDF
Marato pobresa omnia solsona bloc 2
DOC
Practica 8 m10 7b
PDF
DE - ES Property aposta em projectos de reabilitação urbana - Miguel Guede...
PDF
Actividad 12
PDF
December 2016 Redondo Beach Real Estate Market Trends Update
PDF
Raci myo
PPT
Estetica corporal
DOC
Actividad 12 responsabilidad de la administración
PDF
Viaje cultural a Colmenar de Oreja
PPTX
Curso auditoria ohsas 18001 1
Presentación Baby (miniempresa)
Coursera Human-Computer Interaction
Presentation1.PPTX
Filme3
Characteristics of living things
Lista de aprendizajes esp.erados
Marato pobresa omnia solsona bloc 2
Practica 8 m10 7b
DE - ES Property aposta em projectos de reabilitação urbana - Miguel Guede...
Actividad 12
December 2016 Redondo Beach Real Estate Market Trends Update
Raci myo
Estetica corporal
Actividad 12 responsabilidad de la administración
Viaje cultural a Colmenar de Oreja
Curso auditoria ohsas 18001 1
Ad

Similar to Drupal module development (20)

PDF
Blisstering drupal module development ppt v1.2
PPTX
Top 20 mistakes you will make on your 1st Drupal project
PPTX
Rapid site production with Drupal
PPTX
Oleksandr Medvediev - Content delivery tools in Drupal 8.
PDF
Drupal 8 - Core and API Changes
PPTX
Drupal8 corporate training in Hyderabad
PDF
Introduction To Drupal
PPTX
Top 8 Improvements in Drupal 8
PDF
Everything You Need to Know About the Top Changes in Drupal 8
PPT
Dn D Custom 1
PPT
Dn D Custom 1
PDF
Your first d8 module
PDF
Intro to Drupal Module Developement
PDF
13th Sep, Drupal 7 advanced training by TCS
DOC
Drupal6 and Drupal 7 difference
ODP
Drupal 7x Installation - Introduction to Drupal Concepts
ODP
Custom module and theme development in Drupal7
PPTX
Drupal 7 Features - Introduction - Basics
PPT
Architecture of Drupal - Drupal Camp
Blisstering drupal module development ppt v1.2
Top 20 mistakes you will make on your 1st Drupal project
Rapid site production with Drupal
Oleksandr Medvediev - Content delivery tools in Drupal 8.
Drupal 8 - Core and API Changes
Drupal8 corporate training in Hyderabad
Introduction To Drupal
Top 8 Improvements in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
Dn D Custom 1
Dn D Custom 1
Your first d8 module
Intro to Drupal Module Developement
13th Sep, Drupal 7 advanced training by TCS
Drupal6 and Drupal 7 difference
Drupal 7x Installation - Introduction to Drupal Concepts
Custom module and theme development in Drupal7
Drupal 7 Features - Introduction - Basics
Architecture of Drupal - Drupal Camp

More from Rachit Gupta (6)

PPT
Drupal training day by Rachit Gupta
PPTX
Drupal development environment
PPTX
Drupal terminology
PPTX
Drupal as CMS
PPTX
Introduction to drupal
PPTX
Drupal website in 45 mins
Drupal training day by Rachit Gupta
Drupal development environment
Drupal terminology
Drupal as CMS
Introduction to drupal
Drupal website in 45 mins

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools

Drupal module development

  • 1. Drupal Module Development “Hands-on” Amit Vyas http://drupal.org/user/246119 Rachit Gupta https://drupal.org/user/403301
  • 2. Overview • Drupal Architecture • Types of Drupal Modules • Module Architecture • Hooks  • Hands On Module
  • 3. Drupal Architecture Technology Stack L(/W)AMP Code Base (Drupal 7) Database
  • 5. Types of Drupal Modules Core Modules Contributed Modules Custom Modules
  • 6. Core Modules • Block: Restricted to web administrator access only. • Filter: Authorized users and web administrators can choose from either Filtered or Full HTML Input formats. • Node: Responsible for content. • System: Responsible for cron and caching. Primary Web Site Admin. only. • User: User Management, Roles, Permissions. Web administrator access only. 6
  • 7. Contributed Modules There are very high chances that what you are looking for has already been developed   http://drupal.org/project/Modules  http://drupalmodules.com/module-finder  Google -> site:drupal.org/project <search keywords> -cvs
  • 9. Time to get hands dirty !!  How?
  • 10. Custom Modules • To extend functionality of contributed modules. • To build features that are specific to your site. • To build features that are not available through core or contributed modules. 10
  • 11. Make sure to look inside related modules Related => Modules that do things which are only slightly different or slightly similar to the things that you wound want your module to do.
  • 12. Module Architecture “The building blocks of a module” The .info file The .install file The .module file The .inc file
  • 13. .info file • Drupal uses .info files (aka, "dot info files") to store metadata about themes and modules. Various Drupal components use the information in this file for module management. • The .info file should have the same name as the .module file and reside in the same directory. For example, if our module is named drupal_training.module then your .info file should be named drupal_training.info. 13
  • 14. example.info File name = “Drupal Training” description = “Module for Drupal Training Day” core = 7.x package = “Training” name (Required) The displayed name of your module. It should follow the Drupal capitalization standard: only the first letter of the first word is capitalized ("Example module"). Spaces are allowed as the name is used mainly for the display purposes. description (Required) A short, preferably one line description that will tell the administrator what this module does on the module administration page. core (Required) The version of Drupal that your module is for. For Drupal 6 this would be 6.x, Drupal 7 would be 7.x, etc. 14
  • 15. .inc file • When Drupal loads a page, it loads all the .modules files of all the active/enabled modules. • If you have .inc (aka dot inc) file then .module will be loaded when page loads BUT the inc file will not be loaded • .inc file will be loaded for the specific page/path • .inc file helps to reduce code loaded on a specific page/path • hook_menu allows you to specify a .inc file for a specific path 15
  • 16. Introduction to Hooks What are hooks? Why should I care? 16
  • 17. What are hooks? • A hook is really nothing more than a function that matches the pattern of a call to the module functions . • You can say that hook is a simple callback function that is called on specific events. • Pattern modulename_hookname() • For example, if you want to do some operation on user login, say sending an email to administrator on user logins into the site, then no need to change the code in user module. • Implement hook_user on your own module say “alert” by defining function in your module file called alert_user and write code to send an email to administrator here. 17
  • 18. Why should I care? • Modules Extends it’s functionality through hook system. • One module communicates through other module through hooks. • The Hooks API provides a common naming standard for hooks, allowing developers to implement them in custom modules without needing to engage in extensive programming. • The Hooks API allows developers to create their own hooks that other modules can access, that leverage the same techniques used in core Drupal. • Many hooks are state aware, and operate differently depending on what Drupal is actually doing when the hook is triggered. 18
  • 20. hook_menu Define menu items and page callbacks.
  • 21. Modify an existing form hook_form_alter
  • 22. Node operations “The king of all hooks” hook_nodeapi
  • 23. Major hooks  http://api.drupal.org/api/function/hook_user  Gotcha: Not implementing the case delete. Especially dangerous when modules own tables have user related data. Just do it in the memory of node/8  http://api.drupal.org/api/function/hook_cron  http://api.drupal.org/api/function/hook_block
  • 24. Tools we can use…  DATABASE API  http://api.drupal.org/api/function/drupal_write_records  http://api.drupal.org/api/function/user_roles  http://api.drupal.org/api/function/format_interval  http://api.drupal.org/api/function/user_multiple_role_edit  http://api.drupal.org/api/function/user_load  http://api.drupal.org/api/function/drupal_mail  http://api.drupal.org/api/function/watchdog  ~ 2200 more