SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
My	
  first	
  Drupal	
  module!	
  
         Why	
  not?	
  
About @Cvetko
                       •  Started as PHP developer with
                          custom CMS
                       •  “You need Linux” they said
                       •  I know Drupal since version 4.x
Twitter
@Cvetko
                       •  Working as Sys admin, Drupal
Skype                     developer, iOS developer, etc.
damjan.cvetan

Email
damjan@agiledrop.com
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	
  
                                        Contributed	
  Themes	
  
          Modules	
  

      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 modules.
•    A way to interact with the core code.
•    Occur at various points in execution thread.
•    An event listener.
•    Names as foo_bar()
     –  foo : module name, bar : hook name
How does it work?
Foreach (enabled_module):!
  module_name_menu();!
                                                              locale_menu()!
end foreach;!                                                 user_menu()!
                                                              contact_menu()!
                                                              help_menu()!



                                       Call	
  dispatch	
  
                                                              …!
                                                              …!
                                                              dc_stats_menu()!
                                                              …!
                                                              …!
                                                              trigger_menu()!
            Call	
  for	
  hook:	
                            path_menu()!
            hook_menu()	
  


    Drupal	
  runFme	
                                                           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?

Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Balázs Tatár
 
[PyConTW 2013] Write Sublime Text 2 Packages with Python
[PyConTW 2013] Write Sublime Text 2 Packages with Python[PyConTW 2013] Write Sublime Text 2 Packages with Python
[PyConTW 2013] Write Sublime Text 2 Packages with PythonJenny Liang
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
Drupal 8 Sample Module
Drupal 8 Sample ModuleDrupal 8 Sample Module
Drupal 8 Sample Moduledrubb
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Balázs Tatár
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes ramakesavan
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway ichikaway
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS DrupalMumbai
 
Drupal 8 版型開發變革
Drupal 8 版型開發變革Drupal 8 版型開發變革
Drupal 8 版型開發變革Chris Wu
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
I use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalI use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalChris Wu
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Formsdrubb
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 

Was ist angesagt? (20)

Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Drupal 8 Hooks
 
[PyConTW 2013] Write Sublime Text 2 Packages with Python
[PyConTW 2013] Write Sublime Text 2 Packages with Python[PyConTW 2013] Write Sublime Text 2 Packages with Python
[PyConTW 2013] Write Sublime Text 2 Packages with Python
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
Drupal 8 Sample Module
Drupal 8 Sample ModuleDrupal 8 Sample Module
Drupal 8 Sample Module
 
backend
backendbackend
backend
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
Drupal 8 版型開發變革
Drupal 8 版型開發變革Drupal 8 版型開發變革
Drupal 8 版型開發變革
 
Wc no
Wc noWc no
Wc no
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
I use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalI use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 Drupal
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
Tricky Migrations
Tricky MigrationsTricky Migrations
Tricky Migrations
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 

Andere mochten auch

Aegir Cpanel for Drupal Sites
Aegir Cpanel for Drupal SitesAegir Cpanel for Drupal Sites
Aegir Cpanel for Drupal SitesDamjan Cvetan
 
Essential things that should always be in your car
Essential things that should always be in your carEssential things that should always be in your car
Essential things that should always be in your carEason Chan
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x TechnologyWebVisions
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad ReviewsGlassdoor
 
Catálogo Lexus NX
Catálogo Lexus NXCatálogo Lexus NX
Catálogo Lexus NXrfarias_10
 
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiver
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiverMarie Brandhøj Wiuff fra KORA - borger og lægeperspektiver
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiverkoradk
 
Γ9. Η εκστρατεία του Δράμαλη - Δερβενάκια
Γ9. Η εκστρατεία του Δράμαλη  - ΔερβενάκιαΓ9. Η εκστρατεία του Δράμαλη  - Δερβενάκια
Γ9. Η εκστρατεία του Δράμαλη - ΔερβενάκιαGeorge Giotis
 
High leverage brewster post
High leverage brewster postHigh leverage brewster post
High leverage brewster postEdAdvance
 
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิต
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิตบทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิต
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิตTa Lattapol
 
Eden Brown Built Environment EVP Document
Eden Brown Built Environment EVP DocumentEden Brown Built Environment EVP Document
Eden Brown Built Environment EVP DocumentAndy Husselbee
 
Horarios talleres de acompañamientos actualizados 25 enero 2016
Horarios talleres de acompañamientos actualizados 25 enero 2016Horarios talleres de acompañamientos actualizados 25 enero 2016
Horarios talleres de acompañamientos actualizados 25 enero 2016unidaddetitulacion
 
The Ultimate Guide To ACA Compliance
The Ultimate Guide To ACA ComplianceThe Ultimate Guide To ACA Compliance
The Ultimate Guide To ACA ComplianceBambooHR
 

Andere mochten auch (16)

Aegir Cpanel for Drupal Sites
Aegir Cpanel for Drupal SitesAegir Cpanel for Drupal Sites
Aegir Cpanel for Drupal Sites
 
Essential things that should always be in your car
Essential things that should always be in your carEssential things that should always be in your car
Essential things that should always be in your car
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x Technology
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad Reviews
 
Catálogo Lexus NX
Catálogo Lexus NXCatálogo Lexus NX
Catálogo Lexus NX
 
Hakkımızda
HakkımızdaHakkımızda
Hakkımızda
 
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiver
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiverMarie Brandhøj Wiuff fra KORA - borger og lægeperspektiver
Marie Brandhøj Wiuff fra KORA - borger og lægeperspektiver
 
Γ9. Η εκστρατεία του Δράμαλη - Δερβενάκια
Γ9. Η εκστρατεία του Δράμαλη  - ΔερβενάκιαΓ9. Η εκστρατεία του Δράμαλη  - Δερβενάκια
Γ9. Η εκστρατεία του Δράμαλη - Δερβενάκια
 
High leverage brewster post
High leverage brewster postHigh leverage brewster post
High leverage brewster post
 
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิต
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิตบทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิต
บทที่ 2 การเคลื่อนที่ของสิ่งมีชีวิต
 
Mughal e-azam
Mughal e-azamMughal e-azam
Mughal e-azam
 
Eden Brown Built Environment EVP Document
Eden Brown Built Environment EVP DocumentEden Brown Built Environment EVP Document
Eden Brown Built Environment EVP Document
 
DEB CV 2015
DEB CV 2015DEB CV 2015
DEB CV 2015
 
Horarios talleres de acompañamientos actualizados 25 enero 2016
Horarios talleres de acompañamientos actualizados 25 enero 2016Horarios talleres de acompañamientos actualizados 25 enero 2016
Horarios talleres de acompañamientos actualizados 25 enero 2016
 
The Ultimate Guide To ACA Compliance
The Ultimate Guide To ACA ComplianceThe Ultimate Guide To ACA Compliance
The Ultimate Guide To ACA Compliance
 
Farkımız
FarkımızFarkımız
Farkımız
 

Ähnlich wie Drupal module development

Gajendra sharma Drupal Module development
Gajendra sharma Drupal Module developmentGajendra sharma Drupal Module development
Gajendra sharma Drupal Module developmentGajendra Sharma
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaGábor Hojtsy
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingRobert Carr
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Ryan Price
 
Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandAngela Byron
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Angela Byron
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Drupalcon Paris
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentationhtyson
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security rightGábor Hojtsy
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren Roth
 
Drupal security
Drupal securityDrupal security
Drupal securityJozef Toth
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Emma Jane Hogbin Westby
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
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
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Antonio Peric-Mazar
 
Migrating to Drupal 8
Migrating to Drupal 8Migrating to Drupal 8
Migrating to Drupal 8Alkuvoima
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 

Ähnlich wie Drupal module development (20)

Gajendra sharma Drupal Module development
Gajendra sharma Drupal Module developmentGajendra sharma Drupal Module development
Gajendra sharma Drupal Module development
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp Bratislava
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) Theming
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011
 
Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the island
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentation
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security right
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Drupal security
Drupal securityDrupal security
Drupal security
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
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)
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
 
Migrating to Drupal 8
Migrating to Drupal 8Migrating to Drupal 8
Migrating to Drupal 8
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 

Kürzlich hochgeladen

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Kürzlich hochgeladen (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Drupal module development

  • 1. My  first  Drupal  module!   Why  not?  
  • 2. About @Cvetko •  Started as PHP developer with custom CMS •  “You need Linux” they said •  I know Drupal since version 4.x Twitter @Cvetko •  Working as Sys admin, Drupal Skype developer, iOS developer, etc. damjan.cvetan Email damjan@agiledrop.com
  • 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   Contributed  Themes   Modules   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!
  • 15. 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 modules. •  A way to interact with the core code. •  Occur at various points in execution thread. •  An event listener. •  Names as foo_bar() –  foo : module name, bar : hook name
  • 16. How does it work? Foreach (enabled_module):! module_name_menu();! locale_menu()! end foreach;! user_menu()! contact_menu()! help_menu()! Call  dispatch   …! …! dc_stats_menu()! …! …! trigger_menu()! Call  for  hook:   path_menu()! hook_menu()   Drupal  runFme   Drupal  runFme  
  • 17. 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/
  • 18. 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
  • 19. 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.
  • 20. 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.)
  • 21. 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   }  
  • 22. 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!
  • 23. 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.
  • 24. Books •  Drupal 7 Development by Example •  Beginning Drupal 7 •  Drupal 7 Module Development •  … •  …
  • 25. Q  &  A