SlideShare a Scribd company logo
1 of 59
Download to read offline
Overview       Drupal’s components           Modules   APIs




             Drupal module development
                       Basics and examples


                           Domas Monkus
           domas@monkus.lt :: http://domas.monkus.lt



                      25th September 2010
                          Drupal camp Riga
Overview   Drupal’s components        Modules   APIs




                       Domas Monkus
Overview                 Drupal’s components   Modules   APIs



What is drupal?




   CMS
      Node system
           Taxonomy
           CCK & Views
Overview                 Drupal’s components              Modules       APIs



What is drupal?




   CMS                                         FRAMEWORK
      Node system                                 Module Architecture
           Taxonomy                                Theming
           CCK & Views                             APIs
Overview                Drupal’s components   Modules   APIs


Drupal development workflow
Where did my time go?
Overview       Drupal’s components     Modules   APIs




           Should You develop a custom module?
Overview               Drupal’s components        Modules               APIs


Considerations
Not-invented-here?




           Maintenance - you will need to maintain and update even if
           you do not release it.
Overview               Drupal’s components         Modules              APIs


Considerations
Not-invented-here?




           Maintenance - you will need to maintain and update even if
           you do not release it.
           Investment - making custom one-off modules is not overly
           cost-effective. Will you need it again? In the foreseeable
           future?
Overview               Drupal’s components          Modules                APIs


Considerations
Not-invented-here?




           Maintenance - you will need to maintain and update even if
           you do not release it.
           Investment - making custom one-off modules is not overly
           cost-effective. Will you need it again? In the foreseeable
           future?
           Lonely path - it takes time to flush out all the bugs. Only in
           this case you will almost always be the only one finding them.
Overview               Drupal’s components       Modules            APIs


Alternatives
To custom modules




           Contrib - over 4500 modules, are you sure your problem
           hasn’t been tackled?
Overview               Drupal’s components        Modules           APIs


Alternatives
To custom modules




           Contrib - over 4500 modules, are you sure your problem
           hasn’t been tackled?
           Extending similar modules - base your work on a tested
           codebase.
Overview               Drupal’s components          Modules             APIs


Alternatives
To custom modules




           Contrib - over 4500 modules, are you sure your problem
           hasn’t been tackled?
           Extending similar modules - base your work on a tested
           codebase.
           One-off solutions - if it’s a rare problem, sometimes hacks
           are not the worst idea.
Overview                Drupal’s components   Modules   APIs


Enough talk
Let’s get to the programming



      Things you need to know:
           Drupal’s architecture
           Drupal module structure
           Drupal core subsystems and APIs
           Coding conventions
Overview                Drupal’s components   Modules   APIs


Enough talk
Let’s get to the programming



      Things you need to know:
           Drupal’s architecture
           Drupal module structure
           Drupal core subsystems and APIs
           Coding conventions
      Things you REALLY need to know:
           PHP
           MySQL
           HTML, CSS
           javascript (probably)
Overview   Drupal’s components        Modules   APIs




                           Overview
Overview                  Drupal’s components   Modules   APIs



Drupal’s architecture




           procedural (and it works!)
           event driven
           hooks
Overview                Drupal’s components           Modules   APIs


Hooks
Drupal’s glue




           Observer pattern
           Drupal calls available hooks at certain points
           Modules implement hooks
           Hooks add additional processing of requests
Overview             Drupal’s components          Modules   APIs


Hooks
There’s how many?!




                             (D7 has 178 hooks)
Overview        Drupal’s components   Modules   APIs


Hooks
What they do.
Overview                  Drupal’s components   Modules   APIs


Drupal’s APIs
Output




           Theming
           Menu API
           Output filtering
           Image manipulation
           Blocks
           Translations
           Search
Overview               Drupal’s components   Modules   APIs


Drupal’s APIs
Input




           Forms API
           XMLRPC
Overview               Drupal’s components   Modules   APIs


Drupal’s APIs
Users




           User management
           Session handling
           Access control
Overview                  Drupal’s components   Modules   APIs


Drupal’s APIs
Storage




           Database abstraction layer
           File storage
           Caching
Overview               Drupal’s components   Modules   APIs


Drupal’s APIs
Infrastructure




           Batch API
           Email handling
           Updates
           Module system
Overview    Drupal’s components           Modules   APIs



Reference




                  http://api.drupal.org
Overview   Drupal’s components         Modules   APIs




                 How does this work?
Overview               Drupal’s components         Modules               APIs


Hooking things together
Delayed publishing




      Problem
      We need to publish nodes of unverified users not immediately, but
      after a certain wait period.
Overview               Drupal’s components         Modules               APIs


Hooking things together
Delayed publishing




      Problem
      We need to publish nodes of unverified users not immediately, but
      after a certain wait period.

      Hooks used
          hook_perms
          To define a permission ’Publish nodes immediately’.
           hook_nodeapi
           To forcefully unpublish new nodes.
           hook_cron
           To publish nodes whose wait period has already passed.
Overview                Drupal’s components        Modules             APIs


Hooking things together
Term-node synchronization


      Task
      Create a node for every term in the dictionary and vice-versa,
      constantly synchronizing the contents of a node’s body and the
      term’s description.
Overview                Drupal’s components         Modules            APIs


Hooking things together
Term-node synchronization


      Task
      Create a node for every term in the dictionary and vice-versa,
      constantly synchronizing the contents of a node’s body and the
      term’s description.

      Hooks used
          hook_form_alter
          To add options to taxonomy vocabulary edit form.
           hook_taxonomy
           To react to term creation, updates and deletes.
           hook_node_info
           To define a custom node type.
           hook_insert, hook_update, hook_delete
           To react to node creation, updates and deletes.
Overview   Drupal’s components      Modules   APIs




             So where do we put this?
Overview             Drupal’s components    Modules          APIs



The structure of a drupal module




           module_name/
             * module_name.info - module description
             module_name.install - installation/uninstallation
             * module_name.module - module code
Overview             Drupal’s components    Modules   APIs



The .info file




           name = Devel
           description = Various blocks, pages..
           package = Development
           dependencies[] = menu
           core = 6.x
Overview               Drupal’s components   Modules   APIs



The .module file




           A simple php file
           Hooks and internal functions
Overview                 Drupal’s components            Modules      APIs



The .module file

      <?php
      ...
      define(’DEVEL_ERROR_HANDLER_BACKTRACE’, 2);
      ...
      /**
       * Implementation of hook_menu().
       */
      function devel_menu() {
        $items = array();
        $items[’devel/cache/clear’] = array(
          ’title’ => ’Empty cache’,
          ’page callback’ => ’devel_cache_clear’,
          ’description’ => ’Clear the CSS cache.’,
          ’access arguments’ => array(’access devel information’),
          ’menu_name’ => ’devel’,
        );

           ...
Overview   Drupal’s components   Modules   APIs




           3 most common APIs/hooks
Overview                 Drupal’s components   Modules   APIs



Menu API




      Tasks
          routing
           menus
           breadcrumbs
Overview                    Drupal’s components            Modules     APIs


Menu API
An example




      function devel_menu() {
        $items = array();

           $items[’devel/queries’] = array(
             ’title’ => ’Database queries’,
             ’page callback’ => ’devel_queries’,
             ’access callback’ => ’devel_menu_access_store_queries’,
             ’access arguments’ => array(),
             ’menu_name’ => ’devel’,
           );

           ...

           return $items;
      }
Overview   Drupal’s components   Modules   APIs



Menu API
Overview                Drupal’s components   Modules   APIs



Form API




      Tasks
          Form creation and rendering
           Form altering
           Processing
           Form validation and security
Overview               Drupal’s components     Modules   APIs


Form API
What’s in a form?



           Forms are defined as nested arrays

           $form = array();
           $form[’mail’] = array(
              ’#type’ => ’textfield’,
              ’#title’ => t(’Email’),
              ’#size’ => 20,
              ’#maxlength’ => 128,
              ’#required’ => TRUE,
           );
           return drupal_get_form($form);
Overview               Drupal’s components           Modules          APIs


Form API
Altering forms




           Any Form API form can be altered by other modules
           Fields can be added, removed or changed
           Additional validation and submit processing can be added
Overview               Drupal’s components          Modules           APIs


Form API
hook_form_alter




      function hook_form_alter(&$form, $form_state, $form_id)



           $form
           The form array - passed by reference, can be altered
           $form_state
           The form’s state (if the form has already been rendered)
           $form_id
           The id of the form being processed
Overview                 Drupal’s components            Modules                APIs


Form API
An example




      function path_form_alter(&$form, $form_state, $form_id) {
        if (isset($form[’type’]) && isset($form[’#node’])
            && $form[’type’][’#value’] .’_node_form’ == $form_id) {
          $path = isset($form[’#node’]->path) ? $form[’#node’]->path : NULL;
          $form[’path’] = array(
            ’#type’ => ’fieldset’,
            ’#title’ => t(’URL path settings’),
            ’#collapsible’ => TRUE,
            ’#collapsed’ => empty($path),
            ’#access’ => user_access(’create url aliases’),
            ’#weight’ => 30,
          );
          ...
Overview                Drupal’s components          Modules   APIs



hook_node_api




      Tasks
          React to all operations on nodes
           Additional processing or validation of node fields
           Add additional content to nodes on load
Overview               Drupal’s components         Modules   APIs




      function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL)



           $node
           The node object
           $op
           The operation being performed
           $a3, $a4
           Additional parameters, dependant on operation
Overview              Drupal’s components   Modules   APIs


Node API
Operations




           load
           insert
           update
           delete
           validate
           presave
           etc.
Overview                    Drupal’s components         Modules             APIs


Node API
An example




      function nodeasblock_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
        switch ($op) {
          case ’load’:
            $node->nodeasblock = db_result(
                   db_query(’SELECT nid FROM {nodeasblock}
                             WHERE nid = %d’, $node->nid));
            break;

           case ’insert’:
           ...
Overview   Drupal’s components          Modules   APIs




                       Tips and tools
Overview                Drupal’s components           Modules           APIs



Tools


           devel module
           cache operations, dummy content generation, debugging aids
           coder module
           coding standards validation, basic module security tips
           drupal api module
           have a local instance of api.drupal.org
           simpletest module
           automated unit testing of your module (highly encouraged)
           version control
           cvs, svn, git, mercurial - anything is better than nothing
Overview                Drupal’s components          Modules            APIs



Tips

      Coding practices
          Coding standards
          keep your code clean and documented - if you ever decide to
          release it
           Caching
           because performance matters
           Splitting large module files
           parts can be loaded on demand - less load on the system

      Looking for help
          #drupal
          go to the irc.freenode.net irc channel for help
           api.drupal.org
           complete reference of drupal core APIs
Overview   Drupal’s components          Modules   APIs




                         .. and never
Overview   Drupal’s components          Modules   APIs




                         .. and never
                             ever
Overview   Drupal’s components          Modules   APIs




                         .. and never
                             ever
                             hack
Overview   Drupal’s components          Modules   APIs




                         .. and never
                             ever
                             hack
                             core
Overview           Drupal’s components   Modules   APIs



Don’t hack core!
Overview    Drupal’s components                  Modules   APIs




                            That’s it
           (we’ve barely scratched the surface though)
Overview   Drupal’s components   Modules   APIs
Overview   Drupal’s components         Modules   APIs




                          Questions?

More Related Content

What's hot

Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applicationsJulien Dubois
 
Java: Create The Future Keynote
Java: Create The Future KeynoteJava: Create The Future Keynote
Java: Create The Future KeynoteSimon Ritter
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...JAX London
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonJeremy Brown
 
Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9Simon Ritter
 
3 rad extensibility-srilakshmi_s_rajesh_k
3 rad extensibility-srilakshmi_s_rajesh_k3 rad extensibility-srilakshmi_s_rajesh_k
3 rad extensibility-srilakshmi_s_rajesh_kIBM
 
Free Ebooks Download edhole.com
Free Ebooks Download edhole.comFree Ebooks Download edhole.com
Free Ebooks Download edhole.comEdhole.com
 
The Modern Java Web Developer - Denver JUG 2013
The Modern Java Web Developer - Denver JUG 2013The Modern Java Web Developer - Denver JUG 2013
The Modern Java Web Developer - Denver JUG 2013Matt Raible
 
Java EE7 in action
Java EE7 in actionJava EE7 in action
Java EE7 in actionAnkara JUG
 
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentZen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentClaroline
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Edureka!
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template LanguageGabriel Walt
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module developmentJay Harris
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
 

What's hot (20)

Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applications
 
Java: Create The Future Keynote
Java: Create The Future KeynoteJava: Create The Future Keynote
Java: Create The Future Keynote
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's Skeleton
 
Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9
 
Fame
FameFame
Fame
 
Java Modularity: the Year After
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year After
 
3 rad extensibility-srilakshmi_s_rajesh_k
3 rad extensibility-srilakshmi_s_rajesh_k3 rad extensibility-srilakshmi_s_rajesh_k
3 rad extensibility-srilakshmi_s_rajesh_k
 
Free Ebooks Download edhole.com
Free Ebooks Download edhole.comFree Ebooks Download edhole.com
Free Ebooks Download edhole.com
 
The Modern Java Web Developer - Denver JUG 2013
The Modern Java Web Developer - Denver JUG 2013The Modern Java Web Developer - Denver JUG 2013
The Modern Java Web Developer - Denver JUG 2013
 
Java EE7 in action
Java EE7 in actionJava EE7 in action
Java EE7 in action
 
Spring aop
Spring aopSpring aop
Spring aop
 
Oracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, TambaramOracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, Tambaram
 
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentZen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Learning Rails
Learning RailsLearning Rails
Learning Rails
 
intellimeet
intellimeetintellimeet
intellimeet
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module development
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
 

Viewers also liked

Director Research - Hype Williams
Director Research - Hype WilliamsDirector Research - Hype Williams
Director Research - Hype Williamsguesta44db78
 
LA INFORMATICA
LA INFORMATICALA INFORMATICA
LA INFORMATICAerick
 
Past Tense Invitation Review Q Words
Past Tense Invitation Review Q WordsPast Tense Invitation Review Q Words
Past Tense Invitation Review Q Wordskarenthesecretary
 
Actividad modulo7
Actividad modulo7Actividad modulo7
Actividad modulo7erick
 
actividad del modulo 7
actividad del modulo 7actividad del modulo 7
actividad del modulo 7erick
 
Maddison Ward Talent Led Programmes Public
Maddison Ward Talent Led Programmes PublicMaddison Ward Talent Led Programmes Public
Maddison Ward Talent Led Programmes Publicstuart1403
 
Prediction markets
Prediction marketsPrediction markets
Prediction marketsDomas Monkus
 
Maddison Ward Leading Successful Programmes Public
Maddison Ward Leading Successful Programmes PublicMaddison Ward Leading Successful Programmes Public
Maddison Ward Leading Successful Programmes Publicstuart1403
 
Programme Assurance Questionnaire V1.4
Programme Assurance Questionnaire V1.4Programme Assurance Questionnaire V1.4
Programme Assurance Questionnaire V1.4stuart1403
 
Managing The Portfolio
Managing The PortfolioManaging The Portfolio
Managing The Portfoliostuart1403
 
Ejercicio 7 8
Ejercicio 7 8Ejercicio 7 8
Ejercicio 7 8erick
 
Drupal Programavimas: praktika ir patarimai
Drupal Programavimas: praktika ir patarimaiDrupal Programavimas: praktika ir patarimai
Drupal Programavimas: praktika ir patarimaiDomas Monkus
 
художественная культура нидерландов
художественная культура нидерландовхудожественная культура нидерландов
художественная культура нидерландовAnnGo
 
Target Operating Model Definition
Target Operating Model DefinitionTarget Operating Model Definition
Target Operating Model Definitionstuart1403
 

Viewers also liked (19)

Director Research - Hype Williams
Director Research - Hype WilliamsDirector Research - Hype Williams
Director Research - Hype Williams
 
Arkaic Research
Arkaic ResearchArkaic Research
Arkaic Research
 
LA INFORMATICA
LA INFORMATICALA INFORMATICA
LA INFORMATICA
 
Past Tense Invitation Review Q Words
Past Tense Invitation Review Q WordsPast Tense Invitation Review Q Words
Past Tense Invitation Review Q Words
 
Actividad modulo7
Actividad modulo7Actividad modulo7
Actividad modulo7
 
actividad del modulo 7
actividad del modulo 7actividad del modulo 7
actividad del modulo 7
 
Maddison Ward Talent Led Programmes Public
Maddison Ward Talent Led Programmes PublicMaddison Ward Talent Led Programmes Public
Maddison Ward Talent Led Programmes Public
 
Prediction markets
Prediction marketsPrediction markets
Prediction markets
 
Gs 3 4 Grammar Synthesis
Gs 3 4 Grammar SynthesisGs 3 4 Grammar Synthesis
Gs 3 4 Grammar Synthesis
 
Music
MusicMusic
Music
 
Maddison Ward Leading Successful Programmes Public
Maddison Ward Leading Successful Programmes PublicMaddison Ward Leading Successful Programmes Public
Maddison Ward Leading Successful Programmes Public
 
Programme Assurance Questionnaire V1.4
Programme Assurance Questionnaire V1.4Programme Assurance Questionnaire V1.4
Programme Assurance Questionnaire V1.4
 
Managing The Portfolio
Managing The PortfolioManaging The Portfolio
Managing The Portfolio
 
Ejercicio 7 8
Ejercicio 7 8Ejercicio 7 8
Ejercicio 7 8
 
Drupal Programavimas: praktika ir patarimai
Drupal Programavimas: praktika ir patarimaiDrupal Programavimas: praktika ir patarimai
Drupal Programavimas: praktika ir patarimai
 
художественная культура нидерландов
художественная культура нидерландовхудожественная культура нидерландов
художественная культура нидерландов
 
corevalue ppt
corevalue pptcorevalue ppt
corevalue ppt
 
Target Operating Model Definition
Target Operating Model DefinitionTarget Operating Model Definition
Target Operating Model Definition
 
Calendario Escolar 2017
Calendario Escolar 2017Calendario Escolar 2017
Calendario Escolar 2017
 

Similar to Domas monkus drupal module development

Building API's
Building API'sBuilding API's
Building API'sarcaneadam
 
PHPNW Drupal as a Framework
PHPNW Drupal as a FrameworkPHPNW Drupal as a Framework
PHPNW Drupal as a Frameworkdigital006
 
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 Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Introduction to Drupal, Wayne Eaker, Nov 11, 09
Introduction to Drupal, Wayne Eaker, Nov 11, 09 Introduction to Drupal, Wayne Eaker, Nov 11, 09
Introduction to Drupal, Wayne Eaker, Nov 11, 09 Lunch Ann Arbor Marketing
 
DrupalCon LA 2015 Review
DrupalCon LA 2015 ReviewDrupalCon LA 2015 Review
DrupalCon LA 2015 ReviewlittleMAS
 
Drupal Roadmap 2010
Drupal Roadmap 2010Drupal Roadmap 2010
Drupal Roadmap 2010kathyhh
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsLuís Carneiro
 
2007 Fsoss Drupal Under The Hood
2007 Fsoss Drupal Under The Hood2007 Fsoss Drupal Under The Hood
2007 Fsoss Drupal Under The HoodJames Walker
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRSumanth krishna
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module developmentRachit Gupta
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsRalph Schindler
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampDipen Chaudhary
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Angela Byron
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren Roth
 

Similar to Domas monkus drupal module development (20)

Building API's
Building API'sBuilding API's
Building API's
 
Drupal
DrupalDrupal
Drupal
 
PHPNW Drupal as a Framework
PHPNW Drupal as a FrameworkPHPNW Drupal as a Framework
PHPNW Drupal as a Framework
 
Overview Of Drupal
Overview Of DrupalOverview Of Drupal
Overview Of Drupal
 
Overview Of Drupal
Overview Of DrupalOverview Of Drupal
Overview Of Drupal
 
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 Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Introduction to Drupal, Wayne Eaker, Nov 11, 09
Introduction to Drupal, Wayne Eaker, Nov 11, 09 Introduction to Drupal, Wayne Eaker, Nov 11, 09
Introduction to Drupal, Wayne Eaker, Nov 11, 09
 
DrupalCon LA 2015 Review
DrupalCon LA 2015 ReviewDrupalCon LA 2015 Review
DrupalCon LA 2015 Review
 
Drupal Roadmap 2010
Drupal Roadmap 2010Drupal Roadmap 2010
Drupal Roadmap 2010
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
 
2007 Fsoss Drupal Under The Hood
2007 Fsoss Drupal Under The Hood2007 Fsoss Drupal Under The Hood
2007 Fsoss Drupal Under The Hood
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoR
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View Enhancements
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal Camp
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 

Recently uploaded

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
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
 
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
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
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
 
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
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Domas monkus drupal module development

  • 1. Overview Drupal’s components Modules APIs Drupal module development Basics and examples Domas Monkus domas@monkus.lt :: http://domas.monkus.lt 25th September 2010 Drupal camp Riga
  • 2. Overview Drupal’s components Modules APIs Domas Monkus
  • 3. Overview Drupal’s components Modules APIs What is drupal? CMS Node system Taxonomy CCK & Views
  • 4. Overview Drupal’s components Modules APIs What is drupal? CMS FRAMEWORK Node system Module Architecture Taxonomy Theming CCK & Views APIs
  • 5. Overview Drupal’s components Modules APIs Drupal development workflow Where did my time go?
  • 6. Overview Drupal’s components Modules APIs Should You develop a custom module?
  • 7. Overview Drupal’s components Modules APIs Considerations Not-invented-here? Maintenance - you will need to maintain and update even if you do not release it.
  • 8. Overview Drupal’s components Modules APIs Considerations Not-invented-here? Maintenance - you will need to maintain and update even if you do not release it. Investment - making custom one-off modules is not overly cost-effective. Will you need it again? In the foreseeable future?
  • 9. Overview Drupal’s components Modules APIs Considerations Not-invented-here? Maintenance - you will need to maintain and update even if you do not release it. Investment - making custom one-off modules is not overly cost-effective. Will you need it again? In the foreseeable future? Lonely path - it takes time to flush out all the bugs. Only in this case you will almost always be the only one finding them.
  • 10. Overview Drupal’s components Modules APIs Alternatives To custom modules Contrib - over 4500 modules, are you sure your problem hasn’t been tackled?
  • 11. Overview Drupal’s components Modules APIs Alternatives To custom modules Contrib - over 4500 modules, are you sure your problem hasn’t been tackled? Extending similar modules - base your work on a tested codebase.
  • 12. Overview Drupal’s components Modules APIs Alternatives To custom modules Contrib - over 4500 modules, are you sure your problem hasn’t been tackled? Extending similar modules - base your work on a tested codebase. One-off solutions - if it’s a rare problem, sometimes hacks are not the worst idea.
  • 13. Overview Drupal’s components Modules APIs Enough talk Let’s get to the programming Things you need to know: Drupal’s architecture Drupal module structure Drupal core subsystems and APIs Coding conventions
  • 14. Overview Drupal’s components Modules APIs Enough talk Let’s get to the programming Things you need to know: Drupal’s architecture Drupal module structure Drupal core subsystems and APIs Coding conventions Things you REALLY need to know: PHP MySQL HTML, CSS javascript (probably)
  • 15. Overview Drupal’s components Modules APIs Overview
  • 16. Overview Drupal’s components Modules APIs Drupal’s architecture procedural (and it works!) event driven hooks
  • 17. Overview Drupal’s components Modules APIs Hooks Drupal’s glue Observer pattern Drupal calls available hooks at certain points Modules implement hooks Hooks add additional processing of requests
  • 18. Overview Drupal’s components Modules APIs Hooks There’s how many?! (D7 has 178 hooks)
  • 19. Overview Drupal’s components Modules APIs Hooks What they do.
  • 20. Overview Drupal’s components Modules APIs Drupal’s APIs Output Theming Menu API Output filtering Image manipulation Blocks Translations Search
  • 21. Overview Drupal’s components Modules APIs Drupal’s APIs Input Forms API XMLRPC
  • 22. Overview Drupal’s components Modules APIs Drupal’s APIs Users User management Session handling Access control
  • 23. Overview Drupal’s components Modules APIs Drupal’s APIs Storage Database abstraction layer File storage Caching
  • 24. Overview Drupal’s components Modules APIs Drupal’s APIs Infrastructure Batch API Email handling Updates Module system
  • 25. Overview Drupal’s components Modules APIs Reference http://api.drupal.org
  • 26. Overview Drupal’s components Modules APIs How does this work?
  • 27. Overview Drupal’s components Modules APIs Hooking things together Delayed publishing Problem We need to publish nodes of unverified users not immediately, but after a certain wait period.
  • 28. Overview Drupal’s components Modules APIs Hooking things together Delayed publishing Problem We need to publish nodes of unverified users not immediately, but after a certain wait period. Hooks used hook_perms To define a permission ’Publish nodes immediately’. hook_nodeapi To forcefully unpublish new nodes. hook_cron To publish nodes whose wait period has already passed.
  • 29. Overview Drupal’s components Modules APIs Hooking things together Term-node synchronization Task Create a node for every term in the dictionary and vice-versa, constantly synchronizing the contents of a node’s body and the term’s description.
  • 30. Overview Drupal’s components Modules APIs Hooking things together Term-node synchronization Task Create a node for every term in the dictionary and vice-versa, constantly synchronizing the contents of a node’s body and the term’s description. Hooks used hook_form_alter To add options to taxonomy vocabulary edit form. hook_taxonomy To react to term creation, updates and deletes. hook_node_info To define a custom node type. hook_insert, hook_update, hook_delete To react to node creation, updates and deletes.
  • 31. Overview Drupal’s components Modules APIs So where do we put this?
  • 32. Overview Drupal’s components Modules APIs The structure of a drupal module module_name/ * module_name.info - module description module_name.install - installation/uninstallation * module_name.module - module code
  • 33. Overview Drupal’s components Modules APIs The .info file name = Devel description = Various blocks, pages.. package = Development dependencies[] = menu core = 6.x
  • 34. Overview Drupal’s components Modules APIs The .module file A simple php file Hooks and internal functions
  • 35. Overview Drupal’s components Modules APIs The .module file <?php ... define(’DEVEL_ERROR_HANDLER_BACKTRACE’, 2); ... /** * Implementation of hook_menu(). */ function devel_menu() { $items = array(); $items[’devel/cache/clear’] = array( ’title’ => ’Empty cache’, ’page callback’ => ’devel_cache_clear’, ’description’ => ’Clear the CSS cache.’, ’access arguments’ => array(’access devel information’), ’menu_name’ => ’devel’, ); ...
  • 36. Overview Drupal’s components Modules APIs 3 most common APIs/hooks
  • 37. Overview Drupal’s components Modules APIs Menu API Tasks routing menus breadcrumbs
  • 38. Overview Drupal’s components Modules APIs Menu API An example function devel_menu() { $items = array(); $items[’devel/queries’] = array( ’title’ => ’Database queries’, ’page callback’ => ’devel_queries’, ’access callback’ => ’devel_menu_access_store_queries’, ’access arguments’ => array(), ’menu_name’ => ’devel’, ); ... return $items; }
  • 39. Overview Drupal’s components Modules APIs Menu API
  • 40. Overview Drupal’s components Modules APIs Form API Tasks Form creation and rendering Form altering Processing Form validation and security
  • 41. Overview Drupal’s components Modules APIs Form API What’s in a form? Forms are defined as nested arrays $form = array(); $form[’mail’] = array( ’#type’ => ’textfield’, ’#title’ => t(’Email’), ’#size’ => 20, ’#maxlength’ => 128, ’#required’ => TRUE, ); return drupal_get_form($form);
  • 42. Overview Drupal’s components Modules APIs Form API Altering forms Any Form API form can be altered by other modules Fields can be added, removed or changed Additional validation and submit processing can be added
  • 43. Overview Drupal’s components Modules APIs Form API hook_form_alter function hook_form_alter(&$form, $form_state, $form_id) $form The form array - passed by reference, can be altered $form_state The form’s state (if the form has already been rendered) $form_id The id of the form being processed
  • 44. Overview Drupal’s components Modules APIs Form API An example function path_form_alter(&$form, $form_state, $form_id) { if (isset($form[’type’]) && isset($form[’#node’]) && $form[’type’][’#value’] .’_node_form’ == $form_id) { $path = isset($form[’#node’]->path) ? $form[’#node’]->path : NULL; $form[’path’] = array( ’#type’ => ’fieldset’, ’#title’ => t(’URL path settings’), ’#collapsible’ => TRUE, ’#collapsed’ => empty($path), ’#access’ => user_access(’create url aliases’), ’#weight’ => 30, ); ...
  • 45. Overview Drupal’s components Modules APIs hook_node_api Tasks React to all operations on nodes Additional processing or validation of node fields Add additional content to nodes on load
  • 46. Overview Drupal’s components Modules APIs function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) $node The node object $op The operation being performed $a3, $a4 Additional parameters, dependant on operation
  • 47. Overview Drupal’s components Modules APIs Node API Operations load insert update delete validate presave etc.
  • 48. Overview Drupal’s components Modules APIs Node API An example function nodeasblock_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case ’load’: $node->nodeasblock = db_result( db_query(’SELECT nid FROM {nodeasblock} WHERE nid = %d’, $node->nid)); break; case ’insert’: ...
  • 49. Overview Drupal’s components Modules APIs Tips and tools
  • 50. Overview Drupal’s components Modules APIs Tools devel module cache operations, dummy content generation, debugging aids coder module coding standards validation, basic module security tips drupal api module have a local instance of api.drupal.org simpletest module automated unit testing of your module (highly encouraged) version control cvs, svn, git, mercurial - anything is better than nothing
  • 51. Overview Drupal’s components Modules APIs Tips Coding practices Coding standards keep your code clean and documented - if you ever decide to release it Caching because performance matters Splitting large module files parts can be loaded on demand - less load on the system Looking for help #drupal go to the irc.freenode.net irc channel for help api.drupal.org complete reference of drupal core APIs
  • 52. Overview Drupal’s components Modules APIs .. and never
  • 53. Overview Drupal’s components Modules APIs .. and never ever
  • 54. Overview Drupal’s components Modules APIs .. and never ever hack
  • 55. Overview Drupal’s components Modules APIs .. and never ever hack core
  • 56. Overview Drupal’s components Modules APIs Don’t hack core!
  • 57. Overview Drupal’s components Modules APIs That’s it (we’ve barely scratched the surface though)
  • 58. Overview Drupal’s components Modules APIs
  • 59. Overview Drupal’s components Modules APIs Questions?