Configuring Eclipse
This describes how to configure Eclipse to play nicely with Drupal.
You will need to configure either PHP Development Tools (PDT), or PHPeclipse, depending on what you have installed. In addition, you should configure both Web Development Tools and Drupal friendly CVS settings.
For either editor
Make the following changes under Window -> Preferences (Eclipse -> Preferences on Mac)
- In the left-hand menu click on General -> Editors -> Text Editors
- Check 'Insert spaces for tabs'
For PHP Development Tools (PDT) - PHP editing
This is the official Eclipse project developed by Zend at http://www.eclipse.org/pdt/
We need to ensure that tab/indent inserts two spaces, and also that .inc, .module, .engine, .theme and .install files are recognized as PHP files.
Make the following changes under Window -> Preferences (Eclipse -> Preferences on Mac)
-
Expand the left-hand menu to General -> Content Types
- Under "Content types" on the right, click Text -> PHP Content Type
- Add the *.engine, *.theme, *.install, *.inc, *.module and *.test file types
- In the left-hand menu click on PHP -> Formatter
- Set 'Tab policy' to 'Spaces'
- Set 'Indentation size' to 2
For PHPeclipse - PHP editing
The community developer project is at http://www.phpeclipse.net/
We need to ensure that tab/indent inserts two spaces, and also that .inc, .module, .engine, .theme and .install files are recognised as PHP files.
Make the following changes under Window -> Preferences (Eclipse -> Preferences on Mac)
-
Expand the left-hand menu to General -> Content Types
- Under "Content types" on the right, click Text -> PHP Source File
- Add the *.engine, *.theme, *.install, *.inc, and *.module file types
- In the left-hand menu click on PHPeclipse -> PHP
- In the Typing tab, make sure the 'Insert Spaces for Tab' setting is checked
- In the Appearance tab, it is recommended that you leave the 'Displayed tab width' at 4, so it is easier to spot if any (actual) tabs have snuck in
- In the left-hand menu click on PHPeclipse -> PHP -> Formatter
- In the Style tab, enter 2 for 'Number of spaces representing a tab'
- 'Compact Assignment' and 'Indentation is represented by a tab' should both be unchecked
For Eclipse Web Tools - CSS, JS, XML and (X)HTML editing
This is used in addition to the PDE and PHPeclipse projects and deals with web format files.
Make the following changes under Window -> Preferences
- Expand the left-hand menu to Web and XML -> CSS Files -> CSS Source
- Select 'Indent using spaces'
- Set 'Intentation size' to 2
-
Expand the left-hand menu to Web and XML -> Javascript Files -> Javascript Source
- Select 'Indent using spaces'
- Set 'Intentation size' to 2
-
Expand the left-hand menu to Web and XML -> HTML Files -> HTML Source
- Select 'Indent using spaces'
- Set 'Intentation size' to 2
-
Expand the left-hand menu to Web and XML -> XML Files -> XML Source
- Select 'Indent using spaces'
- Set 'Intentation size' to 2
-
If you use XTemplate: expand the left-hand menu to General -> Content Types -> Text -> HTML
- Add the *.xtmpl file type
For Drupal CVS friendly patch creation
You should only need to set these if you are use Windows. These settings ensure that if you upload files to Drupal.org, or create patches to upload they are in the standardized format (UTF-8, Unix line endings, and CVS -kkv mode).
Make the following changes under Window -> Preferences
- Expand the left-hand menu to General ->Workspace
- Set 'Text file encoding' to 'UTF-8'
- Set 'New text file line delimiter' to 'Unix'
- Expand the left-hand menu to Team -> CVS
- Click on the Files and Folders tab
- Set the 'Default text mode' dropdown to "ASCII with keyword expansion (-kkv)"
- Disable the 'Convert text files to use platform line
ending' checkbox
See also
Eclipse IDE Setup for debugging
Eclipse and CVS
IBM DeveloperWorks article on setting up Eclipse + Drupal

A while back there was
A while back there was someone on the dev list asking Eclipse users to set the default text mode to -kkv. Apparently, this keeps the patches you create from breaking the tags on drupal and other cvs repositories. To make this change:
Window > Preferences > Navigate to Team > CVS
Click on the Files and Folders tab and set the "Default text mode" dropdown to "ASCII with keyword expansion (-kkv)
Also: I'm on windows, so after creating a new project I double check that the default encoding is Unix friendly:
Right click on the project > Properties > Info
Text File encoding should be UTF-8 (not US-ASCII).
New text file line delimeter should be Unix (not Windows).
--------------------
Sean B. Fuller
www.seanbfuller.com
www.tractiv.com
Set default encoding to UTF8 and the line delimiter
To permanently set default encoding to UTF8 and the line delimiter to LF, go to
Window -> Preferences -> General -> Workspace
and select UTF-8 as Text file encoding and Unix as New text file line delimiter.
Thomas (Webbredaktören)
a little confusing
The description of the paths to get to settings is a little confusing because it treats the preference menu hierarchy and tabs and buttons all the same. This is how I would phrase it:
-------------
Make the following changes in the preference dialog under Window -> Preferences:
General -> Content Types
Under Content Types, Text -> PHP Source File
Add the *.engine, *.theme and *.install file types
If they are not already there add the *.inc and *.module file types too
PHPeclipse -> PHP
In the Typing tab, Select (check) the 'Insert Spaces for Tab' setting
PHPeclipse -> PHP -> Formatter
In the Style tab, Enter 2 for 'Number of spaces representing a tab'
'Compact Assignment' should be unchecked
PHPeclipse -> PHP
In the appearance tab,
It is reccommended that you leave the 'Displayed tab width' at 4, so it is easier to spot if any (actual) tabs have sneaked in.
-------
would have made my life easier anyways...
Revised preferences for PDT
I just upgraded to the PDT All-In-One, .07 RC3. Here is a clean list of the preferences. If someone wants to confirm that I didn't miss anything, perhaps a moderator-type could promote this list into the page?
After you have it installed, go to Windows -> Preferences and make the following changes:
1. Content Types
2. Tab formatting for PHP
3. Tab formatting for CSS
4. Tab formatting for JavaScript
5. Tab formatting for HTML
6. Tab formatting for XML
7. Make it Unix-friendly
8. Set default text mode to -kkv
This keeps the patches you create from breaking the tags on drupal and other cvs repositories. To make this change:
I've heard reports that they are some issues with tabs, but that was a while ago and I haven't heard anything since. All of the above settings seem to work fine. I tested this configuration and pulled the output into word and turned on formatting marks and everything looked correct.
9. Tabulators
I'm not sure about this one. It seems to work the same either way:
--------------------
Sean B. Fuller
www.seanbfuller.com
www.tractiv.com
PDT All-in-one version 1.0
I've just installed the PDT all-in-one version 1.0 and it seems to be working. The preferences checklist that I posted above worked fine for this official release, as well.
So far, the only thing I've noticed is that the validator gets confused on lines where you have complex sql queries. (devel and views are the two I noticed having errors on code that seems fine).
Latest Version
The latest version seems to have this fixed.
Folks, be sure to install the latest stable all-in-one version from the eclipse site ( http://www.eclipse.org/pdt/ ) and not zend.com because that version is out of date and still contains this bug (plus many others).
You will save yourself lots of grief. Yes, I learned that the hard way.
Look for the following version or later:
Eclipse IDE 3.3.0v20070625
PDT version 1.0.0.v20070816
I just want to point out that obviously, the last part of the version number is the date it was built on, and that since this is a very new project each new update brings many key bug fixes.
Also, on Mac OS X
Look directly under Preferences in the "Eclipse" menu (for these options, not under Window).
benjamin, Agaric Design Collective
FYI
X-reference back to Setting up Eclipse for realtime debugging (Zend) ... because it's a really cool page.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/