A Gentle Introduction


Addison Berry, Lullabot
DrupalCon, Washington, DC 2009
A lot of people get a bit overwhelmed by Drupal coding.
Sometimes that leads to running away or hacking.
Systems, Frameworks
               and APIs, Oh My!




API = set of functions that accomplish programming tasks - can be ...
Systems, Frameworks
               and APIs, Oh My!
                                        Content Management System
    ...
Systems, Frameworks
               and APIs, Oh My!
                                        Content Management System
    ...
Systems, Frameworks
               and APIs, Oh My!
                                        Content Management System
    ...
What is where?




CMS  framework  apis
Core modules and themes use the framework like everyone else.
Everyone should actu...
What is where?




CMS  framework  apis
Core modules and themes use the framework like everyone else.
Everyone should actu...
What is where?

                                                           base_path()
                                   ...
Hooks

‣ Naming convention
  ‣ hook_* where hook is replaced
    by your module name
‣ Lets modules add their own stuff
  ...
A hook example

                                           Hey modules! I’m
                                           gon...
hook_perm




Each module can respond by saying they have something.
If they don’t have anything, they just don’t use the ...
blog_perm
                           I do!

                 blog




Each module can respond by saying they have somethin...
block_perm
                           I do!

                 blog




                            block

                ...
hook_perm
                           I do!

                 blog



                                                     ...
Voila!




This is the display that gets made from hook_perm
The Train Analogy




•   The Node Train leaves the station with node/12 hitched
    It goes to the hook_nodeapi stop
    ...
The Train Analogy




•   The Node Train leaves the station with node/12 hitched
    It goes to the hook_nodeapi stop
    ...
The Train Analogy




•   The Node Train leaves the station with node/12 hitched
    It goes to the hook_nodeapi stop
    ...
The Train Analogy




•   The Node Train leaves the station with node/12 hitched
    It goes to the hook_nodeapi stop
    ...
Some major players
       Menu
       Form
       Database
       Theme
output: HTML, RSS
actions like: forwarding, login/logout
every internal link on a Drupal site is controlled by the menu sy...
Menu
                        ๏menu.inc != menu.module
                        ๏maps URLs to functions
                    ...
give it an array and it will give you the form
not just for devs. themers can control form output
give it an array and it will give you the form
not just for devs. themers can control form output
FAPI

                      • form.inc
                      • handles the form, validation
                         and s...
dbs are not standardized for creation (schema)
built in security
Database

                         • database.inc (and
                            database*.inc)

                       ...
output is put through the theme system
many core theme elements are found in tpl files in the modules
Theme layer
             ✦theme.inc
             ✦system module has default tpls
                    block, box, page
    ...
Theme’s rule
they get a last crack at all output so the themer can change whatever they need
a function named mytheme_func...
✴Module output uses theme()
                       ✴Order of priority:
                          ✴ theme_function_name()
 ...
Resources
Developer/Theme handbooks
Drupal source/api.drupal.org
Dev/Theme mailing lists (drupal.com/mailing-lists)
IRC: #...
Upcoming SlideShare
Loading in...5
×

Gentle Intro to Drupal Code

5,016

Published on

Slides from my Drupalcon DC presentation. http://dc2009.drupalcon.org/session/gentle-intro-drupal-code

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,016
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
175
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Gentle Intro to Drupal Code"

  1. 1. A Gentle Introduction Addison Berry, Lullabot DrupalCon, Washington, DC 2009
  2. 2. A lot of people get a bit overwhelmed by Drupal coding. Sometimes that leads to running away or hacking.
  3. 3. 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 way CMS = features that help people build sites and manage content Advantages: takes care of nasty, tedious stu; auth., security, etc. and its Open Source :)
  4. 4. Systems, Frameworks and APIs, Oh My! Content Management System built 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 way CMS = features that help people build sites and manage content Advantages: takes care of nasty, tedious stu; auth., security, etc. and its Open Source :)
  5. 5. Systems, Frameworks and APIs, Oh My! Content Management System built 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 way CMS = features that help people build sites and manage content Advantages: takes care of nasty, tedious stu; auth., security, etc. and its Open Source :)
  6. 6. Systems, Frameworks and APIs, Oh My! Content Management System built 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 way CMS = features that help people build sites and manage content Advantages: takes care of nasty, tedious stu; auth., security, etc. and its Open Source :)
  7. 7. What is where? CMS framework apis Core modules and themes use the framework like everyone else. Everyone should actually look at the files. Includes folder holds the magic.
  8. 8. What is where? CMS framework apis Core modules and themes use the framework like everyone else. Everyone should actually look at the files. Includes folder holds the magic.
  9. 9. What is where? base_path() format_date() l() t() url() CMS framework apis Core modules and themes use the framework like everyone else. Everyone should actually look at the files. Includes folder holds the magic.
  10. 10. Hooks ‣ Naming convention ‣ hook_* where hook is replaced by your module name ‣ Lets modules add their own stuff to Drupal’s workflow
  11. 11. 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
  12. 12. hook_perm Each module can respond by saying they have something. If they don’t have anything, they just don’t use the hook.
  13. 13. blog_perm I do! blog Each module can respond by saying they have something. If they don’t have anything, they just don’t use the hook.
  14. 14. block_perm I do! blog block me too Each module can respond by saying they have something. If they don’t have anything, they just don’t use the hook.
  15. 15. hook_perm I do! blog blogapi block I don’t me too Each module can respond by saying they have something. If they don’t have anything, they just don’t use the hook.
  16. 16. Voila! This is the display that gets made from hook_perm
  17. 17. The Train Analogy • The Node Train leaves the station with node/12 hitched It goes to the hook_nodeapi stop Attaches the taxonomy and comment cars Gets to the Theme depot
  18. 18. The Train Analogy • The Node Train leaves the station with node/12 hitched It goes to the hook_nodeapi stop Attaches the taxonomy and comment cars Gets to the Theme depot
  19. 19. The Train Analogy • The Node Train leaves the station with node/12 hitched It goes to the hook_nodeapi stop Attaches the taxonomy and comment cars Gets to the Theme depot
  20. 20. The Train Analogy • The Node Train leaves the station with node/12 hitched It goes to the hook_nodeapi stop Attaches the taxonomy and comment cars Gets to the Theme depot
  21. 21. Some major players Menu Form Database Theme
  22. 22. output: HTML, RSS actions like: forwarding, login/logout every internal link on a Drupal site is controlled by the menu system
  23. 23. Menu ๏menu.inc != menu.module ๏maps URLs to functions ๏functions can display output and initiate actions output: HTML, RSS actions like: forwarding, login/logout every internal link on a Drupal site is controlled by the menu system
  24. 24. give it an array and it will give you the form not just for devs. themers can control form output
  25. 25. give it an array and it will give you the form not just for devs. themers can control form output
  26. 26. FAPI • form.inc • handles the form, validation and submission give it an array and it will give you the form not just for devs. themers can control form output
  27. 27. dbs are not standardized for creation (schema) built in security
  28. 28. Database • database.inc (and database*.inc) • schema creation • abstracted to work with multiple databases dbs are not standardized for creation (schema) built in security
  29. 29. output is put through the theme system many core theme elements are found in tpl files in the modules
  30. 30. 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 system many core theme elements are found in tpl files in the modules
  31. 31. Theme’s rule they get a last crack at all output so the themer can change whatever they need a function named mytheme_function_name will trump core and modules
  32. 32. ✴Module output uses theme() ✴Order of priority: ✴ theme_function_name() ✴ phptemplate_function_name() ✴ mytheme_function_name() Theme’s rule they get a last crack at all output so the themer can change whatever they need a function named mytheme_function_name will trump core and modules
  33. 33. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×