• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
 

Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008

on

  • 7,335 views

I talked about Best Practices for Drupal Developers @ Drupal Camp India 2008 held on DAIICT Campus in Gandhinagar, on August 08-10.

I talked about Best Practices for Drupal Developers @ Drupal Camp India 2008 held on DAIICT Campus in Gandhinagar, on August 08-10.

Statistics

Views

Total Views
7,335
Views on SlideShare
7,283
Embed Views
52

Actions

Likes
6
Downloads
214
Comments
0

3 Embeds 52

http://www.slideshare.net 49
http://www.linkedin.com 2
file:// 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

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…
Post Comment
Edit your comment

    Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008 Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008 Presentation Transcript

    • HELLO, I AM...
      • Mir Nazim
      • Chief Architect @ iKraft Sofrware Pvt Ltd
      • Working on PHP/Drupal & Python/Django
      • since past few years
      • email me - [email_address]
      • More at www.ikraftsoft.com
    • BEST PRACTICES FOR DRUPAL DEVELOPERS DrupalCamp India August 8/9/10, 2008 Dhirubhai Ambani Institute of Information & Communication Technology Gandhinagar, IN
    • We shall be covering -Best practices for - development environment - module development - theme development - some other stuff
    • Get the source Start out with the CVS checkout ALWAYS ” CVS chekout instruction are available on http://drupal.org/handbooks ”
    • Why use CVS version
      • Single most important reason
      • EASY UPDATES
        • $ cvs update -dP
    • TO NEW DRUPAL VERSION
        • $ cvs update -r DRUPAL-6-3 -dP
        • Be sure that contibuted modules have been ported to the
        • new version
    • revision control your project -Even if: - it is a small project - only you are working on it - Take a pick - svn, bzr, git, darcs ... - VSS(if you are crazy enough) - BUT NOT CVS('coz drupal uses it) the benifits are way too many!
    • The Editor Wars - Komodo Edit/IDE my favourite - Scribes on GNOME my other favourite - PHPEclipse or Eclipse PDT - Qunta Plus on KDE - TextMate on Mac OS X - What? Windows? Are You Kidding? ;)
    • MODULE DEVELOPMENT UNDERSTAND ALL THE PREREQUISITES THROUGHLY
    • Drupal DB Schema is the most important fundamental - Most importantly, understand: - how content/comments are stored - how taxonomy is stored - how users/ACL is stored
    • you can't escape the hook Drupal has hooks for everything You can use hooks for: - CRUD operations - modifying anything(almost) at runtime - path/routes definitions - cron tasks, forms, schema definitions - and much much more...
    • and do I need to say - That you should know: - PHP - Bsic RDBMS concepts & SQL - Good Programming Style - Software Design Skills - learn that from Drupal ;)
    • so you want to code a new module Let's ask a few questions
    • Question #1 Is there are a contributed module that has the functionality I need? If Yes, use it. PERIOD.
    • Question #2 Is there any contributed module that does something similar to I need? If yes, use it, switch off the other functions, if possible
    • Question #3 Can I adapt any contributed module to do what I need? If yes, adapt it.
    • code your modules when you need to DON'T FORCE A DONKEY TO RUN A DERBY NEITHER FORCE A STALLION TO PULL A CART
    • If you need a new content type CCK will save you lot of time
    • with CCK, use VIEWS a simplified Crystal Reports for Drupal.
    • when writing modules, you will be... - Creating Forms - Receiving input - Doing SQL stuff - Outputing strings - containing text, html and other content
    • Learn and understand Form API Form API has lot of benifits - Define forms in PHP syntax - Drupal will generate correct HTML - Makes form aterable at runtime - Makes programatic submission possible
    • filter out that evil input with check_plain($string) makes sure $string is plain text and filters out those clever scripts and malicious html
    • It's a full family
        • filter_xss()
        • check_markup()
        • check_url
        • valid_url()
        • valid_email()
    • Drupal has a very powerfull input filter system. LEARN IT – USE IT No Excuses
    • Learn to construct good SQL. PERIOD. Time to go back to basic RDBMS books
    • BAD SQL in drupal
        • $result = db_query(”SELECT *
        • FROM {node}
        • WHERE
        • uid = $uid”);
    • and good SQL
        • $result = db_query(”SELECT *
        • FROM {node}
        • WHERE
        • uid = %d”, $uid);
    • printf style converstion specifications
        • %d = integer
        • $f = float
        • '%s' = sting note the quotes
        • %b = binary data
        • %% = percent sign
    • avoid queries in loops asdasd
        • <?php
        • while (some condition) {
        • $res = db_query(”SELECT * FROM
        • {table} WHERE
        • something = something”);
        • }
        • ?>
        • sometimes can cost just too much!
        • Tip: See if you can use map() function
    • beware of QUERY HELL
      • In some.module
      • <?php
      • $someone = user_load(array('uid' => $uid));
      • call_some_function($uid = $someone->uid);
      • ?>
      • and then
      • <?php
      • function call_some_function($uid){
        • $someone = user_load(array('uid'=>$uid));
        • }
      • ?>
      Reloading user again
    • modules and html REMEMBER Don't output HTML directly from modules BUT DON'T MAKE IT A RELIGION
    • Take a look at
        • blog_user_page()
      • Gerenrates HTML directly
      • LEARN FROM IT
    • one more tip NEVER NEVER NEVER use print statemets from inside function AJAX callbacks are exceptions but don't forget to exit() after print
    • THEMES - Learn and be strong at - HTML/CSS - Javascript/jQuery - Basic graphic design - use GIMP, Inkscape - understand difference between svn and png
    • always use PHPTemplate - Default theme engine since v4.7 - Simple to learn and easy to use - Made for Drupal, by Drupal [people] - Uses our own PHP for templating - No new language to learn (die smarty die)
    • use some base theme - well tested - basic stuff is ready - some even have a framework(zen) - you can use zen, framework, base, clean, igniter, etc etc,
    • do you have a separate designer? - Ask him to - take a look at Drupal generated HTML - learn the id/classes generated by Drupal - learn basics of PHP and Drupal FireBug can help here. http://getfirebug.com
    • avoid complex logic in tpl.php - Templates are for html not for logic - Remeber: - no SQL in templates - no complex logic in templates - on basic branching and looping more than 2 levels of nesting is ALARM ALARM SITUATION
    • Other useful stuff - Follow coding standards - coder module can help - its has other tons of features - use devel module - to profile queries - inspect redirects - generate test data/users/taxonomy - debug themes(drupal 6) - and more
    • drush – drupal swiss army knife - drush = drupal shell - unix scripting interface to drupal - API to build command line tools - a package manager, SQL Tools and ToolBox - Build your own tools and utilities
    • there is a lot left to cover Let that be some other time
    • Thank You - any questions? ?