Gentle Intro to Drupal Code

Preview:

DESCRIPTION

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

Citation preview

A Gentle Introduction

Addison Berry, LullabotDrupalCon, 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 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 :)

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 :)

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 :)

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 :)

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.

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.

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.

Hooks

‣ Naming convention

‣ hook_* where hook is replaced by your module name

‣ Lets modules add their own stuff to Drupal’s workflow

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

hook_perm

Each module can respond by saying they have something.If they don’t have anything, they just don’t use the hook.

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.

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.

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.

Voila!

This is the display that gets made from hook_perm

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

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

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

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

Some major players

Menu

Form

Database

Theme

output: HTML, RSSactions like: forwarding, login/logoutevery internal link on a Drupal site is controlled by the menu system

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

give it an array and it will give you the formnot just for devs. themers can control form output

give it an array and it will give you the formnot just for devs. themers can control form output

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

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

Database

• database.inc (and database*.inc)

• schema creation

• abstracted to work with multiple databases

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

output is put through the theme systemmany core theme elements are found in tpl files in the modules

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

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

✴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

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