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)

  1. 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)

  1. 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
  2. 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)

  1. 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
  2. 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
  3. 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

  1. Expand the left-hand menu to Web and XML -> CSS Files -> CSS Source
    • Select 'Indent using spaces'
    • Set 'Intentation size' to 2
  2. Expand the left-hand menu to Web and XML -> Javascript Files -> Javascript Source
    • Select 'Indent using spaces'
    • Set 'Intentation size' to 2
  3. Expand the left-hand menu to Web and XML -> HTML Files -> HTML Source
    • Select 'Indent using spaces'
    • Set 'Intentation size' to 2
  4. Expand the left-hand menu to Web and XML -> XML Files -> XML Source
    • Select 'Indent using spaces'
    • Set 'Intentation size' to 2
  5. 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

  1. Expand the left-hand menu to General ->Workspace
    • Set 'Text file encoding' to 'UTF-8'
    • Set 'New text file line delimiter' to 'Unix'
  2. 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

Sean B Fuller - October 12, 2006 - 15:52

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

TBarregren - December 22, 2006 - 10:36

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

andrewlevine - January 5, 2007 - 06:04

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

Sean B Fuller - May 10, 2007 - 15:00

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

  1. Expand the left-hand menu to General -> Content Types
  2. Under "Content types" on the right, click Text -> PHP Source File
  3. Add the *.engine, *.theme, *.install, *.inc, and *.module file types

2. Tab formatting for PHP

  1. Expand the left-hand menu to PHP -> Formatter
  2. Check the "Indent using spaces" radio button.
  3. Change the indent size to 2.

3. Tab formatting for CSS

  1. Expand the left-hand menu to Web and XML -> CSS Files -> CSS Source
  2. Select 'Indent using spaces'
  3. Set 'Intentation size' to 2

4. Tab formatting for JavaScript

  1. Expand the left-hand menu to Web and XML -> Javascript Files -> Javascript Source
  2. Select 'Indent using spaces'
  3. Set 'Intentation size' to 2

5. Tab formatting for HTML

  1. Expand the left-hand menu to Web and XML -> HTML Files -> HTML Source
  2. Select 'Indent using spaces'
  3. Set 'Intentation size' to 2

6. Tab formatting for XML

  1. Expand the left-hand menu to Web and XML -> XML Files -> XML Source
  2. Select 'Indent using spaces'
  3. Set 'Intentation size' to 2

7. Make it Unix-friendly

  1. Expand the left-hand menu to General ->Workspace
  2. Text File encoding should be UTF-8
  3. New text file line delimeter should be Unix

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:

  1. Expand the left-hand menu to Team -> CVS
  2. Click on the Files and Folders tab
  3. set the "Default text mode" dropdown to "ASCII with keyword expansion (-kkv)"

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:

  1. Expand the left-hand menu to PHP -> Editor -> Typing
  2. Check the "Tab key indents the current line" under Tabulators

 

--------------------
Sean B. Fuller
www.seanbfuller.com
www.tractiv.com

PDT All-in-one version 1.0

Sean B Fuller - July 5, 2007 - 00:23

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

AltaVida - August 27, 2007 - 09:58

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

Benjamin Melançon - January 19, 2008 - 22:33

Look directly under Preferences in the "Eclipse" menu (for these options, not under Window).

benjamin, Agaric Design Collective

FYI

dman - July 11, 2007 - 13:51

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/

 
 

Drupal is a registered trademark of Dries Buytaert.