Skip to content

Instantly share code, notes, and snippets.

@sirkitree
Created March 26, 2013 22:07
Show Gist options
  • Save sirkitree/5249757 to your computer and use it in GitHub Desktop.
Save sirkitree/5249757 to your computer and use it in GitHub Desktop.

PhpStorm for Drupal

PhpStorm has an excellent debugger for developing Drupal modules or even Drupal themes. After numerous IDE and text editors, it has earned it's place to be my primary IDE for almost anything Drupal, for many good reasons. PhpStorm, by default, is as Drupal friendly as many other PHP IDEs. That means it gets the job done, but there might be some syntax in your code the Drupal Coding Standards and it's authors wouldn't be too happy about. Here are a few things to make PhpStorm play well with Drupal.

Keymap

Althought not related to Drupal, the Keymap is the first thing we will change. PhpStorm by default comes with very unaturally keyboard shortcuts for me. Under Preferences, scroll down to select Keymap on the left. Select the keymap that suits your needs. Mac OS X 10.5+ feels the most intuitive to me. You may also further customize the keyboard shortcuts to each of the actions. Keymap

Syntax

Now let's fix the code style. Drupal recommends less than 80 characters per line. General

I have left the "Wrap when typing reaches right margin unchecked to prevent auto text wrap, since more than 80 characters is allowed for some situations. This gives you a nice solid line in the editor where 80 characters is. 80 characters

Then we will work on PHP syntax. PhpStorm conveniently comes with a predefined style for Drupal, we will use that to start. Predefined Drupal style

The "Tabs and Indents" should look like this. Tabs and Indents

On the "Spaces" tab, make sure "After type cast" is selected. Spaces

On the "Wrapping and Braces tab", make sure these settings are set correctly. Wrapping and Braces 1 Wrapping and Braces 2

On the "Other" tab, convert True/False and Null to Upper case Other

That should be all we need for the PHP syntax. You might also want to set up syntax for other languages like HTML, JavaScript, CSS and any CSS preprocessors you may use.

PHP CodeSniffer

I like to install the PHP CodeSniffer to give myself extra warnings about some Drupal Coding Standards violations. First of all, follow these instructions to install PHP CodeSniffer and the Drupal coding stands definitions. Once you have phpcs ready, set up the Code Sniffer like so Code Sniffer

Make sure that PhpStorm is using the PHP Code Sniffer for code inspection. Inspection

Now you should get some nice warnings as reminders for keeping up the coding standards Inspector Warnings

Tips and Tricks

If font size changing is not something you often do, I would also recommend turning off the mouse wheel zoom. I noticed a lot of accidental zooming happening under OSX using a Magic Mouse with the option turned on. I end up using Pinch-to-Zoom on the trackpad when I need zooming. You can also set up your own keyboard shortcut under Keymap in Preferences. Zoom

Debugging

The debugger is my main reason for using PhpStorm for Drupal development. Follow this article to set up the debugger with Xdebug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment