SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
My first Drupal module!
Why not?
About @ Gajendra Sharma

• Started as PHP developer with
custom CMS
•“You need Linux” they said
•I know Drupal since version 5.x
Email: gajen.ksharma@gmail
Skype: gajendrakumarsharma1688
LinkedIn: www.linkedin.com/in/gajendrasharma
Drupal
•  Available from drupal.org.
•  Runs on every machine with
PHP, supported database
and web server.
•  Very customizable
(themes, modules).
•  Good documented.
•  No limits.
A whole bunch of modules
Which one to use?
Missing a module?
Three kinds of modules (3 Cs)
•  Core
–  Shipped with Drupal
–  Approved by core developers and community

•  Contributed
–  Written by community
–  Shared under the same GNU Public License

•  Custom
–  Created by website developer
Where to?

Drupal
Core Modules Core Themes
Contributed
Modules

Contributed Themes

Custom Module

Custom Theme

/sites/[all|mysite.com]/custom
Module name
•  Should be a UNIQUE “short name”
•  Used in all file and function names
•  Must start with a letter
•  Only lower-case letters and underscores

•  We will use name: “dc_stat”
–  For display current node/user stats
Create a folder + module file
•  Module name “dc_stats”.
•  Create empty folder:
–  /sites/*/modules/custom/dc_stats/

•  Create new file “dc_stats.module” with
opening PHP tag and NO closing tag!!
•  Create new file “dc_stats.info” for

meta information.
*.info
•  Required for every module!
•  Standard .ini file format – key/value pairs
name = Drupal statistic!
description = Provides some statistic data.!
core = 7.x!
package = Damjan Cvetan!

Other optional keys:
stylesheets, scripts, files, dependencies, …
Checkpoint
•  Navigate to Modules section on your site

•  You should see your module
•  Enable it!
Coding standards
•  Use an indent of 2 spaces, no tabs!

• 
• 
• 
• 

UNIX line ending (n)
Omit closing “?>” PHP tag
Constants should be all-uppercase
Comments are your friends!
Half way there
Hook(s)
hook – [hoo k], noun Ÿ a
curved or angular piece of
metal or other hard
substance for catching,
pulling, holding, or
suspending something.

•  Fundamental to Drupal
How does it work?

Call dispatch

Foreach (enabled_module):!
module_name_menu();!
end foreach;!

Call for hook:
hook_menu()
Drupal runFme

locale_menu()!
user_menu()!
contact_menu()!
help_menu()!
…!
…!
dc_stats_menu()!
…!
…!
trigger_menu()!
path_menu()!

Drupal runFme
Hooks line up!
•  hook_help() – Provides
available documentation.
•  hook_menu() – For paths registration
in order to define how URL request
are handled.
•  hook_init() – Run at the beginning of
page request.
•  hook_cron() – Called whenever a cron
run happens.
•  More at http://api.drupal.org/
API.drupal.org
•  Drupal developer’s documentation.
•  Doc for Drupal 4.6+.
•  Describes function calls, their
parameters and return values.
•  You can see the code and “who” is
calling this code within Drupal.
•  http://api.drupal.org
Let’s code
•  Define callback function dc_stats_page()
as follows:
funcFon dc_stats_page(){
return "Hello world! You’re awesome!”;
}

•  This will return defined string on call.
•  Put this code in dc_stats.module file.
Hey Drupal! Come in!
•  Register path with hook_menu().
•  We will use basic return array structure.
funcFon dc_stats_menu(){
$items['dc/stats-page'] = array(
'Ftle' => 'Stats info page',
'page callback' => 'dc_stats_page',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}

Visit URL: /dc/stats-page to see if it works.
(You might need to clear cache first.)
Get some real data
funcFon dc_stats_page(){
drupal_set_Ftle("Drupal staFsFcs");
$node_count = $db_node_count;
$user_count = $db_users_count;
$header = array("InformaFon", "Value");
$rows[] = array('Number of nodes:', $node_count);
$rows[] = array('Number of users:', $user_count);
return theme_table(array( 'header' => $header,
'rows' => $rows,

…
…
)); // return
}
Happy ending
•  Refresh your page and see your work.

•  You can do much more – I’m certain!
•  Use your PHP + any other knowledge
with existing Drupal functions, hooks
and variables!
Links to consider
•  http://api.drupal.org
http://drupalcontrib.org/
•  http://buildamodule.com/
•  http://drupal.org/project/devel
–  A suit of modules containing fun for
module developers and themers.
Books
•  Drupal 7 Development by Example

•  Beginning Drupal 7
•  Drupal 7 Module Development
•  …
•  …
Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Flying with Griffon @ CONFESS
Flying with Griffon @ CONFESSFlying with Griffon @ CONFESS
Flying with Griffon @ CONFESSAndres Almiray
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
HTTP cache: keeping it fresh
HTTP cache: keeping it freshHTTP cache: keeping it fresh
HTTP cache: keeping it freshDavid de Boer
 
Week6 office-hours
Week6 office-hoursWeek6 office-hours
Week6 office-hoursRandall Rode
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Mark Hamstra
 
Introducing MongoPress
Introducing MongoPressIntroducing MongoPress
Introducing MongoPressMark Smalley
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureBarry Jones
 
Front End Development Automation with Grunt
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with GruntLadies Who Code
 
Putting "Phings" together - how to automate your life
Putting "Phings" together - how to automate your lifePutting "Phings" together - how to automate your life
Putting "Phings" together - how to automate your lifeBoyan Borisov
 
Build website using Open Source Technology
Build website using Open Source TechnologyBuild website using Open Source Technology
Build website using Open Source TechnologyArunkumar Kupppuswamy
 
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Tim Plummer
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)Chandan Das
 
Tweaking your Template: Joomla Day Boston 2014 Barb Ackemann
Tweaking your Template: Joomla Day Boston 2014 Barb AckemannTweaking your Template: Joomla Day Boston 2014 Barb Ackemann
Tweaking your Template: Joomla Day Boston 2014 Barb AckemannBarb Ackemann
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
Make JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanMake JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanBlue Raster
 
Three Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. GoThree Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. GoChristian Horsdal
 

Was ist angesagt? (18)

Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Flying with Griffon @ CONFESS
Flying with Griffon @ CONFESSFlying with Griffon @ CONFESS
Flying with Griffon @ CONFESS
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
<?php + WordPress
<?php + WordPress<?php + WordPress
<?php + WordPress
 
HTTP cache: keeping it fresh
HTTP cache: keeping it freshHTTP cache: keeping it fresh
HTTP cache: keeping it fresh
 
Week6 office-hours
Week6 office-hoursWeek6 office-hours
Week6 office-hours
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
 
Introducing MongoPress
Introducing MongoPressIntroducing MongoPress
Introducing MongoPress
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Front End Development Automation with Grunt
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with Grunt
 
Putting "Phings" together - how to automate your life
Putting "Phings" together - how to automate your lifePutting "Phings" together - how to automate your life
Putting "Phings" together - how to automate your life
 
Build website using Open Source Technology
Build website using Open Source TechnologyBuild website using Open Source Technology
Build website using Open Source Technology
 
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)
 
Tweaking your Template: Joomla Day Boston 2014 Barb Ackemann
Tweaking your Template: Joomla Day Boston 2014 Barb AckemannTweaking your Template: Joomla Day Boston 2014 Barb Ackemann
Tweaking your Template: Joomla Day Boston 2014 Barb Ackemann
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Make JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanMake JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and Clean
 
Three Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. GoThree Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. Go
 

Ähnlich wie Gajendra sharma Drupal Module development

Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2Confiz
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module developmentDamjan Cvetan
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security rightGábor Hojtsy
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkBryan Ollendyke
 
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)Mark Hamstra
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Doing Drupal security right from Drupalcon London
Doing Drupal security right from Drupalcon LondonDoing Drupal security right from Drupalcon London
Doing Drupal security right from Drupalcon LondonGábor Hojtsy
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Mark Hamstra
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren Roth
 
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)Laura Scott
 
Drupal security
Drupal securityDrupal security
Drupal securityJozef Toth
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module developmentRachit Gupta
 
Rapid site production with Drupal
Rapid site production with DrupalRapid site production with Drupal
Rapid site production with DrupalRob Sawyer
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsLuís Carneiro
 
Drupal Training Topics
Drupal Training TopicsDrupal Training Topics
Drupal Training Topicsvibrantuser
 
Drush and drupal. администрирование волчек михаил
Drush and drupal. администрирование  волчек михаилDrush and drupal. администрирование  волчек михаил
Drush and drupal. администрирование волчек михаилdrupalconf
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 moduletedbow
 
Introduction to Drupal Content Management System
Introduction to Drupal Content Management SystemIntroduction to Drupal Content Management System
Introduction to Drupal Content Management SystemMario Hernandez
 

Ähnlich wie Gajendra sharma Drupal Module development (20)

Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security right
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talk
 
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Doing Drupal security right from Drupalcon London
Doing Drupal security right from Drupalcon LondonDoing Drupal security right from Drupalcon London
Doing Drupal security right from Drupalcon London
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
 
Drupal security
Drupal securityDrupal security
Drupal security
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Rapid site production with Drupal
Rapid site production with DrupalRapid site production with Drupal
Rapid site production with Drupal
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
 
Drupal Training Topics
Drupal Training TopicsDrupal Training Topics
Drupal Training Topics
 
Drush and drupal. администрирование волчек михаил
Drush and drupal. администрирование  волчек михаилDrush and drupal. администрирование  волчек михаил
Drush and drupal. администрирование волчек михаил
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 module
 
Drupal Skils Lab 302Labs
Drupal Skils Lab 302Labs Drupal Skils Lab 302Labs
Drupal Skils Lab 302Labs
 
72d5drupal
72d5drupal72d5drupal
72d5drupal
 
Introduction to Drupal Content Management System
Introduction to Drupal Content Management SystemIntroduction to Drupal Content Management System
Introduction to Drupal Content Management System
 

Kürzlich hochgeladen

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Kürzlich hochgeladen (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Gajendra sharma Drupal Module development

  • 1. My first Drupal module! Why not?
  • 2. About @ Gajendra Sharma • Started as PHP developer with custom CMS •“You need Linux” they said •I know Drupal since version 5.x Email: gajen.ksharma@gmail Skype: gajendrakumarsharma1688 LinkedIn: www.linkedin.com/in/gajendrasharma
  • 3. Drupal •  Available from drupal.org. •  Runs on every machine with PHP, supported database and web server. •  Very customizable (themes, modules). •  Good documented. •  No limits.
  • 4. A whole bunch of modules
  • 7. Three kinds of modules (3 Cs) •  Core –  Shipped with Drupal –  Approved by core developers and community •  Contributed –  Written by community –  Shared under the same GNU Public License •  Custom –  Created by website developer
  • 8. Where to? Drupal Core Modules Core Themes Contributed Modules Contributed Themes Custom Module Custom Theme /sites/[all|mysite.com]/custom
  • 9. Module name •  Should be a UNIQUE “short name” •  Used in all file and function names •  Must start with a letter •  Only lower-case letters and underscores •  We will use name: “dc_stat” –  For display current node/user stats
  • 10. Create a folder + module file •  Module name “dc_stats”. •  Create empty folder: –  /sites/*/modules/custom/dc_stats/ •  Create new file “dc_stats.module” with opening PHP tag and NO closing tag!! •  Create new file “dc_stats.info” for meta information.
  • 11. *.info •  Required for every module! •  Standard .ini file format – key/value pairs name = Drupal statistic! description = Provides some statistic data.! core = 7.x! package = Damjan Cvetan! Other optional keys: stylesheets, scripts, files, dependencies, …
  • 12. Checkpoint •  Navigate to Modules section on your site •  You should see your module •  Enable it!
  • 13. Coding standards •  Use an indent of 2 spaces, no tabs! •  •  •  •  UNIX line ending (n) Omit closing “?>” PHP tag Constants should be all-uppercase Comments are your friends!
  • 14. Half way there Hook(s) hook – [hoo k], noun Ÿ a curved or angular piece of metal or other hard substance for catching, pulling, holding, or suspending something. •  Fundamental to Drupal
  • 15. How does it work? Call dispatch Foreach (enabled_module):! module_name_menu();! end foreach;! Call for hook: hook_menu() Drupal runFme locale_menu()! user_menu()! contact_menu()! help_menu()! …! …! dc_stats_menu()! …! …! trigger_menu()! path_menu()! Drupal runFme
  • 16. Hooks line up! •  hook_help() – Provides available documentation. •  hook_menu() – For paths registration in order to define how URL request are handled. •  hook_init() – Run at the beginning of page request. •  hook_cron() – Called whenever a cron run happens. •  More at http://api.drupal.org/
  • 17. API.drupal.org •  Drupal developer’s documentation. •  Doc for Drupal 4.6+. •  Describes function calls, their parameters and return values. •  You can see the code and “who” is calling this code within Drupal. •  http://api.drupal.org
  • 18. Let’s code •  Define callback function dc_stats_page() as follows: funcFon dc_stats_page(){ return "Hello world! You’re awesome!”; } •  This will return defined string on call. •  Put this code in dc_stats.module file.
  • 19. Hey Drupal! Come in! •  Register path with hook_menu(). •  We will use basic return array structure. funcFon dc_stats_menu(){ $items['dc/stats-page'] = array( 'Ftle' => 'Stats info page', 'page callback' => 'dc_stats_page', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } Visit URL: /dc/stats-page to see if it works. (You might need to clear cache first.)
  • 20. Get some real data funcFon dc_stats_page(){ drupal_set_Ftle("Drupal staFsFcs"); $node_count = $db_node_count; $user_count = $db_users_count; $header = array("InformaFon", "Value"); $rows[] = array('Number of nodes:', $node_count); $rows[] = array('Number of users:', $user_count); return theme_table(array( 'header' => $header, 'rows' => $rows, … … )); // return }
  • 21. Happy ending •  Refresh your page and see your work. •  You can do much more – I’m certain! •  Use your PHP + any other knowledge with existing Drupal functions, hooks and variables!
  • 22. Links to consider •  http://api.drupal.org http://drupalcontrib.org/ •  http://buildamodule.com/ •  http://drupal.org/project/devel –  A suit of modules containing fun for module developers and themers.
  • 23. Books •  Drupal 7 Development by Example •  Beginning Drupal 7 •  Drupal 7 Module Development •  … •  …
  • 24. Q&A