Establishing NetBeans Intended for drupal
In addition to its speed and refactoring capabilities, it offers the following:
- Formats your code according to Drupal Coding Standards
- It recognizes Drupal specific file extensions (.info, .module .install etc.)
- Replaces tabs with spaces
- Stores line breaks in UNIX format
- Character encoding of files can be UTF-8 by default
- Provides autocompletion with hint support for functions and classes project-wide, including Drupal core (provided core is in your project directory
- Code templates available for Drupal hooks
- Supports SVN and GIT version control systems
Note: These directions have been mostly updated to correspond to the current version of Netbeans (7.1.1 at this time). Most images are still from Netbeans 6.9 and were not changed if the setup was not significantly different. (LoMo — March 8, 2012)
Note: Windows users see http://drupal.org/node/1846954 to set up Netbeans, Xdebug, Drupal Dev Tools and Templates with Windows 7/XP and Acquia Dev Desktop (c11a - 11/21/2012)
Download the latest stable version of NetBeans, either the PHP bundle or the bundle labeled “All” (support for Java SE/EE and C/C++ as well). The page will offer the right version for you based on your browser’s operating system, but you can also select other platforms from the top-right drop-down menu.
After downloading, follow the instructions given by the installer. When the installation is complete, locate the Tools > Plugins menu item, choose the Installed tab, and activate the PHP plugin, if not already active.
Setting up Drupal Coding Standards
After you have activated the PHP plugin, go to Preferences (or Tools > Options) > Editor > Formatting, choose PHP in the “Language” drop-down, and choose Tabs And Indents from the “Category” drop-down. You should uncheck the "Use All Language Settings" checkbox in order to continue. After that use the following settings:
- Expand tabs to spaces: (check)
- Number of Spaces per indent: 2
- Tab size: 2
- Right margin: 80
- Initial Indentation: 0
- Continuation Indentation: 4 (if a new row is started within a condition)
- Array Declaration Indentation: 2
After that, choose Alignment from the category drop-down, and set "else and elseif" to start in a new row:
Choose Braces from category drop-down and set everything to "Same line":
Choose Blank Lines from category drop-down and set 1-1 blank lines to be used before and after functions:
The last category is "Spaces". You should use the following settings here:
- Check while, else, catch
- Uncheck Method / Function Declaration, Method / Function Call, Array Declaration
- Check if, for, while, catch, switch
- Uncheck Unary and Object operators
- Check Binary, Ternary, String concatenation, Key => Value and Assignment operators
- Check all options in "Before Left Braces"
- Uncheck all options in "Within parentheses"
- Uncheck “Before Comma” and “Before Semicolon”; check all others
When you have finished these steps, the code formatting will be just as required by the Drupal Coding Standards.
Setting up Drupal-specific file extensions and Drupal core functions
Go to Preferences > Miscellaneous > Files, and click New on the Files tab. Add the following extensions one by one:
Associated file type (MIME) type should be: PHP Files (text/x-php5)
Finally, add the "info" and "po" extensions with MIME type: text/plain.
Now NetBeans will recognize these filetypes. The next step is to allow it to autocomplete Drupal core functions. For this to happen you need to download Drupal and extract the files to a folder (you don’t need to install it, you just need the files, so that NetBeans can read the functions), go to Preferences > PHP > General, and add the folder to the Global include path list.
If you are also developing Drush-compatible modules, you should add the Drush folder to this list, to be able to use Drush functions.
Setting up Drupal hook templates
You just need to download the NetBeans Templates project, and import the extracted [.ZIP] file in Preferences > Editor > Code Templates. Please note that the import process will require a Netbeans IDE restart, so ensure you have saved all your preferences before running the template import.
Using version control systems
NetBeans supports CVS by default, but GIT can also be installed easily. You just need to download the plugin and install it.
(Note/Update: Netbeans 7.x includes Git and is active, by default).
After you have set up localhost, and installed your Drupal, create a new PHP project with File > New Project, PHP, PHP Application with Existing Sources.
After clicking “Next”, you can set your project’s properties. I suggest using the sites folder of your installed Drupal as Sources folder. Select 5.3 for PHP version and UTF-8 for encoding. You don’t need to store Netbeans metadata in a separate directory.
Now you can click “Finish”, and you will see your newly-created project. After creating a new file, you can use the autocomplete, and you are ready to use your NetBeans for Drupal development.