SlideShare une entreprise Scribd logo
1  sur  26
Think generic - add API's to your custom modules By Jens Beltofte Technical Manager and Senior Drupal Developer at Propeople
Facts about me Jens Beltofte Technical Manager at Propeople Working with Drupal since 2007 Founder of Drupal Danmark Member of the Drupal Danmark board DrupalCon CPH core team Camps, days and stammtisch in CPH
Facts about Propeople Danish full service web agency 70+ brains CPH, Sofia, Chisinau, Sweden, SF Drupal, Magento, SiteFinity, EPiServer, MOSS Acquia Enterprise Select & Microsoft Gold  Berlingske, Amnesty, UNICEF, FDM, Saxo Bank, Arla Foods, Mærsk, Egmont, SBS
This session Module architecture API’s what and why? How to create a hook / API Drupal core helper functions Custom API’s Real life examples Questions
Module architecture Steps in module architecture in Propeople Think & research Specify Code Review by team lead QA
Module architecture Think & research Let the ideas flow around in your brain Think on every aspect of the module Discuss with colleagues if needed Research Prototyping
Module architecture Specify Business purpose Every aspect of the module Administration interface Frontend API’s Code examples
Module architecture Code Code the module Test your code manually or with simpletest Review with coder & coder_tough_love Commit to version control
Module architecture Review by team lead Review with coder & coder_tough_love Manually review Testing
Module architecture Quality assurance Test module compared to specification Test the user experience Report bugs / record videos
API’s what and why? Application programming interface Allow systems to interact Flexibility Custimization Integration Plugins Drupal API’s vs. hooks.
How to create a hook / API A hook: Can be defined in D7 – not required. Don’t exists as a function in Drupal before a module implements it. Is a skeleton for a function that other modules can implement. Provide an example file or module. Know hooks: hook_menu, hook_perm etc.
How to create a hook / API Example hook D6 style: function hook_foo($op = 'info', $delta = NULL, &$a3 = NULL) {   switch ($op) {     case 'info':       $info[0] = array('info' => t('Some info about delta 1'));       $info[1] = array('info' => t('Some info about delta 2'));       return $info;     case 'configuration':         $form['example_field'] = array(           '#type' => 'textfield',           '#title' => t('Example field'),         ); 		return $form;     case 'view':       // Returning the frontend part.       break;   } }
How to create a hook / API Example hook D7 style: function hook_foo_info($delta = NULL, &$a3 = NULL) { 	$info[0] = array('info' => t('Some info about delta 1')); 	$info[1] = array('info' => t('Some info about delta 2')); 	return $info; } function hook_foo_configuration($delta = NULL, &$a3 = NULL) { 	$form['example_field'] = array( 	   '#type' => 'textfield',       '#title' => t('Example field'), 	); 	return $form; } Drupal core hooks no longer use the $op variable, but instead a function for each $op.
Drupal core helper functions Functions that help you implement API’s hook_hook_info() hook_hook_info_alter() module_hook() module_implements() module_invoke() module_invoke_all() drupal_alter()
hook_hook_info() Define hooks exposed by a module in D7 function example_hook_info() {  	$hooks[’foo_info'] = array(  		'group' => ’hooks',  	);  	$hooks[’foo_view'] = array( 		'group' => ’hooks',  	);  	return $hooks;  } Autoloading of example.hooks.inc if it exists.
hook_hook_info_alter() Alter a hook defined with hook_hook_info(). function example_hook_info_alter(&$hooks) {   // Makes it possible to overwrite existing hooks.   $hooks[’foo_info']['group'] = 'hooks_new';   $hooks[’foo_view']['group'] = 'hooks_new'; } It will now try to load example.hooks_new.inc instead of example.hooks.inc.  This means that we can overwrite the hook if it’s code is placed outsite example.module.
module_hook() Check if a module implements a given hook. $check = module_hook('example', ’foo'); If example implements the hook example_foo is $check TRUE else FALSE.
module_implements() Find all modules implementing the hook. $r = module_implements(’foo'); The function returns an array with all modules implementing the hook foo.
module_invoke() Invokes a hook in a specific module. $r = module_invoke('example', ’foo', ’info’, $args); The function returns the return value from example_foo().  If you need $args passed as reference is module_invoke not the solution. Instead use: $function = 'example_foo'; if (module_hook('example,’foo')) { call_user_func_array($function, $args); }
module_invoke_all() Invokes a hook in all modules implementing it. $r = module_invoke_all('foo', ’info’, $args); The function returns an array of all the return values. If you need $args passed as reference is module_invoke not the solution. Instead use: $hook = 'foo'; foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; call_user_func_array($function, $args); }
drupal_alter() Invokes hook_TYPE_alter() in modules implementing it. drupal_alter('example', $args); It will invoke module module_example_alter() in all modules. $args is passed as reference to module_example_alter(). drupal_alter() is used in the core for hooks like hook_form_alter(), hook_menu_alter(), hook_link_alter() etc.
Custom API’s Newsletter subscription module Flexible module for handling subscription and unsubscription to multiple lists and with custom fields. Used on UNICEF.dk, Amnesty.dk etc. DIBS API (Danish payment gateway) Flexible module for handling payments via DIBS. Support settings per module delta. Used on FDM.dk, UNICEF.dk, DDC.dk etc. 	Available at http://drupal.org/project/dibs
Questions? ?
Want to learn more? Drupal Thursdays For you that want to learn advanced Drupal from the developers and themers in Propeople. Location: Sofia, Pirin 40A street. Date: Every Thursday from ~19.30. More info http://groups.drupal.org/bulgaria
Need a new job? We’re hiring  Team Lead / Senior PHP developer PHP / Drupal developers Senior HTML developer Interested? Talk with Welin or Rumen.

Contenu connexe

Tendances

Gary Gao: APIs Are Good
Gary Gao: APIs Are GoodGary Gao: APIs Are Good
Gary Gao: APIs Are Good
talnoznisky
 
Power Theming
Power ThemingPower Theming
Power Theming
drkdn
 

Tendances (20)

Gary Gao: APIs Are Good
Gary Gao: APIs Are GoodGary Gao: APIs Are Good
Gary Gao: APIs Are Good
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Ant
Ant Ant
Ant
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Power Theming
Power ThemingPower Theming
Power Theming
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learnedMoving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
 
Ampersandjs
AmpersandjsAmpersandjs
Ampersandjs
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019
 
Crafting [Better] API Clients
Crafting [Better] API ClientsCrafting [Better] API Clients
Crafting [Better] API Clients
 
Framework
FrameworkFramework
Framework
 
I Love codeigniter, You?
I Love codeigniter, You?I Love codeigniter, You?
I Love codeigniter, You?
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
 
Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your View
 

En vedette

artikel_praktik_sep15_opslag
artikel_praktik_sep15_opslagartikel_praktik_sep15_opslag
artikel_praktik_sep15_opslag
Darikha Kulbaeva
 
Independent research task
Independent research taskIndependent research task
Independent research task
Naamah Hill
 
CV - Linda Anne Jeremiah.doc 2
CV - Linda Anne Jeremiah.doc 2CV - Linda Anne Jeremiah.doc 2
CV - Linda Anne Jeremiah.doc 2
Linda Jeremiah
 
Resume of Selvapathy - Senior Rig Mechanic
Resume of Selvapathy - Senior Rig MechanicResume of Selvapathy - Senior Rig Mechanic
Resume of Selvapathy - Senior Rig Mechanic
palanivel selvapathy
 

En vedette (14)

NURSING-CVSAMPLE ENGLISH
NURSING-CVSAMPLE ENGLISHNURSING-CVSAMPLE ENGLISH
NURSING-CVSAMPLE ENGLISH
 
Entendendo o edital parte 1 - edital 1
Entendendo o edital   parte 1 - edital 1Entendendo o edital   parte 1 - edital 1
Entendendo o edital parte 1 - edital 1
 
Entendendo o edital parte 1 - edital 3
Entendendo o edital   parte 1 - edital 3Entendendo o edital   parte 1 - edital 3
Entendendo o edital parte 1 - edital 3
 
Articulo
ArticuloArticulo
Articulo
 
Diagrama de de errores de redacción
Diagrama de de errores de redacciónDiagrama de de errores de redacción
Diagrama de de errores de redacción
 
CVwithHEADER
CVwithHEADERCVwithHEADER
CVwithHEADER
 
SINY Leanstartup Introduction | Reduce waste, run experiments!
SINY Leanstartup Introduction | Reduce waste, run experiments!SINY Leanstartup Introduction | Reduce waste, run experiments!
SINY Leanstartup Introduction | Reduce waste, run experiments!
 
Entendendo o edital parte 2 - edital 1
Entendendo o edital   parte 2 - edital 1Entendendo o edital   parte 2 - edital 1
Entendendo o edital parte 2 - edital 1
 
Sw Marketing & Sustainability Conference 6 11 12 Fv
Sw Marketing & Sustainability Conference 6 11 12 FvSw Marketing & Sustainability Conference 6 11 12 Fv
Sw Marketing & Sustainability Conference 6 11 12 Fv
 
artikel_praktik_sep15_opslag
artikel_praktik_sep15_opslagartikel_praktik_sep15_opslag
artikel_praktik_sep15_opslag
 
Independent research task
Independent research taskIndependent research task
Independent research task
 
04
0404
04
 
CV - Linda Anne Jeremiah.doc 2
CV - Linda Anne Jeremiah.doc 2CV - Linda Anne Jeremiah.doc 2
CV - Linda Anne Jeremiah.doc 2
 
Resume of Selvapathy - Senior Rig Mechanic
Resume of Selvapathy - Senior Rig MechanicResume of Selvapathy - Senior Rig Mechanic
Resume of Selvapathy - Senior Rig Mechanic
 

Similaire à Think Generic - Add API's To Your Custom Modules

Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
DrupalCampDN
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
Andrew Curioso
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in php
Wade Womersley
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
CodeIgniter Conference
 

Similaire à Think Generic - Add API's To Your Custom Modules (20)

Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right Reasons
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
Writing webapps with Perl Dancer
Writing webapps with Perl DancerWriting webapps with Perl Dancer
Writing webapps with Perl Dancer
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in php
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Convert modules from 6.x to 7.x
Convert modules from 6.x to 7.xConvert modules from 6.x to 7.x
Convert modules from 6.x to 7.x
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in SugarSugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
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
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Think Generic - Add API's To Your Custom Modules

  • 1. Think generic - add API's to your custom modules By Jens Beltofte Technical Manager and Senior Drupal Developer at Propeople
  • 2. Facts about me Jens Beltofte Technical Manager at Propeople Working with Drupal since 2007 Founder of Drupal Danmark Member of the Drupal Danmark board DrupalCon CPH core team Camps, days and stammtisch in CPH
  • 3. Facts about Propeople Danish full service web agency 70+ brains CPH, Sofia, Chisinau, Sweden, SF Drupal, Magento, SiteFinity, EPiServer, MOSS Acquia Enterprise Select & Microsoft Gold Berlingske, Amnesty, UNICEF, FDM, Saxo Bank, Arla Foods, Mærsk, Egmont, SBS
  • 4. This session Module architecture API’s what and why? How to create a hook / API Drupal core helper functions Custom API’s Real life examples Questions
  • 5. Module architecture Steps in module architecture in Propeople Think & research Specify Code Review by team lead QA
  • 6. Module architecture Think & research Let the ideas flow around in your brain Think on every aspect of the module Discuss with colleagues if needed Research Prototyping
  • 7. Module architecture Specify Business purpose Every aspect of the module Administration interface Frontend API’s Code examples
  • 8. Module architecture Code Code the module Test your code manually or with simpletest Review with coder & coder_tough_love Commit to version control
  • 9. Module architecture Review by team lead Review with coder & coder_tough_love Manually review Testing
  • 10. Module architecture Quality assurance Test module compared to specification Test the user experience Report bugs / record videos
  • 11. API’s what and why? Application programming interface Allow systems to interact Flexibility Custimization Integration Plugins Drupal API’s vs. hooks.
  • 12. How to create a hook / API A hook: Can be defined in D7 – not required. Don’t exists as a function in Drupal before a module implements it. Is a skeleton for a function that other modules can implement. Provide an example file or module. Know hooks: hook_menu, hook_perm etc.
  • 13. How to create a hook / API Example hook D6 style: function hook_foo($op = 'info', $delta = NULL, &$a3 = NULL) { switch ($op) { case 'info': $info[0] = array('info' => t('Some info about delta 1')); $info[1] = array('info' => t('Some info about delta 2')); return $info; case 'configuration': $form['example_field'] = array( '#type' => 'textfield', '#title' => t('Example field'), ); return $form; case 'view': // Returning the frontend part. break; } }
  • 14. How to create a hook / API Example hook D7 style: function hook_foo_info($delta = NULL, &$a3 = NULL) { $info[0] = array('info' => t('Some info about delta 1')); $info[1] = array('info' => t('Some info about delta 2')); return $info; } function hook_foo_configuration($delta = NULL, &$a3 = NULL) { $form['example_field'] = array( '#type' => 'textfield', '#title' => t('Example field'), ); return $form; } Drupal core hooks no longer use the $op variable, but instead a function for each $op.
  • 15. Drupal core helper functions Functions that help you implement API’s hook_hook_info() hook_hook_info_alter() module_hook() module_implements() module_invoke() module_invoke_all() drupal_alter()
  • 16. hook_hook_info() Define hooks exposed by a module in D7 function example_hook_info() { $hooks[’foo_info'] = array( 'group' => ’hooks', ); $hooks[’foo_view'] = array( 'group' => ’hooks', ); return $hooks; } Autoloading of example.hooks.inc if it exists.
  • 17. hook_hook_info_alter() Alter a hook defined with hook_hook_info(). function example_hook_info_alter(&$hooks) { // Makes it possible to overwrite existing hooks. $hooks[’foo_info']['group'] = 'hooks_new'; $hooks[’foo_view']['group'] = 'hooks_new'; } It will now try to load example.hooks_new.inc instead of example.hooks.inc. This means that we can overwrite the hook if it’s code is placed outsite example.module.
  • 18. module_hook() Check if a module implements a given hook. $check = module_hook('example', ’foo'); If example implements the hook example_foo is $check TRUE else FALSE.
  • 19. module_implements() Find all modules implementing the hook. $r = module_implements(’foo'); The function returns an array with all modules implementing the hook foo.
  • 20. module_invoke() Invokes a hook in a specific module. $r = module_invoke('example', ’foo', ’info’, $args); The function returns the return value from example_foo(). If you need $args passed as reference is module_invoke not the solution. Instead use: $function = 'example_foo'; if (module_hook('example,’foo')) { call_user_func_array($function, $args); }
  • 21. module_invoke_all() Invokes a hook in all modules implementing it. $r = module_invoke_all('foo', ’info’, $args); The function returns an array of all the return values. If you need $args passed as reference is module_invoke not the solution. Instead use: $hook = 'foo'; foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; call_user_func_array($function, $args); }
  • 22. drupal_alter() Invokes hook_TYPE_alter() in modules implementing it. drupal_alter('example', $args); It will invoke module module_example_alter() in all modules. $args is passed as reference to module_example_alter(). drupal_alter() is used in the core for hooks like hook_form_alter(), hook_menu_alter(), hook_link_alter() etc.
  • 23. Custom API’s Newsletter subscription module Flexible module for handling subscription and unsubscription to multiple lists and with custom fields. Used on UNICEF.dk, Amnesty.dk etc. DIBS API (Danish payment gateway) Flexible module for handling payments via DIBS. Support settings per module delta. Used on FDM.dk, UNICEF.dk, DDC.dk etc. Available at http://drupal.org/project/dibs
  • 25. Want to learn more? Drupal Thursdays For you that want to learn advanced Drupal from the developers and themers in Propeople. Location: Sofia, Pirin 40A street. Date: Every Thursday from ~19.30. More info http://groups.drupal.org/bulgaria
  • 26. Need a new job? We’re hiring  Team Lead / Senior PHP developer PHP / Drupal developers Senior HTML developer Interested? Talk with Welin or Rumen.