Development Environment

Want to help the Drupal Community by donating some development effort?  You will learn lots about the Drupal platform and at the same time help make Drupal better for everyone!

Go to http://drupal.org/community-initiatives/drupal-core to learn more.

For novices, try working a patch on drupal.org/patch/novice.

 

 

Acquia Stack

The Acquia Stack is a bundling of PHP, MySQL, and Apache, based on XAMP, made spefically for doing Drupal development.  The Acquia Stack simplifies the installation and configuration of a Drupal capable environment.

After installing the Acquia Stack, be sure to configure the Apache configuration file, located in the a directory called "conf", which is located under the main Apache directory.  Be sure to configure is the Virtual Hosts section of httpd.conf, so that Apache can service your sites.

If running on Windows, be sure to modify the "hosts" file located in  \Windows\System32\drivers\etc.  Ad any host names and appropriate IPs that you would like to use, and comment out the line:"::1  localhost" by placing a "#" in at the beginning of the line.  Commenting out this line is important, otherwise you may get the dreaded "HTTP Request Status" error on the Drupal Status Report.

By default, the Acquia Drupal Stack ships with the Apache port set to 8082. For many users, it makes sense to change this to port 80, by modifying the http.conf file, with the directive "Listen 80" rather than "Listen 8082". This way you can type "localhost" into your browsers address bar, rather than "localhost:8082". You should also change the ServerName directive to "ServerName 127.0.0.1:80".

Admin Menu

The Admin Menu Module adds a dropdown menu for administrative users, which is much faster than going to the pages under the "admin" path.

The default font of the admin menu is a pretty small, you may want to increase it by putting the following CSS rule in your stylesheet:

body #admin-menu {font-size: 11px}


Advanced help

Install the Advanced Help module to get help with certain modules that have advanced help available.

 

Automated Testing

 

The simpletest module runs a series of automated tests and alerts you if there is an error.

Drupal 7 is the first version of Drupal being developed using an automated test process.

 

 

Commonly Used Drupal API Functions

dbquery

Use dbquery to run a query in the Drupal database.


The first parameter is the query as a text string.  Then a variable number of parameters are permitted, each being a variable that is substituted into the query.  This variable substitution is necessary to avoid SQL injection attacks.

For example:

dbquery("SELECT * FROM node INNERJOIN content_type_profile ON node.nid = content_type_profile.nid WHERE node.nid = %d", $nid);
$start = time();
$query = "SELECT * FROM node INNERJOIN content_type_profile ON node.nid = content_type_profile.nid WHERE node.nid = %d";
$result = dbquery($query, $nid);
//dpm($query); //Used for debugging
//dpm($result); //Used for debugging
$duration = time() - $start;
watchdog('gs_custom', 'Search query took '. $duration .'ms');
if ($result) {
      while ($row = db_fetch_object($result)) {
        $status = $row->status;
        // Do something...
      }
}

Available Substitution Placeholder:

%s => String
%d => Integer
%b => Binary
%f => Float
%% => Insert a literal %


Devel Module

The Devel Module is actually a suite of modules designed to assist both module and theme developers. Enable the Devel Module Block to control Devel Module settings.

Theme Developer

This module places markers in the DOM, and is designed to work with FireFox FireBug.  Once activated, the module allows theme developers to click on page elements to determine which templates and theme functions effected the element.

Generate Content

Create test content including nodes, comments, terms, users etc.

Node Access Summary

View the node access log for each node on a page.

Performance Logging

View and log performance stats.

Drupal Module Page: http://drupal.org/project/devel

 

 

 

Drush

 

Drush stands for Drupal Shell, and is often referred to as the "swiss army knife” for Drupal developers.  With the latest release ("Drush 2") there is no longer a contributed module. This makes Drush 2 independant of Drupal, whereby functionality is available from the operating system (e.g. Linux) command line.  Drush 2 uses an autodetect mechanism, whereby Drush 2 is able to determine if you are in a directory associated with a Drupal installation, with commands directed to that Drupal installation.

Before upgrading modules with Drush, be sure to back up the Drupal database and the Drupal directory.

A related module is the Drush System Manager, which provides the ability to list variables, cck field, and view information from the command line.  These output listings can then be checked into version control, so that changes made to content types and views can be tracked.  See http://drupal.org/project/drush_sm.

drush help => List drush commands

drush dl views => Download the Views module

drush enable views => Enable the Views module

drush update => Update all contributed modules

drush updatedb => Update database (same as update.php)

drush cache clear => Clear caches

drush cron => Run cron

drush statusmodules => generate list of module info

Eclipse IDE

Eclipse is an IDE (Integrated Development Environment) written in Java, orignally funded by IBM.  Originally targetted as an IDE for Java development, it now support other languages, including C++ and PHP.

Eclipse PDT is the PHP development plug-in for the Eclipse IDE.   To get Eclipse with PDT already installed,  download the all-in-one Eclipse/PHP distrubution from http://www.eclipse.org/downloads and unzip. Make sure to keep your version of PDT up to date by going to Check for Updates under the Help menu.  To learn more, see http://www.eclipse.org/pdt.

Zen Studio is a distribution of Eclipse/PDT specifically for PHP programmers.  When you install Zen Studio, it has a 30 day evaluation, but reverts to a "Personal Edition" after the 30 days evaluation, unless a license fee is paid.  To learn more, see http://www.zend.com/en/products/studio.

CVS Checkout

To checkout from CVS, open the CVS Repository Exploring perspective, by clicking the yellow plus sign and picking Other... in the top left tab that lists current perspectives.

Then right click in the CVS Repositories Window and select New/Repository Location...  and enter (for Drupal) the following:

Connection type: pserver

User: anonymous

Password: anonymous

Host: cvs.drupal.org

Repository path: /cvs/drupal

Default Editor Font

You may want to select a different default editor font, e.g. Verdana Regular 12 works nicely if you prefer larger type.  To set the default editor font, go to Preferences under the Window menu and pick General/Appearance/Colors and Fonts/Structured Text Editors/Edit.

Editing Remote Files Using FTP

Editing of remote files using FTP is possible using an Eclipse plug in called Remote Systems Explorer (RSE), which is part of the Eclipse Target Mangement Project.

To install Target Mangement, go to Install New Software...  under the Help menu.  The go and add the location:

http://download.eclipse.org/dsdp/tm/updates/3.0

and then check the box next to "TM and RSE 3.1.1" (or a newer version if one is available) and click Next to complete the install.

 

Shortcut Keys

F3 Open Declaraton, click F3 to navigate to the the function the cursor is currently on, also works for variables.  May not work on remote files.

Crtl-D Delete Line

Ctrl-E Recent file list

Ctrl-G Goto Line

Ctrl-M Maximize or Un-maximize the current view

Ctrl-N Make a new project or file

Ctrl-I Correct Indentation

Ctrl-J Incremental Search

Ctrl-Shift-F Format entire file

 

Ctrl-Space Autocomplete

Ctrl-F6 Switch Tabs

Ctrol-F8 Switch Perspectives

F11 Debug Ctrl+F11 Run

Ctrl-O Open outline of current file, quick way to navigate current file

Ctrl-E Easy navigatation to an open file

Ctrl-Q Go to last edit location in current file

Ctrl-Shift-R Open Resouce, quickly navigate to a specified file name

Ctrl-Shift-L List all hot keys

Alt + Up/Down Arrow

Move the row (or the entire selection) up or down in order  to rearrange code. Multiple rows may be selected and indentation is automatically corrected.

Using Eclipse for Drupal Projects

In the top right hand corner of the PHP Explorer, it is usually preferable to pick "Link with Editor", which tells Eclipse to highlight the file you are editing in the PHP Explorer.

Go to the Windows/Preferences/Content Types and then pick  from "Text/PHP Content Types" from the list, and add the following:

1.  *.module
2.  *.install

Xdebug

Ports

Run netstat to see which ports are in use, once with Eclipse running, and again after exiting Eclipse. The command is :C:\WINDOWS>netstat -an | find /i "listening". After closing Eclipse, port 9000 and 10000 should no longer be listed.

Firebug

Essential for theme development, Firebug is a FireFox plug-in that allows the theme develop to click on a page element and see the underlying HTML and CSS code.

 

 

Setup email in php.ini

It makes sense to configure your local development machine to have a working email configuration so that parts of the Drupal site being developed that have email functionality can be tested. If you are running locally on Windows, enter your email servers address into php.ini similar to the following example: [mail function] ; For Win32 only. SMTP = smtp.example.com smtp_port = 25