Gentle Intro to Drupal Code
-
date post
17-Oct-2014 -
Category
Technology
-
view
6.202 -
download
1
description
Transcript of Gentle Intro to Drupal Code
![Page 1: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/1.jpg)
A Gentle Introduction
Addison Berry, LullabotDrupalCon, Washington, DC 2009
![Page 2: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/2.jpg)
A lot of people get a bit overwhelmed by Drupal coding.Sometimes that leads to running away or hacking.
![Page 3: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/3.jpg)
Systems, Frameworks and APIs, Oh My!
API = set of functions that accomplish programming tasks - can be used “publicly”Framework = basic app skeleton that solves common needs in a standardized wayCMS = features that help people build sites and manage contentAdvantages: takes care of nasty, tedious stuff; auth., security, etc. and its Open Source :)
![Page 4: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/4.jpg)
Systems, Frameworks and APIs, Oh My!
Content Management Systembuilt on the
API = set of functions that accomplish programming tasks - can be used “publicly”Framework = basic app skeleton that solves common needs in a standardized wayCMS = features that help people build sites and manage contentAdvantages: takes care of nasty, tedious stuff; auth., security, etc. and its Open Source :)
![Page 5: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/5.jpg)
Systems, Frameworks and APIs, Oh My!
Content Management Systembuilt on the
Framework,which uses the
API = set of functions that accomplish programming tasks - can be used “publicly”Framework = basic app skeleton that solves common needs in a standardized wayCMS = features that help people build sites and manage contentAdvantages: takes care of nasty, tedious stuff; auth., security, etc. and its Open Source :)
![Page 6: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/6.jpg)
Systems, Frameworks and APIs, Oh My!
Content Management Systembuilt on the
Framework,which uses the
APIs(Application Programming Interface)
API = set of functions that accomplish programming tasks - can be used “publicly”Framework = basic app skeleton that solves common needs in a standardized wayCMS = features that help people build sites and manage contentAdvantages: takes care of nasty, tedious stuff; auth., security, etc. and its Open Source :)
![Page 7: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/7.jpg)
What is where?
CMS > framework > apisCore modules and themes use the framework like everyone else.Everyone should actually look at the files.Includes folder holds the magic.
![Page 8: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/8.jpg)
What is where?
CMS > framework > apisCore modules and themes use the framework like everyone else.Everyone should actually look at the files.Includes folder holds the magic.
![Page 9: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/9.jpg)
What is where?
base_path()format_date()l()t()url()
CMS > framework > apisCore modules and themes use the framework like everyone else.Everyone should actually look at the files.Includes folder holds the magic.
![Page 10: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/10.jpg)
Hooks
‣ Naming convention
‣ hook_* where hook is replaced by your module name
‣ Lets modules add their own stuff to Drupal’s workflow
![Page 11: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/11.jpg)
A hook example
Hey modules! I’m gonna display the
permissions page, you have anything you want me to add?
Naming convention for functions that lets modules jump in to the Drupal workflow
![Page 12: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/12.jpg)
hook_perm
Each module can respond by saying they have something.If they don’t have anything, they just don’t use the hook.
![Page 13: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/13.jpg)
I do!
blog_perm
blog
Each module can respond by saying they have something.If they don’t have anything, they just don’t use the hook.
![Page 14: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/14.jpg)
I do!
me too
block_perm
block
blog
Each module can respond by saying they have something.If they don’t have anything, they just don’t use the hook.
![Page 15: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/15.jpg)
I do!
me too
block
blog
blogapiI don’t
hook_perm
Each module can respond by saying they have something.If they don’t have anything, they just don’t use the hook.
![Page 16: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/16.jpg)
Voila!
This is the display that gets made from hook_perm
![Page 17: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/17.jpg)
The Train Analogy
• The Node Train leaves the station with node/12 hitchedIt goes to the hook_nodeapi stopAttaches the taxonomy and comment carsGets to the Theme depotGoes on to the Browser Terminal
![Page 18: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/18.jpg)
The Train Analogy
• The Node Train leaves the station with node/12 hitchedIt goes to the hook_nodeapi stopAttaches the taxonomy and comment carsGets to the Theme depotGoes on to the Browser Terminal
![Page 19: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/19.jpg)
The Train Analogy
• The Node Train leaves the station with node/12 hitchedIt goes to the hook_nodeapi stopAttaches the taxonomy and comment carsGets to the Theme depotGoes on to the Browser Terminal
![Page 20: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/20.jpg)
The Train Analogy
• The Node Train leaves the station with node/12 hitchedIt goes to the hook_nodeapi stopAttaches the taxonomy and comment carsGets to the Theme depotGoes on to the Browser Terminal
![Page 21: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/21.jpg)
Some major players
Menu
Form
Database
Theme
![Page 22: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/22.jpg)
output: HTML, RSSactions like: forwarding, login/logoutevery internal link on a Drupal site is controlled by the menu system
![Page 23: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/23.jpg)
Menu
๏menu.inc != menu.module
๏maps URLs to functions
๏functions can display output and initiate actions
output: HTML, RSSactions like: forwarding, login/logoutevery internal link on a Drupal site is controlled by the menu system
![Page 24: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/24.jpg)
give it an array and it will give you the formnot just for devs. themers can control form output
![Page 25: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/25.jpg)
give it an array and it will give you the formnot just for devs. themers can control form output
![Page 26: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/26.jpg)
FAPI
• form.inc
• handles the form, validation and submission
give it an array and it will give you the formnot just for devs. themers can control form output
![Page 27: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/27.jpg)
dbs are not standardized for creation (schema)built in security
![Page 28: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/28.jpg)
Database
• database.inc (and database*.inc)
• schema creation
• abstracted to work with multiple databases
dbs are not standardized for creation (schema)built in security
![Page 29: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/29.jpg)
output is put through the theme systemmany core theme elements are found in tpl files in the modules
![Page 30: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/30.jpg)
Theme layer✦theme.inc
✦system module has default tpls
✦ block, box, page
✦ other tpls are in the module folder
output is put through the theme systemmany core theme elements are found in tpl files in the modules
![Page 31: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/31.jpg)
Theme’s rulethey get a last crack at all output so the themer can change whatever they needa function named mytheme_function_name will trump core and modules
![Page 32: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/32.jpg)
✴Module output uses theme()
✴Order of priority:
✴ theme_function_name()
✴ phptemplate_function_name()
✴mytheme_function_name()
Theme’s rulethey get a last crack at all output so the themer can change whatever they needa function named mytheme_function_name will trump core and modules
![Page 33: Gentle Intro to Drupal Code](https://reader034.fdocuments.in/reader034/viewer/2022051512/5441beebafaf9f4e208b47a4/html5/thumbnails/33.jpg)
Resources
Developer/Theme handbooks
Drupal source/api.drupal.org
Dev/Theme mailing lists (drupal.com/mailing-lists)
IRC: #drupal (#drupal-dev) #drupal-themes
Issue queues
Paper books: http://drupal.org/books