Newbie to Ninja -- Drupal development training

Newbie to Ninja... Drupal development training

by

Chad Phillips (hunmonk)

http://drupal5.xcarnated.com/drupal-ninja-training
http://drupal5.xcarnated.com/node/22/s5

Your destination...


= super Drupal developer ninja dude...

Overview

  • Drupal basics
  • Setting up a working development stack
  • Editors, IDE's
  • Coding standards
  • Resources
  • Helper modules
  • Tips

Drupal basics

  • Drupal is modular
  • Core/Contributions
  • Uses a hook system
  • Content separate from presentation

Drupal hooks 101

  1. Core 'invokes' a hook.
  2. Modules implement the hook via a naming convention: modulename_hookname
  3. In module's hook code it can:
    • Take actions pertaining to the module
    • Return information to core
    • Alter information or data from other modules

hook_menu()

  • Maps a URI to the code needed to build the page
  • Determines if the URI is accessible to a user
  • Records the URI into a menu "tree" of related URIs and paths
    • Adds a link to the "navigation" menu
    • Remembers the paths that lead to a given URI for generating breadcrumbs

hook_form_alter()

  • Forms represented as nested arrays
  • After core builds a form, it passes the array around to other modules
  • Modules can alter parts of the array (form), add to it, or delete it

Content != Presentation
Generally what happens is:

  • Content is stored in the database
  • When a page is requested, the content is retrieved from the database
  • The content is processed and run through Drupal's theming system
  • The HTML is built for the page

What Drupal needs

  • Web Server (Apache, IIS)
  • PHP (scripting language)
  • Database server (MySQL, PostgreSQL)

The easy way – using *AMP

Advantages

  • Simple to download and install
  • Mostly pre-configured for development needs
  • Standalone (easy to uninstall)
  • Other goodies (phpMyAdmin)

Video tutorials of MAMP/WAMP installation:
http://drupal.org/node/159534

Editors
Talking about 'the best editor/IDE' can often lead to a lot of different opinions...


An ideal editor/IDE would

  • Load quickly
  • Be intuitive/fast to navigate/use
  • Cost nothing
  • Be widely available
  • Offer the ability for customization
  • Color-code your programming language
  • Support code completion
  • Include a step debugger

Editors

IDEs
IDE = Integrated Development Environment

Coding standards
Two kinds of standards:

Why?

  • More consistent between developers
  • Easier to read
  • Allows for automated code documentation
  • More secure
  • Critical for getting core patches accepted

I'm stuck -- now what??


Resources
http://drupal.org/support
http://drupal.org/handbooks


IRC (Internet Relay Chat)

  • #drupal
    General advocacy, development questions & discussion
  • #drupal-dev
    Developer-centric -- lot's o' ninjas around...
  • #drupal-support
    General support questions
  • #drupal-themes
    Specific help for Drupal themers

Full Drupal IRC chatroom list: http://drupal.org/node/108355 -- or make your own!!

Tutorial: http://www.irchelp.org/irchelp/irctutorial.html

drupal.org Forums
http://drupal.org/forum

Other resources

Helper modules

API module

  • Code documentation
    • Functions/hooks
    • Files
    • Constants
    • Globals
    • General topics (database layer, menu system, etc...)
  • http://api.drupal.org

Devel module

Coder module

  • Drupal coding standards
  • Automatic module upgrade
  • Secure text handling checker
  • Performance review

http://boston2008.drupalcon.org/node/731

Simpletest module

http://boston2008.drupalcon.org/node/429

Tips


Master CVS/Project management

Tips from a super-ninja (chx)

  • Use test scripts
    Copy first two lines of index.php, then paste in your code.
  • Examine your variables
    print_r(), var_dump(), var_export(), step debugger
  • exit() is your friend
    Great for tracing down a crash.
    Bisect your code flow with exit() calls until you locate the problem line.
  • Study core's code

More tips