intro to drupal module developement
DESCRIPTION
Intro to custom Drupal 7 module development.TRANSCRIPT
![Page 1: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/1.jpg)
Drupal 7 Module DevelopmentA Brief Introduction
Matt Mendonca
![Page 2: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/2.jpg)
Background
• IT Specialist at the National Institute of Standards and Technology
• 2+ years professional experience with Drupal • Previously worked for VOX Global
(FleishmanHillard) and High Rock Studios
![Page 3: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/3.jpg)
Content
• What are modules • Why you should modularize your code • What makes up a module
• What is the hook system • How does that (magic) work
• Resources • Make a module
![Page 4: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/4.jpg)
Modules Are…
• Building blocks • Encapsulated functionality • Frameworks • API’s
![Page 5: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/5.jpg)
Why You Should Modularize Your Code
• Code encapsulation • Enable / disable code • Cleanly extend core and / or contributed modules
• Prevents hacking other's code • Preserves upgrade path • https://www.drupal.org/best-practices/do-not-hack-core
• Share your code • Allows your code to be extendable
![Page 6: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/6.jpg)
Modules And Themes
• Make things work using modules • Make things pretty using themes • Developing modules allows you to keep logic
out of your themes • Separation of concerns
![Page 7: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/7.jpg)
Module Dissected• Folder designated by the machine name of the
module (/sites/all/modules/dev/my_module)* • Info file designated by the machine name of the
module (my_module.info) • Module file designated by the machine name of
the module (my_module.module) * Drupal’s module scanning is recursive; you can add folders with in the module folder and it will find it. E.g. /sites/all/module/contrib | /sites/all/module/dev | etc.
![Page 8: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/8.jpg)
Info File
• The .info file describes your module • At the minimum describe name, description, package, and core
![Page 9: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/9.jpg)
Info File: Name
• Name is the user friendly name of your module • E.g.
name = “My Module”
![Page 10: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/10.jpg)
Info File: Description
• Description is the description of your module • E.g.
description = “This my module.”
![Page 11: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/11.jpg)
Info File: Package
• Package is the category of your module • Groups modules together on the module admin
page • E.g.
package = “User Interface”
![Page 12: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/12.jpg)
Info File: Core
• Core is the major version of Drupal core that your module is designed for
• E.g.
core = 7.x
![Page 13: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/13.jpg)
Info File: Version• Version describes which release your module is at • By convention, version of Core followed by version of the
module • Note: this is only to be filled out when your module is not on
Drupal.org • E.g.
version = 7.x-1.0
![Page 14: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/14.jpg)
Info File: Dependencies• Dependencies is an array listing all the modules that your
module requires • You do not need to list the dependencies of your
dependencies • E.g.
dependencies[] = views
dependencies[] = panels
![Page 15: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/15.jpg)
Info File: Configure
• Configure specifies the url of the module’s configuration page (if any)
• Adds a configure link on the module admin page
• E.g.
configure = admin/config/content/my-module
![Page 16: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/16.jpg)
Module File
• The module file is the file that Drupal always loads for enabled modules - always
• Should contain your bootstrap code / hooks • When possible, store code in .inc files
![Page 17: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/17.jpg)
(Captain) Hook
• The hooks system provides access points to Drupal's response cycle
• Used by Modules and Themes (preprocessing) • Like a roll call
![Page 18: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/18.jpg)
How Does The Hook System Work
• At certain points in Drupal's response cycle, Drupal (and module's with hooks) will run hook-able functions
• Lets explore: https://github.com/matt-mendonca/hooks-explained
![Page 19: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/19.jpg)
Modules That Don't Have Any Hooks
• There are modules that don't use any hooks • Use Case: loading a php library for use by other
modules
![Page 20: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/20.jpg)
Resources
• https://www.drupal.org/developing/modules • https://www.drupal.org/best-practices • https://api.drupal.org/api/drupal • https://drupal.stackexchange.com/ • https://stackoverflow.com/questions/tagged/drupal • https://www.google.com/
![Page 21: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/21.jpg)
Questions?
![Page 22: Intro to Drupal Module Developement](https://reader034.vdocuments.net/reader034/viewer/2022042714/554f3738b4c90572088b4cc2/html5/thumbnails/22.jpg)
Lets Make A Module !
https://github.com/matt-mendonca/example-d7-module