Drupal Development
Upcoming SlideShare
Loading in...5
×
 

Drupal Development

on

  • 10,720 views

Intro to Drupal Development (Part 1), originally presented at the Chicago CMS Expo. See http://cmsexpo.net for details and other session information.

Intro to Drupal Development (Part 1), originally presented at the Chicago CMS Expo. See http://cmsexpo.net for details and other session information.

Statistics

Views

Total Views
10,720
Views on SlideShare
10,646
Embed Views
74

Actions

Likes
25
Downloads
327
Comments
1

5 Embeds 74

http://www.slideshare.net 40
http://surfmagix.com 26
http://mmsac-forums.blogspot.com 5
https://si0.twimg.com 2
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • amazing ...
    where can i findout the Drupal Code: Day 2...??
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • Core - bootstrap, route incoming page requests to modules <br /> Modules - Build page content and respond to events <br /> Many third-party modules, some build on top of other modules <br /> Theme - Turn data from modules into HTML. <br /> <br /> <br /> <br /> We’ll be concentrating on the module side of things today. <br />
  • This is a module. Two files, A few lines of code. <br /> In Drupal, that’s all you need to customize the behavior of the system and add new functionality. <br />
  • A little more complicated. Shorter function, has an .install file. <br /> <br /> <br />
  • This is a module, too. Views, one of Drupal’s most popular, contains over 400 files, over a meg of code and inline docs. <br /> Don’t worry, there’s a middle ground. <br /> We’re going to cover what they have in common. <br />
  • This is a module, too. Views, one of Drupal’s most popular, contains over 400 files, over a meg of code and inline docs. <br /> Don’t worry, there’s a middle ground. <br /> We’re going to cover what they have in common. <br />
  • <br /> <br />
  • Part 1: user with a web browser makes a request. <br /> sends a URL, optionally a cookie. <br /> <br /> <br /> <br /> http://www.mysite.com/articles/welcome.html <br /> <br /> <br />
  • Apache intercepts the request. <br /> Possibly routes it to other servers <br /> What folder should I look in for foo.com? <br /> Normally, it would then check /articles for a welcome.html file and send it back. <br /> .htaccess turns foo.com/blah into foo.com/index.php?q=blah <br /> ...And PHP takes over. <br />
  • Apache intercepts the request. <br /> Possibly routes it to other servers <br /> What folder should I look in for foo.com? <br /> Normally, it would then check /articles for a welcome.html file and send it back. <br /> .htaccess turns foo.com/blah into foo.com/index.php?q=blah <br /> ...And PHP takes over. <br />
  • Apache intercepts the request. <br /> Possibly routes it to other servers <br /> What folder should I look in for foo.com? <br /> Normally, it would then check /articles for a welcome.html file and send it back. <br /> .htaccess turns foo.com/blah into foo.com/index.php?q=blah <br /> ...And PHP takes over. <br />
  • Apache intercepts the request. <br /> Possibly routes it to other servers <br /> What folder should I look in for foo.com? <br /> Normally, it would then check /articles for a welcome.html file and send it back. <br /> .htaccess turns foo.com/blah into foo.com/index.php?q=blah <br /> ...And PHP takes over. <br />
  • Bootstrap <br /> All page requests go through index.php (front-side controller) <br /> Bootstrap Drupal core, load essential includes <br /> What site am I running? connect to database <br /> Is there a cookie? Load the user. <br /> Now, ask for menu items... <br />
  • Bootstrap <br /> All page requests go through index.php (front-side controller) <br /> Bootstrap Drupal core, load essential includes <br /> What site am I running? connect to database <br /> Is there a cookie? Load the user. <br /> Now, ask for menu items... <br />
  • Bootstrap <br /> All page requests go through index.php (front-side controller) <br /> Bootstrap Drupal core, load essential includes <br /> What site am I running? connect to database <br /> Is there a cookie? Load the user. <br /> Now, ask for menu items... <br />
  • Bootstrap <br /> All page requests go through index.php (front-side controller) <br /> Bootstrap Drupal core, load essential includes <br /> What site am I running? connect to database <br /> Is there a cookie? Load the user. <br /> Now, ask for menu items... <br />
  • Bootstrap <br /> All page requests go through index.php (front-side controller) <br /> Bootstrap Drupal core, load essential includes <br /> What site am I running? connect to database <br /> Is there a cookie? Load the user. <br /> Now, ask for menu items... <br />
  • The module <br /> Why, yes! Here’s a list of all the URLs I can handle. <br /> Explain each line. See api.drupal.org <br /> This is called a hook. We’ll get to this later. <br />
  • The module <br /> Why, yes! Here’s a list of all the URLs I can handle. <br /> Explain each line. See api.drupal.org <br /> This is called a hook. We’ll get to this later. <br />
  • Traffic Cop <br /> Is welcome.html an SEO-friendly alias? (about/welcome vs. welcome.html) <br /> Find the best match. (about) <br /> Run access checks. <br /> Call the function, passing along unused pieces of the path <br /> <br /> <br />
  • Grunt work <br /> Module’s function gets called. Extra params passed along. <br /> That’s how node module works -- ‘node’ plus a wildcard <br /> Can do anything now: print out JSON and exit(), etc. <br /> To build a normal page, build HTML and return it. <br />
  • Grunt work <br /> Module’s function gets called. Extra params passed along. <br /> That’s how node module works -- ‘node’ plus a wildcard <br /> Can do anything now: print out JSON and exit(), etc. <br /> To build a normal page, build HTML and return it. <br />
  • Presentation <br /> Checks for 404, 403, and empty page. <br /> index.php now has the contents of the page. <br /> theme(‘page’, $content) <br /> Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc. <br /> <br /> <br />
  • Presentation <br /> Checks for 404, 403, and empty page. <br /> index.php now has the contents of the page. <br /> theme(‘page’, $content) <br /> Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc. <br /> <br /> <br />
  • Presentation <br /> Checks for 404, 403, and empty page. <br /> index.php now has the contents of the page. <br /> theme(‘page’, $content) <br /> Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc. <br /> <br /> <br />
  • Oh, look. Welcome.html! <br /> Apache gets back the fully rendered HTML. Sweet. <br /> Document gets fired back to the user. <br /> The user’s browser renders it -- and they click on the next link and the process starts all over again. <br />
  • Important detail: when drupal asked about menus and modules responded, we saw a hook. <br /> hooks are everywhere: when pieces of content load, when a db query is run, when a user logs in… <br /> that’s a drupal event. module_invoke_all(‘hook’) => for modules()… _menu() <br /> Modules can create their own hooks just by calling module_invoke_all() <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • As a Drupal page is built, events are firing nonstop. <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • Hooks can announce what’s going on <br /> Allow modules to answer questions <br /> Allow modules to extend functionality <br /> Allow modules to change existing workflows <br />
  • Hooks can announce what’s going on <br /> Allow modules to answer questions <br /> Allow modules to extend functionality <br /> Allow modules to change existing workflows <br />
  • Hooks can announce what’s going on <br /> Allow modules to answer questions <br /> Allow modules to extend functionality <br /> Allow modules to change existing workflows <br />
  • Hooks can announce what’s going on <br /> Allow modules to answer questions <br /> Allow modules to extend functionality <br /> Allow modules to change existing workflows <br />
  • Hooks can announce what’s going on <br /> Allow modules to answer questions <br /> Allow modules to extend functionality <br /> Allow modules to change existing workflows <br />
  • What does “hacking core” mean? <br /> Why is it bad? <br />
  • What does “hacking core” mean? <br /> Why is it bad? <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />

Drupal Development Drupal Development Presentation Transcript

  • Drupal Code: Day 1 where am i, and how did i get all these arrays
  • Hi. I’m eaton.
  • Drupal is... http://www.flickr.com/photos/druclimb/282597447/
  • Drupal is... Drupal Core http://www.flickr.com/photos/druclimb/282597447/
  • Drupal is... Node Drupal Core User http://www.flickr.com/photos/druclimb/282597447/
  • Drupal is... Views Five Star CCK Node Drupal Core User http://www.flickr.com/photos/druclimb/282597447/
  • Drupal is... Theme Views Five Star CCK Node Drupal Core User http://www.flickr.com/photos/druclimb/282597447/
  • Drupal is... Theme Views Five Star CCK Node Drupal Core User http://www.flickr.com/photos/druclimb/282597447/
  • name = Demo description = Just a simple demo module. core = 6.x function demo_nodeapi(&$node, $op) { global $user; if ($op == ‘view’) { if ($node->uid == $user->uid) { $node->title . ‘ [YOUR ARTICLE]’; } } } demo.info demo.module
  • name = Tricky description = A slightly trickier module. core = 6.x function tricky_form_alter(&form, $form_state, $id) { if ($id == ‘node_form’) { $title[‘#required’] = FALSE; } } function tricky_install() { drupal_set_message(‘You just installed Tricky!’); } tricky.info tricky.module tricky.install
  • views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc filters.inc query.inc sprout.info sprout.module forum.inc views.pages.inc table.inc views.install sprout.install sprout.admin.inc sprout.inc CHANGELOG README
  • views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc filters.inc query.inc sprout.info sprout.module forum.inc views.pages.inc table.inc views.install sprout.install sprout.admin.inc sprout.inc CHANGELOG README
  • views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc filters.inc query.inc sprout.info sprout.module forum.inc views.pages.inc table.inc views.install sprout.install sprout.admin.inc sprout.inc CHANGELOG README
  • under the hood http://www.flickr.com/photos/sprakope/143770402/
  • I’d like welcome.html!
  • I’d like welcome.html!
  • I’ll go get that html file!
  • I’ll go get that html file!
  • I’ll go get that html file! .htaccess says to check… index.php?q=welcome.html
  • Index.php? I’ve got that.
  • Index.php? I’ve got that. bootstrap.inc menu.inc random mysql user
  • Here are all my URLs…
  • function mymodule_menu() { $items['about'] = array( 'title' => 'About us', 'description' => 'A description of us.', 'page callback' => 'mymodule_about', 'access arguments' => array('access content'), ); return $items; } Here are all my URLs…
  • function mymodule_menu() { $items['about'] = array( 'title' => 'About us', 'description' => 'A description of us.', 'page callback' => 'mymodule_about', 'access arguments' => array('access content'), ); return $items; } Here are all my URLs…
  • What’s the best match?
  • What’s the best match? Is welcome.html an alias? Does anyone handle the path? Does the user have access?
  • I’ll build the contents.
  • function mymodule_about($subpage = ‘legal’) { if ($subpage == ‘legal’) { return “We don’t have lawyers yet.”; } if ($subpage == ‘welcome’) { return “Welcome to our web site!”; } } I’ll build the contents.
  • function mymodule_about($subpage = ‘legal’) { if ($subpage == ‘legal’) { return “We don’t have lawyers yet.”; } if ($subpage == ‘welcome’) { return “Welcome to our web site!”; } } I’ll build the contents.
  • I’ll take that HTML...
  • I’ll take that HTML...
  • I’ll take that HTML...
  • I’ll take that HTML...
  • Here’s index.php… Eh, looks like welcome.html…
  • don’t use a hack. hook! http://www.flickr.com/photos/lanier67/185311136/
  • A list of content types A user is is being built registering A node is being Content is being displayed searched The menu is Links are being being built displayed The database is being queried A comment is being posted A form is being processed
  • module_invoke_all(‘foo’)
  • yourmodule_foo()
  • theirmodule_foo() mymodule_foo() yourmodule_foo() hismodule_foo() hermodule_foo()
  • function demo_nodeapi(&$node, $op) { global $user; if ($op == ‘view’ && $node->uid == $user->uid) { $node->title . ‘ [YOUR ARTICLE]’; } } function demo_form_alter(&form, $form_state, $id) { if ($id == ‘node_form’) { $title[‘#required’] = FALSE; } }
  • i
  • i ?
  • i ?
  • i ?
  • i All w i t h o u t h a ng ing Dr u p a l’s c o w n c o de ! ?
  • Don’t. Hack. Core.
  • Don’t. Hack. Core.
  • let’s see a module! http://www.flickr.com/photos/gonzales2010/8632116/
  • name = Birthday description = Wishes users a happy birthday. requirements[] = user core = 6.x
  • name = Birthday description = Wishes users a happy birthday. requirements[] = user core = 6.x
  • /** * Allows users to save their birthday, * and congratulates them on the big day. */ function birthday_menu() { $items['admin/settings/birthdays'] = array( 'title' => 'Birthday settings', 'description' => 'Settings for birthdays.', 'page callback' => 'birthday_page', 'access arguments' => array('administer users'), ); return $items; } function birthday_page() { return drupal_get_form('birthday_form'); }
  • /** * Allows users to save their birthday, * and congratulates them on the big day. */ function birthday_menu() { $items['admin/settings/birthdays'] = array( 'title' => 'Birthday settings', 'description' => 'Settings for birthdays.', 'page callback' => 'birthday_page', 'access arguments' => array('administer users'), ); return $items; } function birthday_page() { return drupal_get_form('birthday_form'); }
  • function birthday_form() { $form['birthday_age'] = array( '#type' => 'checkbox', '#title' => t(quot;Show users how old they are.quot;), '#default_value' => variable_get('age', TRUE), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save settings'), ); return $form; } function birthday_form_submit($form, $form_state) { $values = $form_state['values']; variable_set('age', $values['birthday_age']); drupal_set_message(t('Birthday settings saved.')); }
  • function birthday_form() { $form['birthday_age'] = array( '#type' => 'checkbox', '#title' => t(quot;Show users how old they are.quot;), '#default_value' => variable_get('age', TRUE), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save settings'), ); return $form; } function birthday_form_submit($form, $form_state) { $values = $form_state['values']; variable_set('age', $values['birthday_age']); drupal_set_message(t('Birthday settings saved.')); }
  • function birthday_user($op, &$edit, &$account) { if ($op == 'view' && $day = $account->birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account->content['birthday'] = array( '#type' => 'item', '#title' => t('Birthday'), '#value' => date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' => 'date', '#title' => t('Birthday'), '#default_value' => $account->birthday); return $form; } }
  • function birthday_user($op, &$edit, &$account) { if ($op == 'view' && $day = $account->birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account->content['birthday'] = array( '#type' => 'item', '#title' => t('Birthday'), '#value' => date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' => 'date', '#title' => t('Birthday'), '#default_value' => $account->birthday); return $form; } }
  • function birthday_user($op, &$edit, &$account) { if ($op == 'view' && $day = $account->birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account->content['birthday'] = array( '#type' => 'item', '#title' => t('Birthday'), '#value' => date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' => 'date', '#title' => t('Birthday'), '#default_value' => $account->birthday); return $form; } }
  • function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' && $day = $user->birthday) { if ($day['month']==date('n') && $day['day']==date('j')) { $message = t(quot;It's your birthday! it's your birthday!quot;); if (variable_get('age', TRUE)) { $age = date('Y') - $day['year']; $message .= t(quot; You're %age.quot;, array('%age' => $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
  • function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' && $day = $user->birthday) { if ($day['month']==date('n') && $day['day']==date('j')) { $message = t(quot;It's your birthday! it's your birthday!quot;); if (variable_get('age', TRUE)) { $age = date('Y') - $day['year']; $message .= t(quot; You're %age.quot;, array('%age' => $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
  • function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' && $day = $user->birthday) { if ($day['month']==date('n') && $day['day']==date('j')) { $message = t(quot;It's your birthday! it's your birthday!quot;); if (variable_get('age', TRUE)) { $age = date('Y') - $day['year']; $message .= t(quot; You're %age.quot;, array('%age' => $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
  • function birthday_song() { $path = drupal_get_path('module', 'birthday'); $path .= '/birthday.mid '; $output = '<embed src=quot;' . $path . 'quot;; $output .= ' autostart=quot;truequot; loop=quot;truequot;'; $output .= ' width=quot;2quot; height=quot;0quot;></embed>'; return $output; }
  • function birthday_song() { $path = drupal_get_path('module', 'birthday'); $path .= '/birthday.mid '; $output = '<embed src=quot;' . $path . 'quot;; $output .= ' autostart=quot;truequot; loop=quot;truequot;'; $output .= ' width=quot;2quot; height=quot;0quot;></embed>'; return $output; }
  • http://www.flickr.com/photos/thomashawk/2681744739
  • drupal manages the page http://www.flickr.com/photos/thomashawk/2681744739
  • drupal manages the page modules build the content http://www.flickr.com/photos/thomashawk/2681744739
  • drupal manages the page modules build the content modules also respond to events http://www.flickr.com/photos/thomashawk/2681744739
  • drupal manages the page modules build the content modules also respond to events hack with hooks http://www.flickr.com/photos/thomashawk/2681744739
  • api.drupal.org tinyurl.com/drupal-code tinyurl.com/drupal-kickstart tinyurl.com/drupal-rocking