33
A Gentle Introduction Addison Berry, Lullabot DrupalCon, Washington, DC 2009

Gentle Intro to Drupal Code

  • View
    6.201

  • Download
    1

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Gentle Intro to Drupal Code

A Gentle Introduction

Addison Berry, LullabotDrupalCon, Washington, DC 2009

Page 2: Gentle Intro to Drupal Code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Voila!

This is the display that gets made from hook_perm

Page 17: Gentle Intro to Drupal Code

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

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

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

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

Some major players

Menu

Form

Database

Theme

Page 22: Gentle Intro to Drupal Code

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

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

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

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

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

dbs are not standardized for creation (schema)built in security

Page 28: Gentle Intro to Drupal Code

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

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

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

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

✴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

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