SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
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	
  

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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