If you can't read please download the document
Upload
manugoel2003
View
27.862
Download
0
Embed Size (px)
Citation preview
DRUPAL
BEST
PRACTICES
We are going to cover...
Drupal Best practices for
Development Environment
Module Development
Theme Development
Other stuff
Installation
Always use the latest CVS code
Not necessarily the HEAD version
Geting Drupal from CVS
$ cvs -d:pserver:anonymous:[email protected]:/cvs/drupal checkout -r DRUPAL-5 -d mysite drupal
http://drupal.org/node/93966
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
Now updates are a snap
$ cvs update -dP
This gets any updates to the core and the modules for the installed version
Updating to new Drupal version
Be sure that contibuted modules have been ported to the new version
$ cvs update -r DRUPAL-5-2 -dP
Revision Control you project
Subversion users
$ cd mysite
$ svn import /path/to/svn/repository
Bazaar users
$ cd mysite
$ bzr init
YOU CANNOT USE CVS HERE
Best Practices so far
Get the latest version from CVS
Check for updates before going further
Get the needed contributed modules from CVS
Have your own revision control system in place
You do not own Drupal CVS repository
Update(CVS) periodically to get latest fixes
Don't even try using CVS
Module Development
UNDERSTANT
ALL
PREQUISITES
VERY
THOUROUGHLY
Make sure you understand
Drupal's database schema
Just to give you a glimpse
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
And obiviously
You should know
PHP
SQL
Good programming style
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?
`
Code you own modules when needed
DO NOT FORCE
A DONKEY
RUN A DERBY
NEITHER FORCE
A STALLION
TO PULL A CART
If it is a Node Module
Try to use
Content
Construction
Kit
if possible...
With CCK
Use
VIEWS
Views module provides creating custom views of the node related data and other data as well.
While writing module
You will be
Creating Forms
Recieving input
Doing SQL stuff
Oupting Stings
containing Text, HTML and other content
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
Makes programatic submission possible
Convention over Configuration
Use Form API conventions
Validate
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.
Othe use full functions
filter_xss()
check_markup()
check_url
valid_url()
valid_email()
Drupal has a very powerfull input filter syetem
LEARN IT
USE IT
No Excuses
SQL
CONSTRUCT
GOOD
QUERIES
BAD SQL...
$result = db_query(SELECT *
FROM {node}
WHERE
uid = $uid);
Good SQL
$result = db_query(SELECT *
FROM {node}
WHERE
uid = %d, $uid);
printf style convervsion specs
%d = integer
$f = float
'%s' = sting
%b = binary data
%% = percent sign
Avoid queries in loop
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
Modules and HTML
MODULE != HTML
Never output html directly from module functions
BUT DON'T MAKE IT A RELIGION
Example of Module + HTML
blog_user_page()
Generates HTML directly
Learn from it
One tip
Never
Never
Never
use print statement from inside functions
Themes
You MUST be strong in
HTML
CSS
JavaScript
jQuery
Theme engines
Available theme engines
PHPTemplate
Zengine psedo theme theme engine pased on PHPTemplate
Smarty
PHPTAL
Xtemplate DEPRECATED
Pure PHP themes
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
TPL Magic
page.tpl.php
node.tpl.php
comment.tpl.php
block.tpl.php
box.tpl.php
etc etc
Learn the variables available to tpl
$head$styles$scripts$head_title$is_front$footer......$node$links$posted$$page.........page.tpl.php
node.tpl.php
Override anything themeable
theme_pager()
phptemplate_pager()
Rule of Thumb is
theme('pager');
theme-name_pager();
theme-engine_pager();
theme_pager();
Blocks/Regions are good
Blocks are places where chunks of UI GO
Called regions in developer language
Called blocks user language
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')
);
}
What we did not cover
Upgrade and Maintenance
Localization and Internationalization
Deployment practices
But you know where to go
www.drupal.org
http://groups.drupal.org
http://lists.drupal.org
and off course
www.Google.com
Thank You for your time
?
Mir NazimXensoft [email protected]
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamalla
Toinen jsennystaso
Kolmas jsennystaso
Neljs jsennystaso
Viides jsennystaso
Kuudes jsennystaso
Seitsems jsennystaso
Kahdeksas jsennystaso
Yhdekss jsennystaso