Best Practises For Drupal Maintenance

Robert Castelo, Code Positive Ltd.

If You’re In Charge Of A Project

Get A Good Team
• Developer • Themer • Designer • Configuration(er)

How To Evaluate Candidates?

Look At Involvement user account See: • modules • themes • documentation • years involved

Check Work Quality

Coder module tests for compliance with Drupal coding style

Client Testimonials
What do heads of other Drupal projects say about the candidate?

If You’re Configuring A Website

Modules & Themes

modules & themes directories are for core Drupal - NEVER install into them

Sites Directory
Every file you add to your Drupal site should live in the ‘sites’ directory. ✔ This makes it easier to keep your site updated.

Sites Default
✔ ✔ ✔

sites/default/modules - used by a single site. Recommended in most cases.

Sites All
✔ ✔

Installed modules used by multiple sites. Only recommended if all sites use the same code base.

Modules Sub-directories
✔ ✔

Modules can be separated into contrib and custom (internal development) for easier maintenance

Update Status
Keep up to date (Drupal 6 & 7 built in) Drupal 5:

If You’re Developing A Site

Separate Logic / Presentation



• • •
Easier to Code Code is Re-usable Easier to Maintain

Rapid Development & Less Maintenance
• •
Less Code To Create Less Code to Maintain

Avoid Spaghetti Code
• •

Standard API Strict Formatting

Code Legibility

Give functions and variables meaningful labels

Code Documentation

Well documented code improves maintainability

API Module
Convert documentation in code into web pages

Quick Tips
✔ t(‘Example text’) Enable interface text to be translated ✔ l() and url() for links <? ✔ <?php Don’t add ?> at end of file

Local Module
Create a Local module to add small custom tweeks

Views In Module
Store your custom Views in a module

• improves performance • easier to move (dev to live) • puts views in version control managing-drupal-views-the-proper-way

Keep PHP Out Of The Database
• Easier to maintain code • Easier to find • Easier to upgrade • Under version control
If you must put PHP in a block, view, node.... put code in a function in your Local module then just call the function

Use Version Control
Enables code to be rolled back, and teams to work on same code CVS SVN GIT ...

Maintenance Tools

Devel Module
Essential development tools

Devel Module
Also good for theme building

Coder Module
Automatic validation of module & themes

Simple Test
Automated tests of your code check new code doesn’t break the old

Masquerade Module
Log in as a different user, test roles


Image Credits

Sign up to vote on this title
UsefulNot useful