Configuring Eclipse

Last modified: June 17, 2009 - 16:27

The following has been updated for the RC4 of pdt!

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.
  2. In the left-hand menu click on General -> Workspace
    • Check Text file encoding and select Other : UTF-8
    • Check New text file line delimiter and select Other: Unix.

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 -> Code Style -> Formatter:
    • Set Tab policy: 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, *.test, 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 -> CSS Files -> Editor:
    • Select Indent using spaces.
    • Set Indentation size to 2.
  2. Expand the left-hand menu to General-> Editors -> Text Editors:
    • Select Displayed tab width.
    • Set Indentation size to 2.
  3. Expand the left-hand menu to Web -> HTML Files -> Editor:
    • Select Indent using spaces.
    • Set Indentation size to 2.
  4. Expand the left-hand menu to XML -> XML Files -> Editor:
    • Select Indent using spaces.
    • Set Indentation 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 Aptana

An Eclipse based IDE (or Eclipse extension) for editing PHP, CSS, xHTML, JavaScript and the like.

Make the following changes under Window -> Preferences:

  1. Expand the left-hand menu to General -> Editors -> Text Editor:
    • Enter 2 for Displayed tab width.
  2. Expand the left-hand menu to Aptana -> Editors:
    • Under Tab Insertion on the right, click Use Spaces.
    • If current width is not set to 2, click the edit link.

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.

When it's working, the PHP syntax checker and highlighter will save you hours of debug time. :)
Eclipse PHP syntax checker

See also

Eclipse IDE Setup for debugging
Eclipse and CVS
IBM DeveloperWorks article on setting up Eclipse + Drupal

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/

Configuring PHPEclipse for debugging

Liberation - December 1, 2008 - 05:14

It's quite possible to debug Drupal via PHPEclipse and XDebug, though not documented on this site - see http://dev.phpeclipse.com/wiki/Howto/XDebugAndPHPEclipse for information. On the XDebug Remote Script configuration, on the Main page I left the Remote Location blank, and on the Pathmap page had the Remote path as / which was mapped to the physical Apache doc root.

Make sure also to disable DBG debugging by deleting the net.sourceforge.phpeclipse.debug.core and net.sourceforge.phpeclipse.debug.ui jars as the two debuggers cannot coexist at present.

Hope this helps :)

just curious what is best

armyofda12mnkeys - October 27, 2008 - 00:23

just curious what is best way to setup drupal with eclipse workspace-wise?

my usual setup is htdocs/site1, htdocs/site2 htdocs/site3 in apache,
in apache conf file, i have virtual hosting setup so for example htdocs/site1 is associated with alias site1, aka http://site1. etc (i guess even doing this with site1.com will work too but it could get confusing versus your live site).
and then in windows hosts file, have it setup so site1, site2, site3 are pointing to localhost.

should eclipses workspace be in your home|mydocuments directory just so store settings, and each site folder its own Project, so like htdocs/site1 is a project directory and mydocuments/workspace is your settings.

i saw some tutorials where the workspace is actually htdocs/site1, and some where mydocuments/workspace is the workspace and it seems like they publish to a directory htdocs/site1?

right now i think im going to go with keeping workspace outside of htdocs, unless anyone has a good reason otherwise.

EDIT: i think theres a couple approaches
* like above have the workspace outside of web directory, but when starting a new project, dont 'Use Default' for default workspace directory.
so actually point to the drupal directory/project on localhost. and eclipse settings will still be in default workspace using.
I would still use vhosting setup so u can reach http://site4 like the below settings only difference is, /site4 is in htdocs and >Directory not needed if using default apache settings for access.

* have the workspace separate but setup in apache to reach it, like
apache conf file

<VirtualHost *:80>
DocumentRoot "C:\Documents and Settings\ach\My Documents\workspace\site4"
ServerName site4:80
ErrorLog logs/site4_error.log
CustomLog logs/site4_access.log common
<Directory "C:\Documents and Settings\ach\My Documents\workspace\site4">
Options Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

hosts file:
127.0.0.1 site4
and setup eclipses debug options so setup a PHP Server to be http://site4
* same setup as above but just make the workspace the drupal install site4 inside of htdocs, and configure vhosting.
* have it seperate and use eclipse plugin like esFTP to sync local workspace to a site if not testing locally

Many preference paths seem to have changed

nadam - March 7, 2009 - 17:33

I just installed Eclipse 3.4 with WTP 3.0 and PDT 2.0 from http://www.zend.com/community/pdt?ecl=EclipseZend and many of the paths seem to have changed since this instruction was written.

For tabs and spaces use the following paths:

PHP -> CodeStyle -> Formatter
JavaScript -> CodeStyle -> Formatter (then click the Edit-button)
Web -> CSS Files -> Editor
Web -> HTML Files -> Editor
XML -> XML Files -> Editor

Eclipse seems to fall over on jquery

peamik123 - March 17, 2009 - 20:49

I've just installed Eclipse Version: 3.4.2 Build id: M20090211-1700 Ganymede all-in-one with pdt & zend on my winXP desktop, but I can't get remote debug to work. It keeps failing on jquery statements (we've got TinyMCE installed which is the first thing it hits). I am sure there must be a plugin somewhere or a configuration setting for jquery in Eclipse that I am missing. I'm new to IDE's generally & find all the options somewhat bewildering.

Has anyone cracked getting Eclipse working with zenddebugger (please don't tell me about xDebug...that isn't available on the remote server environment I need to debug) and making it work for jquery? This is driving me nuts presently, and I am out of options on where to look, but I desperately need to get a debug environment going urgently.

All help welcomed - I'm not really up-to-date on the technical aspects of this stuff, so if you can help, a detailed response would be much appreciated.

If you want to be debugging

dman - March 17, 2009 - 22:16

If you want to be debugging jquery, you need to be using the unpacked version (avaialble at the jquery site)
Yes, Eclipse failes to load the compressed version (it freezes for 3 minutes or more) due to it all being one long line. It wouldn't be much help for reading anyway, as the packed version is almost unreadable.
Replace your jquery.js with the unpacked and carry on!

Breakpoints

doompal - March 24, 2009 - 10:08

My eclipse set up (PDT) does not allow the setting of breakpoints in .module and .tpl.php. Any ideas anyone? Thanks.

Solved, my fault. It looks like I got confused setting up file associations, at one point I couldn't open .php files. module now define in content types -> text -> php content type.

Eclipse and the drupal API?

esend7881 - April 4, 2009 - 11:15

I wonder, is there a way to connect the drupal api (http://api.drupal.org) into Eclipse, just like how Eclipse ports to php.net?

Errors after creating new PHP project

yymoto2 - April 14, 2009 - 12:17

Hi, I'm new to eclipse and with minimal understanding of programming, trying to setup a proper IDE development environment and learn.

I'm on Window XP, using Drupal 6.10, xampp, successfully installed PDT2.0 + Zend Debugger v5.2.15 but encounter issues when trying to create a new project. Here's what I did:

1) File > New > PHP Project
2) Inside 'PHP Project' box, I do the following:
- 'Create content from existing source' where I point to "e:\xampp\htdocs\drupal6.10"
- Enable javascript support
3) click 'Finish'
4) File > Import > General > File System > From Directory "e:\xampp\htdocs\drupal6.10" > Into Folder "my_new_project"
5) Finish

The entire folder get imported but it turns out to have a long list of error present at the 'Problems' tab. Following are the errors (sorry I don't know how to attach a screencap of error page):
1) Error Type = 'JavaScript problem'
2) With the 'Description' such as: "cannot be resolve to a type", "$ cannot be resolved", "blocks cannot be resolved", "cannot make a static reference...."
3) Practically involves every single ".js" file.

May I know where I did wrong or missing out any steps? Is my approach to add a Drupal project correct? Can somebody point me to the right direction?

Thanks for the help :)

Re: Errors after creating new PHP project

whatdoesitwant - June 15, 2009 - 11:35

Hi yymoto2,

I saw your question just now.
I do not think your step 4 and 5 are necessary.

  • You either create your project from an existing source (step 1-2-3) and finish: now all your drupal6.10 directory content becomes directly editable in eclipse by simply selecting the php perspective (window > open perspective > php).
  • Or you import what you need into your default eclipse workspace. This way never worked for me. Maybe a real developer with some cvs experience can help you with that one.
  • I believe that you are trying to do both.

    I am not sure this will resolve your problem, though. Check to see if you are using an upacked jquery library. See dman's post above.

    I would love to get back to you on this but I am never going to find this thread again until the new drupal.org is launched. I can't find where to subscribe to these threads anywhere.

    Willem

     
     

    Drupal is a registered trademark of Dries Buytaert.