Eclipse eclipse logois a powerful open source IDE built on Java that has been around since 2001 and has become quite useful tool for PHP development, including Drupal. This post is meant to give some rationale on why to use this platform for Drupal development and get you oriented as soon as possible. With Eclipse, there is definitely a learning curve, but if you give it a chance I’ll think you’ll find it an indispensable resource for your toolbox.

Why Eclipse / PHP Development Tools (PDT)?
  • Open source – forever free
  • Multi-platform, have same experience on MacOS/Windows!
  • Code assist, including Drupal API functions, HTML markup and CSS attributes!
    • F3 to go right to function’s declaration!
  • Great SVN/CVS integration
    • Easily see which files have been modified, which files are new, committing/updating is easy
  • Function outline
    • Makes it easy to find functions defined in a module
  • IDEs keep projects organized
  • PHP syntax validation, easily find syntax errors in the file itself and PHP outline
 
Steps to Getting Up And Running

NOTE: I am running Eclipse on a Windows 7 box with XAMPP as my LAMP stack, but the instructions are basically the same for MacOS.
 
  1. Download and install Eclipse PDT
  2. Install Subclipse from Eclipse
  3. Configure Eclipse – this is where it gets tricky!
  4. Create a test project and try it out yourself
 
1.       Download and install Eclipse PDT
 
Eclipse is easier than ever with the PDT platform. Go to the Eclipse homepage and you will see a link for Eclipse for PHP Developers. What’s different about installing Eclipse is that it doesn’t have an install dialog, basically all you do is drop the eclipse folder anywhere on your machine, in Windows I put it in ‘Program Files’ and create a shortcut myself. When you first launch Eclipse, it will ask for your workspace, usually I recommend pointing to your www folder or htdocs.
 
2.       Install Subclipse from Eclipse
 
You will also probably want SVN integration and for that you will need to install Subclipse, view the installation instructions here. I will not go into full detail here but an important note is that Eclipse allows you to install plugins from the IDE itself, via the ‘Install New Software…’ menu item from the help screen. Basically this involves giving Eclipse the download URL and selecting what to install. There is an optional driver, I think for Java I would ignore that - as it usually fails when I try to install Subclipse and it’s not needed.
 
eclipse subsclipse screenshot
 
3.       Configure Eclipse – this is where it gets tricky!
 
Almost all of the instructions below involve changing settings under the Window - Preferences menu item. If you spend any time with Eclipse, you will need to get very familiar with the preferences dialog. Some of these instructions are optional but I strongly recommend all of them for Drupal development.
 
  • Select a workspace
    • This is the first thing you are prompted when launching Eclipse, I select the XAMPP htdocs folder (or WAMP www, etc) and make it always start with this workspace
  • Select PHP perspective (if not already selected)
    • If you ever don’t see PHP explorer you might be in the wrong perspective, in which case select Window..Open Perspective..PHP
  • Adjust PHP settings
    • In preferences, under PHP..PHP Executables you will need to add the paths to your executable path and php ini path.
  • Turn off validation
    • In preferences, under validation I would uncheck all the validation because I find it to be too strict. If you have PHP errors those will still be shown in the PHP explorer.
  • Turn off ‘Enable auto activation’
    • ‘Auto activation’ will trigger code assist automatically and can REALLY slow things down, my advice is to disable this option and use ctrl+space to trigger auto assist as needed. You shouldn’t have to do this for PHP but for CSS/HTML/JavaScript.
    • In preferences, under Web..JavaScript..Editor..Content Assist unclick ‘Enable auto activation’
    • In preferences, under Web..HTML Files..Editor unclick ‘Automatically make suggestions’
  • Adjust Subclipsesettings
    • In preferences, under Team..SVN I wold change the ‘SVN interface’ client to ‘SVNKit’, this is not selected by default but I cannot get SVN to work with the default client.
    • In preferences, under Team..SVN..Menu Icons I would use ‘Subversive’
  • Convert tabs to spaces
    • Use 2 spaces for tabs according to Drupal coding standards
    • In preferences, under General..Editor..Text Editors change ‘Displayed tab width’ to 2
    • In preferences, under PHP..Code Style..Formatter change to spaces/2.
    • In preferences, under Web..CSS Files..Editor change to spaces/2.
    • In preferences, under Web..HTML Files..Editor change to spaces/2.
    • In preferences, under XML..XML Files..Editor change to spaces/2.
  • Add .moduleto PHP editor types
    • In preferences, under General..Content Types double click ‘Text’ and find the ‘PHP Content Type’. Add ‘.module’ and click OK, you will probably need to restart Eclipse for this change to take effect.
  • Enable line numbers
    • This really helps, in preferences under General..Editors..Text Editors click ‘Show line numbers’
  • Add PHP support
    • Sometimes a project does not automatically have PHP support, in which case you can right click a project in the PHP Explorer and under Configure select ‘Add PHP Support’
      • This sometimes occurs when you add a pre-existing project to the Eclipse workspace

 

eclipse preferences dialog screenshot

 
4.       Create a test project and try it out yourself
 
Right click in the PHP Explorer on the left side of the screen and click New..PHP Project to add a php project and start playing around! Also if you work off of SVN like we do you will normally add a new project by right clicking and selecting ‘Import..’, then select SVN and following that dialog to import an SVN project into your workspace.
 
In summary
 
If you have done any tire-kicking with Eclipse before but had trouble I hope the step 3 breakdown of configration settings helped. It took me a long time to find all these settings so I strongly suggest you read through that step before playing around with Eclipse.
 
Part of the problem with Eclipse is that the documentation is scattered and so it can be really difficult to get up and running quickly. I have talked to a number of people who tried Eclipse in the past and gave up. That being said, I implore you to try again because I believe you’ll find it a powerful platform once you get past the initial set of “secret handshakes.” Features like SVN integration, code assist and real-time PHP syntax validation have made Eclipse my favorite platform for Drupal development.
 
Additional References/Links:
 

 
Feedback? Comment below or reply at http://twitter.com/drupalninja.

      Additional Resources

Drupal Vs. Sharepoint

      | Mediacurrent Blog Post

An Inside Look at the Omega Theme

      | Mediacurrent Blog Post Free Drupal Whitepaper |

The Mobile Web and Drupal