Main Content

Drupal Development Using PhpStorm

The PhpStorm IDE comes with a bundled Drupal Plugin, providing functionality for modules, themes as well as for core Drupal development for Drupal 6, 7 or 8. Combine that with PhpStorm’s excellent PHP, HTML, CSS and JavaScript support, automatic code inspections, debugging and unit testing support and we have a great tool for developing our next Drupal application! In this post, we will see how we can get started with Drupal development in PhpStorm.
From the Welcome screen (or by selecting File | New Project), we can choose to create a new project of the Drupal type. PhpStorm will make sure all include paths are set up and a .module and .info file are created to get started.
When opening an existing Drupal module in the IDE, we will be offered the ability to enable support for Drupal automatically. Enabling it will set up the PhpStorm project we are working in to provide full code completion, Drupal code style and so on.
While coding, having code completion available is very handy. PhpStorm indexes all code in our project and for any hook invocation, the hook name will be available. We can complete code by pressing Ctrl+Space (Cmd-Space on Mac OS X) and have the IDE create the hook implementation.
From the editor we can also navigate to Hook Invocations, so we can find out where a hook is being invoked, what parameters are passed into it, and so on. While the code is useful, having the API documentation from .api.php files at hand can be useful too. Core, as well as many module authors, provide these files for additional documentation on a hook which goes beyond just seeing the code. The View | Quick Documentation menu (or the F1 key) will bring up Quick Documentation when needed.
If quick documentation is not enough, the Drupal API Documentation at can also be invoked from the IDE. Just select the text you are interested in, invoke the context menu in the editor, and then select Search in Drupal API. This will fire up the default browser with the request sent from PhpStorm.
Once that code starts flowing, whether through caffeine or some good music, having a debugger at hand will help to analyze what is happening in code. We can work with Xdebug as well as Zend Debugger to debug our Drupal applications in PhpStorm, even when they are running on a remote server or on a Vagrant box. Speaking of which: the IDE comes with full support for launching Vagrant boxes, downloading plugins and so on.
We can of course also make use of the Acquia Dev Desktop which comes with an Apache web server and a MySQL database and makes it easy to have multiple development Drupal sites running on our machine. From there, we can deploy to the Acquia Cloud and benefit from a Drupal-tuned hosting stack and elastic resources to go from a staging site to full production.
Now, one would say development is more than the IDE, right? That’s true, but PhpStorm gives us a lot of things we can do from within the IDE. Consider Drush, a command line shell and scripting interface for Drupal. We can configure it inside our IDE and get it to run there as well, including autocompletion on all commands. This not only works for Drush but also for Symfony2 (or Drupal 8), Composer and many other tools. We can bring up the command line tool by selecting Tools | Run Command... or pressing Ctrl+Shift+X (Cmd-Shift-X on Mac OS X).
Next to command line tools, we can also make use of the issue tracker from within PhpStorm. Once configured (check the Integrating PhpStorm and the Issue Queue blog post by Cameron Eagans for details on configuration), we can start working on a task in the issue tracker, commit to version control and move on to the next item. One smooth development workflow, right in the IDE!
This post was written by Martin Balliauw at JetBrains. JetBrains is a partner of our partner, Acquia.