Drupal hooks code completion with PhpStorm 7
PhpStorm is my favourite IDE for PHP development and is a great tool for Drupal development. Drupal hook autocomplete used to be available via 3rd party plugins with varying reliability. It is now standard with PhpStorm with the recent release of PhpStorm 7 (via the Drupal Plugin).
When you open a module file, PhpStorm should ask you if you want like to enable Drupal support. PhpStorm should automatically recognise that it is a Drupal module. However, I have noticed that when opening a module file that is in a Virtual Machine, it is not automatically detecting it. In this case, you need to manually enable Drupal support.
Manually enable Drupal support.
Go to Preferences and select Drupal under project settings. Tick "Enable Drupal integration" and set the installation path for your Drupal site.
Just start typing out the function name as you normally would, and PhpStorm will start to autocomplete it with available hooks.
For example, when implementing hook_form_alter in a module called news:
- function news_form
Select the hook you want and hit enter. PhpStorm will create the function and include the relevant parameters.
You can quickly view the documentation for a hook implementation by clicking on the name and hitting F1.
Navigation to the hook itself
You can navigate to the hook itself by clicking on the ‘navigate to hook invocation’ in the gutter.
A couple of notes, on my Mac, F1 is reserved for Spotlight, so I had to give Spotlight a different shortcut.
Also, the transparency for floating windows is set to 50% . I turned off floating window transparency so I could read the documentation better. To turn it off, go to Preferences, then IDE settings and then Appearance. Deselect "Use transparent mode for floating windows". You can also try changing the ratio - what ever floats your boat.