HELLO,  I  AM... <ul><li>Mir Nazim </li></ul><ul><li>Chief Architect @ iKraft Sofrware Pvt Ltd </li></ul><ul><li>Working o...
BEST PRACTICES FOR DRUPAL DEVELOPERS DrupalCamp India August 8/9/10, 2008 Dhirubhai Ambani Institute of Information & Comm...
We shall be covering -Best practices for - development environment - module development - theme development - some other s...
Get the source Start out with the CVS checkout ALWAYS ” CVS chekout instruction  are available on  http://drupal.org/handb...
Why use CVS version <ul><li>Single most important reason </li></ul><ul><li>EASY UPDATES </li></ul><ul><ul><li>$ cvs update...
TO NEW DRUPAL VERSION <ul><ul><li>$ cvs update -r DRUPAL-6-3 -dP </li></ul></ul><ul><ul><li>Be sure that contibuted module...
revision control your project -Even if: - it is a small project - only you are working on it - Take a pick - svn, bzr, git...
The Editor Wars - Komodo Edit/IDE  my favourite - Scribes on GNOME  my other favourite   - PHPEclipse or Eclipse PDT - Qun...
MODULE DEVELOPMENT UNDERSTAND ALL THE PREREQUISITES  THROUGHLY
Drupal DB Schema is the most important fundamental - Most importantly, understand: - how content/comments are stored - how...
you can't escape  the hook Drupal has hooks for everything You can use hooks for: - CRUD operations - modifying anything(a...
and do I need to say - That you should know: - PHP - Bsic RDBMS concepts & SQL - Good Programming Style - Software Design ...
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 f...
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...
Learn and understand Form API Form API has lot of benifits - Define forms in PHP syntax - Drupal will generate correct HTM...
filter out that evil input with check_plain($string) makes sure $string is plain text and filters out those clever scripts...
It's a full family <ul><ul><li>filter_xss() </li></ul></ul><ul><ul><li>check_markup() </li></ul></ul><ul><ul><li>check_url...
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 <ul><ul><li>$result = db_query(”SELECT * </li></ul></ul><ul><ul><li>FROM {node} </li></ul></ul><ul><ul>...
and good SQL <ul><ul><li>$result = db_query(”SELECT * </li></ul></ul><ul><ul><li>FROM {node} </li></ul></ul><ul><ul><li>WH...
printf style converstion specifications <ul><ul><li>%d = integer </li></ul></ul><ul><ul><li>$f = float </li></ul></ul><ul>...
avoid queries in loops asdasd  <ul><ul><li><?php </li></ul></ul><ul><ul><li>while (some condition)  { </li></ul></ul><ul><...
beware of QUERY HELL <ul><li>In some.module </li></ul><ul><li><?php </li></ul><ul><li>$someone = user_load(array('uid' => ...
modules and html REMEMBER Don't output HTML directly from modules BUT DON'T MAKE IT A RELIGION
Take a look at <ul><ul><li>blog_user_page()  </li></ul></ul><ul><li>Gerenrates HTML directly </li></ul><ul><li>LEARN FROM ...
one more tip NEVER NEVER NEVER use print statemets from inside function AJAX callbacks are exceptions but don't forget to ...
THEMES - Learn and be strong at - HTML/CSS - Javascript/jQuery - Basic graphic design - use GIMP, Inkscape -  understand d...
always use PHPTemplate - Default theme engine since v4.7 - Simple to learn and easy to use - Made for Drupal, by Drupal [p...
use some base theme - well tested - basic stuff is ready - some even have a framework(zen) - you can use zen, framework, b...
do you have a separate designer? - Ask him to  - take a look at Drupal generated HTML - learn the id/classes generated  by...
avoid complex logic in tpl.php - Templates are for html not for logic - Remeber: - no SQL in templates - no complex logic ...
Other useful stuff - Follow coding standards - coder module can help - its has other tons of features - use devel module -...
drush – drupal swiss army knife  - drush = drupal shell - unix scripting interface to drupal - API to build command line t...
there is a lot left to cover Let that be some other time
Thank You - any questions? ?
Upcoming SlideShare
Loading in...5
×

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

4,460

Published on

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

Published in: Technology, Business
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,460
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
215
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

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

  1. 1. HELLO, I AM... <ul><li>Mir Nazim </li></ul><ul><li>Chief Architect @ iKraft Sofrware Pvt Ltd </li></ul><ul><li>Working on PHP/Drupal & Python/Django </li></ul><ul><li>since past few years </li></ul><ul><li>email me - [email_address] </li></ul><ul><li>More at www.ikraftsoft.com </li></ul>
  2. 2. BEST PRACTICES FOR DRUPAL DEVELOPERS DrupalCamp India August 8/9/10, 2008 Dhirubhai Ambani Institute of Information & Communication Technology Gandhinagar, IN
  3. 3. We shall be covering -Best practices for - development environment - module development - theme development - some other stuff
  4. 4. Get the source Start out with the CVS checkout ALWAYS ” CVS chekout instruction are available on http://drupal.org/handbooks ”
  5. 5. Why use CVS version <ul><li>Single most important reason </li></ul><ul><li>EASY UPDATES </li></ul><ul><ul><li>$ cvs update -dP </li></ul></ul>
  6. 6. TO NEW DRUPAL VERSION <ul><ul><li>$ cvs update -r DRUPAL-6-3 -dP </li></ul></ul><ul><ul><li>Be sure that contibuted modules have been ported to the </li></ul></ul><ul><ul><li>new version </li></ul></ul>
  7. 7. 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!
  8. 8. 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? ;)
  9. 9. MODULE DEVELOPMENT UNDERSTAND ALL THE PREREQUISITES THROUGHLY
  10. 10. 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
  11. 11. 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...
  12. 12. 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 ;)
  13. 13. so you want to code a new module Let's ask a few questions
  14. 14. Question #1 Is there are a contributed module that has the functionality I need? If Yes, use it. PERIOD.
  15. 15. 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
  16. 16. Question #3 Can I adapt any contributed module to do what I need? If yes, adapt it.
  17. 17. code your modules when you need to DON'T FORCE A DONKEY TO RUN A DERBY NEITHER FORCE A STALLION TO PULL A CART
  18. 18. If you need a new content type CCK will save you lot of time
  19. 19. with CCK, use VIEWS a simplified Crystal Reports for Drupal.
  20. 20. when writing modules, you will be... - Creating Forms - Receiving input - Doing SQL stuff - Outputing strings - containing text, html and other content
  21. 21. 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
  22. 22. filter out that evil input with check_plain($string) makes sure $string is plain text and filters out those clever scripts and malicious html
  23. 23. It's a full family <ul><ul><li>filter_xss() </li></ul></ul><ul><ul><li>check_markup() </li></ul></ul><ul><ul><li>check_url </li></ul></ul><ul><ul><li>valid_url() </li></ul></ul><ul><ul><li>valid_email() </li></ul></ul>
  24. 24. Drupal has a very powerfull input filter system. LEARN IT – USE IT No Excuses
  25. 25. Learn to construct good SQL. PERIOD. Time to go back to basic RDBMS books
  26. 26. BAD SQL in drupal <ul><ul><li>$result = db_query(”SELECT * </li></ul></ul><ul><ul><li>FROM {node} </li></ul></ul><ul><ul><li>WHERE </li></ul></ul><ul><ul><li>uid = $uid”); </li></ul></ul>
  27. 27. and good SQL <ul><ul><li>$result = db_query(”SELECT * </li></ul></ul><ul><ul><li>FROM {node} </li></ul></ul><ul><ul><li>WHERE </li></ul></ul><ul><ul><li>uid = %d”, $uid); </li></ul></ul>
  28. 28. printf style converstion specifications <ul><ul><li>%d = integer </li></ul></ul><ul><ul><li>$f = float </li></ul></ul><ul><ul><li>'%s' = sting note the quotes </li></ul></ul><ul><ul><li>%b = binary data </li></ul></ul><ul><ul><li>%% = percent sign </li></ul></ul>
  29. 29. avoid queries in loops asdasd <ul><ul><li><?php </li></ul></ul><ul><ul><li>while (some condition) { </li></ul></ul><ul><ul><li>$res = db_query(”SELECT * FROM </li></ul></ul><ul><ul><li>{table} WHERE </li></ul></ul><ul><ul><li>something = something”); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>?> </li></ul></ul><ul><ul><li>sometimes can cost just too much! </li></ul></ul><ul><ul><li>Tip: See if you can use map() function </li></ul></ul>
  30. 30. beware of QUERY HELL <ul><li>In some.module </li></ul><ul><li><?php </li></ul><ul><li>$someone = user_load(array('uid' => $uid)); </li></ul><ul><li>call_some_function($uid = $someone->uid); </li></ul><ul><li>?> </li></ul><ul><li>and then </li></ul><ul><li><?php </li></ul><ul><li>function call_some_function($uid){ </li></ul><ul><ul><li>$someone = user_load(array('uid'=>$uid)); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>?> </li></ul>Reloading user again
  31. 31. modules and html REMEMBER Don't output HTML directly from modules BUT DON'T MAKE IT A RELIGION
  32. 32. Take a look at <ul><ul><li>blog_user_page() </li></ul></ul><ul><li>Gerenrates HTML directly </li></ul><ul><li>LEARN FROM IT </li></ul>
  33. 33. one more tip NEVER NEVER NEVER use print statemets from inside function AJAX callbacks are exceptions but don't forget to exit() after print
  34. 34. THEMES - Learn and be strong at - HTML/CSS - Javascript/jQuery - Basic graphic design - use GIMP, Inkscape - understand difference between svn and png
  35. 35. 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)
  36. 36. 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,
  37. 37. 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
  38. 38. 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
  39. 39. 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
  40. 40. 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
  41. 41. there is a lot left to cover Let that be some other time
  42. 42. Thank You - any questions? ?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×