Slideshare.net (beta)

 
Post to TwitterPost to Twitter
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 17 (more)

Drupal Best Practices

From manugoel2003, 2 years ago

Mir Nazim - Drupal Best Practices

7037 views  |  1 comment  |  16 favorites  |  450 downloads  |  6 embeds (Stats)
 

Categories

Add Category
 
 

Groups / Events

 
Embed
options

More Info

This slideshow is Public
Total Views: 7037
on Slideshare: 6350
from embeds: 687

Slideshow transcript

Slide 1: DRUPAL BEST PRACTICES

Slide 2: We are going to cover... Drupal Best practices for Development Environment ● Module Development ● Theme Development ● Other stuff ●

Slide 3: Installation Always use the latest CVS code Not necessarily the HEAD version

Slide 4: Geting Drupal from CVS $ cvs ­d :pserver:anonymous:anonymous @cvs.drupal.org:/cvs/drupal  checkout ­r DRUPAL­5 ­d  mysite drupal http://drupal.org/node/93966 

Slide 5: Getting contibuted modules $ cd mysite $ cvs checkout ­d modules/views ­r  DRUPAL­5  contributions/modules/views $ cvs checkout ­d modules/cck ­r  DRUPAL­5 contributions/modules/cck http://drupal.org/node/93966 

Slide 6: Now updates are a snap $ cvs update ­dP This gets any updates to the core and the modules for the installed version

Slide 7: Updating to new Drupal version $ cvs update ­r DRUPAL­5­2 ­dP Be sure that contibuted modules have been ported to the new version

Slide 8: Revision Control you project Subversion users $ cd mysite  $ svn import /path/to/svn/repository Bazaar users $ cd mysite  $ bzr init YO U C A N N O T U SE C V S H ERE

Slide 9: Best Practices so far 1) Get the latest version from CVS 2) Check for updates before going further 3) Get the needed contributed modules from CVS 4) Have your own revision control system in place You do not own Drupal CVS repository ● 5) Update(CVS) periodically to get latest fixes 6) Don't even try using CVS

Slide 10: Module Development UNDERSTANT ALL PREQUISITES VERY THOUROUGHLY

Slide 11: Make sure you understand Drupal's database schema Just to give you a glimpse

Slide 13: Understand hooks Drupal has hooks for every thing CRUD operations ● Modiying into user data at runtime ● Modifying almost everything at runtime ● Path definitions (rails is a bit late here) ● And much much more ●

Slide 14: And obiviously You should know PHP ● SQL ● Good programming style ●

Slide 15: Ask questions Is the functionality already available in any contributed module? Is there a contributed module that does something similar that I need? Can I adapt some existing module to do what I need to do? `

Slide 16: Code you own modules when needed DO NOT FORCE A DONKEY RUN A DERBY NEITHER FORCE A STALLION

Slide 17: If it is a Node Module Try to use Content Construction Kit if p o s s ib le . . .

Slide 18: With CCK Use VIEWS Views module provides creating custom views of the node related data and other data as well.

Slide 19: While writing module You will be Creating Forms ● Recieving input ● Doing SQL stuff ● Oupting Stings ● containing Text, HTML and other content ●

Slide 20: Use the Form API Form API has benifits Define forms in php syntax ● Drupal will generate the HTML for ● you Dupal takes care proper html ● Makes form alterable at the runtime ● by other modules ●

Slide 21: Convention over Configuration Use Form API conventions <?php function module_form(){    //form definitions } ?>

Slide 22: Validate <?php function module_form_validate ($form_id, $form_values) { // do the validation // set the errors } function module_form_submit ($form_id, $form_values) { // perform submit } ?>

Slide 23: Input validation Make sure you check all text only fields with check_plain() It checks for malicious contents in like clever scripts, specially HTML etc.

Slide 24: Othe use full functions filter_xss() check_markup() check_url valid_url() valid_email()

Slide 25: Drupal has a very powerfull input filter syetem LEARN IT USE IT N o E x cu se s

Slide 26: SQL CONSTRUCT GOOD QUERIES

Slide 27: BAD SQL... $result = db_query(”SELECT *              FROM {node}              WHERE               uid = $uid”);

Slide 28: Good SQL $result = db_query(”SELECT *              FROM {node}              WHERE               uid = %d”, $uid);

Slide 29: printf style convervsion specs    %d = integer    $f = float  '%s' = sting    %b = binary data    %% = percent sign

Slide 30: Avoid queries in loop <?php while (some condition)  {     $res = db_query(”SELECT * FROM             {table} WHERE              something = something”); } ?>

Slide 31: Bewre of QUERY HELL In some-page.tpl.php  $someone = user_load(array('uid' => $uid));  call_some_function($uid = $user­>uid); function call_some_function($uid){   $someone = user_load(array('uid'=>$uid)); } Reloading user again

Slide 32: Modules and HTML MODULE != HTML Never output html directly from module functions BUT DON'T MAKE IT A RELIGION

Slide 33: Example of Module + HTML blog_user_page()  Generates HTML directly Learn from it

Slide 34: One tip Never Never Never use print statement from inside functions

Slide 35: Themes You MUST be strong in HTML ● CSS ● JavaScript ● jQuery ●

Slide 36: Theme engines Available theme engines PHPTemplate ● Zengine psedo theme theme engine pased on PHPTemplate ● Smarty ● PHPTAL ● Xtemplate DEPRECATED ●

Slide 37: PHPTemplate The default theme engine since v4.7 ● Simple to learn and use ● Built for Drupal ● Uses PHP for templating ● No new language to learn ● DIE SMARTY DIE ● Powerfull, but sometimes dangerous ●

Slide 38: TPL Magic page.tpl.php ● node.tpl.php ● comment.tpl.php ● block.tpl.php ● box.tpl.php ● etc etc ●

Slide 39: Learn the variables available to tpl page.tpl.php node.tpl.php $head $node $styles $links $scripts $posted $head_title $$page $is_front ... $footer ... ... ... ...

Slide 40: Override anything themeable theme_pager() phptemplate_pager()

Slide 41: Rule of Thumb is theme('pager'); theme­name_pager(); theme­engine_pager(); theme_pager();

Slide 42: Blocks/Regions are good Blocks are places where chunks of UI ● GO Called ”regions” in developer ● language

Slide 44: defining regions function mytheme_regions() {   return array(        'left' => t('left sidebar'),        'right' => t('right sidebar'),        'content_top' => t('content top'),        'content_bottom' => t('content bottom'),        'header' => t('header'),        'footer' => t('footer')   ); }

Slide 45: What we did not cover Upgrade and Maintenance ● Localization and Internationalization ● Deployment practices ●

Slide 46: But you know where to go www.drupal.org  http://groups.drupal.org http://lists.drupal.org and off course www.Google.com 

Slide 47: ? Thank You for your time Mir Nazim Xensoft Labs www.xensoftlabs.com mirnazim@xensoftlabs.om