Your SlideShare is downloading. ×
0
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Drupal Development
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Drupal Development

8,763

Published on

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.

Published in: Technology, Design
1 Comment
26 Likes
Statistics
Notes
  • amazing ...
    where can i findout the Drupal Code: Day 2...??
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
8,763
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
372
Comments
1
Likes
26
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide






  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • Core - bootstrap, route incoming page requests to modules
    Modules - Build page content and respond to events
    Many third-party modules, some build on top of other modules
    Theme - Turn data from modules into HTML.



    We’ll be concentrating on the module side of things today.
  • This is a module. Two files, A few lines of code.
    In Drupal, that’s all you need to customize the behavior of the system and add new functionality.
  • A little more complicated. Shorter function, has an .install file.


  • This is a module, too. Views, one of Drupal’s most popular, contains over 400 files, over a meg of code and inline docs.
    Don’t worry, there’s a middle ground.
    We’re going to cover what they have in common.
  • This is a module, too. Views, one of Drupal’s most popular, contains over 400 files, over a meg of code and inline docs.
    Don’t worry, there’s a middle ground.
    We’re going to cover what they have in common.


  • Part 1: user with a web browser makes a request.
    sends a URL, optionally a cookie.



    http://www.mysite.com/articles/welcome.html


  • Apache intercepts the request.
    Possibly routes it to other servers
    What folder should I look in for foo.com?
    Normally, it would then check /articles for a welcome.html file and send it back.
    .htaccess turns foo.com/blah into foo.com/index.php?q=blah
    ...And PHP takes over.
  • Apache intercepts the request.
    Possibly routes it to other servers
    What folder should I look in for foo.com?
    Normally, it would then check /articles for a welcome.html file and send it back.
    .htaccess turns foo.com/blah into foo.com/index.php?q=blah
    ...And PHP takes over.
  • Apache intercepts the request.
    Possibly routes it to other servers
    What folder should I look in for foo.com?
    Normally, it would then check /articles for a welcome.html file and send it back.
    .htaccess turns foo.com/blah into foo.com/index.php?q=blah
    ...And PHP takes over.
  • Apache intercepts the request.
    Possibly routes it to other servers
    What folder should I look in for foo.com?
    Normally, it would then check /articles for a welcome.html file and send it back.
    .htaccess turns foo.com/blah into foo.com/index.php?q=blah
    ...And PHP takes over.
  • Bootstrap
    All page requests go through index.php (front-side controller)
    Bootstrap Drupal core, load essential includes
    What site am I running? connect to database
    Is there a cookie? Load the user.
    Now, ask for menu items...
  • Bootstrap
    All page requests go through index.php (front-side controller)
    Bootstrap Drupal core, load essential includes
    What site am I running? connect to database
    Is there a cookie? Load the user.
    Now, ask for menu items...
  • Bootstrap
    All page requests go through index.php (front-side controller)
    Bootstrap Drupal core, load essential includes
    What site am I running? connect to database
    Is there a cookie? Load the user.
    Now, ask for menu items...
  • Bootstrap
    All page requests go through index.php (front-side controller)
    Bootstrap Drupal core, load essential includes
    What site am I running? connect to database
    Is there a cookie? Load the user.
    Now, ask for menu items...
  • Bootstrap
    All page requests go through index.php (front-side controller)
    Bootstrap Drupal core, load essential includes
    What site am I running? connect to database
    Is there a cookie? Load the user.
    Now, ask for menu items...
  • The module
    Why, yes! Here’s a list of all the URLs I can handle.
    Explain each line. See api.drupal.org
    This is called a hook. We’ll get to this later.
  • The module
    Why, yes! Here’s a list of all the URLs I can handle.
    Explain each line. See api.drupal.org
    This is called a hook. We’ll get to this later.
  • Traffic Cop
    Is welcome.html an SEO-friendly alias? (about/welcome vs. welcome.html)
    Find the best match. (about)
    Run access checks.
    Call the function, passing along unused pieces of the path


  • Grunt work
    Module’s function gets called. Extra params passed along.
    That’s how node module works -- ‘node’ plus a wildcard
    Can do anything now: print out JSON and exit(), etc.
    To build a normal page, build HTML and return it.
  • Grunt work
    Module’s function gets called. Extra params passed along.
    That’s how node module works -- ‘node’ plus a wildcard
    Can do anything now: print out JSON and exit(), etc.
    To build a normal page, build HTML and return it.
  • Presentation
    Checks for 404, 403, and empty page.
    index.php now has the contents of the page.
    theme(‘page’, $content)
    Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc.


  • Presentation
    Checks for 404, 403, and empty page.
    index.php now has the contents of the page.
    theme(‘page’, $content)
    Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc.


  • Presentation
    Checks for 404, 403, and empty page.
    index.php now has the contents of the page.
    theme(‘page’, $content)
    Sidebar blocks get loaded, the theme system is given a chance to add CSS and JS, etc.


  • Oh, look. Welcome.html!
    Apache gets back the fully rendered HTML. Sweet.
    Document gets fired back to the user.
    The user’s browser renders it -- and they click on the next link and the process starts all over again.
  • Important detail: when drupal asked about menus and modules responded, we saw a hook.
    hooks are everywhere: when pieces of content load, when a db query is run, when a user logs in…
    that&#x2019;s a drupal event. module_invoke_all(&#x2018;hook&#x2019;) => for modules()&#x2026; <name>_menu()
    Modules can create their own hooks just by calling module_invoke_all()
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.
  • As a Drupal page is built, events are firing nonstop.












  • Hooks can announce what&#x2019;s going on
    Allow modules to answer questions
    Allow modules to extend functionality
    Allow modules to change existing workflows
  • Hooks can announce what&#x2019;s going on
    Allow modules to answer questions
    Allow modules to extend functionality
    Allow modules to change existing workflows
  • Hooks can announce what&#x2019;s going on
    Allow modules to answer questions
    Allow modules to extend functionality
    Allow modules to change existing workflows
  • Hooks can announce what&#x2019;s going on
    Allow modules to answer questions
    Allow modules to extend functionality
    Allow modules to change existing workflows
  • Hooks can announce what&#x2019;s going on
    Allow modules to answer questions
    Allow modules to extend functionality
    Allow modules to change existing workflows
  • What does &#x201C;hacking core&#x201D; mean?
    Why is it bad?
  • What does &#x201C;hacking core&#x201D; mean?
    Why is it bad?
























  • Transcript

    • 1. Drupal Code: Day 1 where am i, and how did i get all these arrays
    • 2. Hi. I&#x2019;m eaton.
    • 3. Drupal is... http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 4. Drupal is... Drupal Core http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 5. Drupal is... Node Drupal Core User http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 6. Drupal is... Views Five Star CCK Node Drupal Core User http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 7. Drupal is... Theme Views Five Star CCK Node Drupal Core User http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 8. Drupal is... Theme Views Five Star CCK Node Drupal Core User http://www.&#xFB02;ickr.com/photos/druclimb/282597447/
    • 9. name = Demo description = Just a simple demo module. core = 6.x function demo_nodeapi(&amp;$node, $op) { global $user; if ($op == &#x2018;view&#x2019;) { if ($node-&gt;uid == $user-&gt;uid) { $node-&gt;title . &#x2018; [YOUR ARTICLE]&#x2019;; } } } demo.info demo.module
    • 10. name = Tricky description = A slightly trickier module. core = 6.x function tricky_form_alter(&amp;form, $form_state, $id) { if ($id == &#x2018;node_form&#x2019;) { $title[&#x2018;#required&#x2019;] = FALSE; } } function tricky_install() { drupal_set_message(&#x2018;You just installed Tricky!&#x2019;); } tricky.info tricky.module tricky.install
    • 11. views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc &#xFB01;lters.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
    • 12. views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc &#xFB01;lters.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
    • 13. views.info views.module views.inc user.inc node.inc blog.inc comment.inc ui.info ui.module arguments.inc handlers.inc &#xFB01;lters.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
    • 14. under the hood http://www.&#xFB02;ickr.com/photos/sprakope/143770402/
    • 15. I&#x2019;d like welcome.html!
    • 16. I&#x2019;d like welcome.html!
    • 17. I&#x2019;ll go get that html &#xFB01;le!
    • 18. I&#x2019;ll go get that html &#xFB01;le!
    • 19. I&#x2019;ll go get that html &#xFB01;le! .htaccess says to check&#x2026; index.php?q=welcome.html
    • 20. Index.php? I&#x2019;ve got that.
    • 21. Index.php? I&#x2019;ve got that. bootstrap.inc menu.inc random mysql user
    • 22. Here are all my URLs&#x2026;
    • 23. function mymodule_menu() { $items['about'] = array( 'title' =&gt; 'About us', 'description' =&gt; 'A description of us.', 'page callback' =&gt; 'mymodule_about', 'access arguments' =&gt; array('access content'), ); return $items; } Here are all my URLs&#x2026;
    • 24. function mymodule_menu() { $items['about'] = array( 'title' =&gt; 'About us', 'description' =&gt; 'A description of us.', 'page callback' =&gt; 'mymodule_about', 'access arguments' =&gt; array('access content'), ); return $items; } Here are all my URLs&#x2026;
    • 25. What&#x2019;s the best match?
    • 26. What&#x2019;s the best match? Is welcome.html an alias? Does anyone handle the path? Does the user have access?
    • 27. I&#x2019;ll build the contents.
    • 28. function mymodule_about($subpage = &#x2018;legal&#x2019;) { if ($subpage == &#x2018;legal&#x2019;) { return &#x201C;We don&#x2019;t have lawyers yet.&#x201D;; } if ($subpage == &#x2018;welcome&#x2019;) { return &#x201C;Welcome to our web site!&#x201D;; } } I&#x2019;ll build the contents.
    • 29. function mymodule_about($subpage = &#x2018;legal&#x2019;) { if ($subpage == &#x2018;legal&#x2019;) { return &#x201C;We don&#x2019;t have lawyers yet.&#x201D;; } if ($subpage == &#x2018;welcome&#x2019;) { return &#x201C;Welcome to our web site!&#x201D;; } } I&#x2019;ll build the contents.
    • 30. I&#x2019;ll take that HTML...
    • 31. I&#x2019;ll take that HTML...
    • 32. I&#x2019;ll take that HTML...
    • 33. I&#x2019;ll take that HTML...
    • 34. Here&#x2019;s index.php&#x2026; Eh, looks like welcome.html&#x2026;
    • 35. don&#x2019;t use a hack. hook! http://www.&#xFB02;ickr.com/photos/lanier67/185311136/
    • 36. 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
    • 37. module_invoke_all(&#x2018;foo&#x2019;)
    • 38. yourmodule_foo()
    • 39. theirmodule_foo() mymodule_foo() yourmodule_foo() hismodule_foo() hermodule_foo()
    • 40. function demo_nodeapi(&amp;$node, $op) { global $user; if ($op == &#x2018;view&#x2019; &amp;&amp; $node-&gt;uid == $user-&gt;uid) { $node-&gt;title . &#x2018; [YOUR ARTICLE]&#x2019;; } } function demo_form_alter(&amp;form, $form_state, $id) { if ($id == &#x2018;node_form&#x2019;) { $title[&#x2018;#required&#x2019;] = FALSE; } }
    • 41. i
    • 42. i ?
    • 43. i ?
    • 44. i ?
    • 45. i All w i t h o u t h a ng ing Dr u p a l&#x2019;s c o w n c o de ! ?
    • 46. Don&#x2019;t. Hack. Core.
    • 47. Don&#x2019;t. Hack. Core.
    • 48. let&#x2019;s see a module! http://www.&#xFB02;ickr.com/photos/gonzales2010/8632116/
    • 49. name = Birthday description = Wishes users a happy birthday. requirements[] = user core = 6.x
    • 50. name = Birthday description = Wishes users a happy birthday. requirements[] = user core = 6.x
    • 51. /** * Allows users to save their birthday, * and congratulates them on the big day. */ function birthday_menu() { $items['admin/settings/birthdays'] = array( 'title' =&gt; 'Birthday settings', 'description' =&gt; 'Settings for birthdays.', 'page callback' =&gt; 'birthday_page', 'access arguments' =&gt; array('administer users'), ); return $items; } function birthday_page() { return drupal_get_form('birthday_form'); }
    • 52. /** * Allows users to save their birthday, * and congratulates them on the big day. */ function birthday_menu() { $items['admin/settings/birthdays'] = array( 'title' =&gt; 'Birthday settings', 'description' =&gt; 'Settings for birthdays.', 'page callback' =&gt; 'birthday_page', 'access arguments' =&gt; array('administer users'), ); return $items; } function birthday_page() { return drupal_get_form('birthday_form'); }
    • 53. function birthday_form() { $form['birthday_age'] = array( '#type' =&gt; 'checkbox', '#title' =&gt; t(quot;Show users how old they are.quot;), '#default_value' =&gt; variable_get('age', TRUE), ); $form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; 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.')); }
    • 54. function birthday_form() { $form['birthday_age'] = array( '#type' =&gt; 'checkbox', '#title' =&gt; t(quot;Show users how old they are.quot;), '#default_value' =&gt; variable_get('age', TRUE), ); $form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; 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.')); }
    • 55. function birthday_user($op, &amp;$edit, &amp;$account) { if ($op == 'view' &amp;&amp; $day = $account-&gt;birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account-&gt;content['birthday'] = array( '#type' =&gt; 'item', '#title' =&gt; t('Birthday'), '#value' =&gt; date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' =&gt; 'date', '#title' =&gt; t('Birthday'), '#default_value' =&gt; $account-&gt;birthday); return $form; } }
    • 56. function birthday_user($op, &amp;$edit, &amp;$account) { if ($op == 'view' &amp;&amp; $day = $account-&gt;birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account-&gt;content['birthday'] = array( '#type' =&gt; 'item', '#title' =&gt; t('Birthday'), '#value' =&gt; date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' =&gt; 'date', '#title' =&gt; t('Birthday'), '#default_value' =&gt; $account-&gt;birthday); return $form; } }
    • 57. function birthday_user($op, &amp;$edit, &amp;$account) { if ($op == 'view' &amp;&amp; $day = $account-&gt;birthday) { $timestamp = mktime(0, 0, 0, $day['month'], $day['day'], $day['year']); $account-&gt;content['birthday'] = array( '#type' =&gt; 'item', '#title' =&gt; t('Birthday'), '#value' =&gt; date('l, F jS, Y', $timestamp)); } elseif ($op == 'form') { $form['birthday'] = array( '#type' =&gt; 'date', '#title' =&gt; t('Birthday'), '#default_value' =&gt; $account-&gt;birthday); return $form; } }
    • 58. function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' &amp;&amp; $day = $user-&gt;birthday) { if ($day['month']==date('n') &amp;&amp; $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' =&gt; $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
    • 59. function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' &amp;&amp; $day = $user-&gt;birthday) { if ($day['month']==date('n') &amp;&amp; $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' =&gt; $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
    • 60. function birthday_block($op = 'list') { global $user; if ($op == 'list') { $block['congrats']['info'] = t('Birthday'); return $block; } elseif ($op == 'view' &amp;&amp; $day = $user-&gt;birthday) { if ($day['month']==date('n') &amp;&amp; $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' =&gt; $age)); } $block['subject'] = t('Happy birthday!'); $block['content'] = $message . birthday_song(); return $block; } } }
    • 61. function birthday_song() { $path = drupal_get_path('module', 'birthday'); $path .= '/birthday.mid '; $output = '&lt;embed src=quot;' . $path . 'quot;; $output .= ' autostart=quot;truequot; loop=quot;truequot;'; $output .= ' width=quot;2quot; height=quot;0quot;&gt;&lt;/embed&gt;'; return $output; }
    • 62. function birthday_song() { $path = drupal_get_path('module', 'birthday'); $path .= '/birthday.mid '; $output = '&lt;embed src=quot;' . $path . 'quot;; $output .= ' autostart=quot;truequot; loop=quot;truequot;'; $output .= ' width=quot;2quot; height=quot;0quot;&gt;&lt;/embed&gt;'; return $output; }
    • 63. http://www.&#xFB02;ickr.com/photos/thomashawk/2681744739
    • 64. drupal manages the page http://www.&#xFB02;ickr.com/photos/thomashawk/2681744739
    • 65. drupal manages the page modules build the content http://www.&#xFB02;ickr.com/photos/thomashawk/2681744739
    • 66. drupal manages the page modules build the content modules also respond to events http://www.&#xFB02;ickr.com/photos/thomashawk/2681744739
    • 67. drupal manages the page modules build the content modules also respond to events hack with hooks http://www.&#xFB02;ickr.com/photos/thomashawk/2681744739
    • 68. api.drupal.org tinyurl.com/drupal-code tinyurl.com/drupal-kickstart tinyurl.com/drupal-rocking

    ×