Drupal-Specific Coding Assistance
On this page:
- Using Drupal Hooks In PhpStorm
- Completing hook declarations
- Navigating to a hook invocation from the editor
- Quick documentation look-up for hooks
- Setting the Drupal code style in a project
- Checking code against the Drupal coding standards
- Viewing Drupal API documentation from PhpStorm
- Using the Drush command line tool
Using Drupal Hooks In PhpStorm
PhpStorm provides full native support of Drupal hooks
Completing hook declarations
- Start typing a hook name and press Ctrl+Space.
Navigating to a hook invocation from the editor
- To navigate to a hook invocation from the editor, click the icon in the gutter.
In case of multiple invocations, PhpStorm displays a list of available hook invocations so you can choose which one to navigate to.
You will be navigated to the line where the relevant hook is invoked with
Quick documentation look-up for hooks
- To view documentation on a hook, position the cursor at the hook name in question and choose View | Quick Documentation Lookup or press Ctrl+Q.
Setting the Drupal code style in a project
In the Event Log tool window, click the Set link next to the
Drupal-style formatting can be set for this projectmessage.
Use the Code Style: PHP page of the Settings dialog box:
- Open the Settings dialog box by choosing File | Settings on the main menu, click Code Style, and then click PHP.
- On the Code Style: PHP page that opens, click the Set from link.
- On the pop-up menu, choose Predefined, then choose Drupal.
Checking code against the Drupal coding standards
- To use PHP Code Sniffer:
To use Coder, the native Drupal code quality tool:
- Download the Drupal Coder module (7x-2.0 version is recommended). You don't need to install or use the Drupal Coder module, it contains the Drupal Coding Standards inside.
Unpack the downloaded archive and find the
coder_sniffer/Drupalsubdirectory inside. You need to move the contents of this directory to
<php installation folder>/CodeSniffer/Standards/Drupal. This directory must contain the
ruleset.xmlfile and some other subdirectories.
Viewing Drupal API documentation from PhpStorm
- Select the symbol you are interested in and choose Search in Drupal API on the context menu of the selection.
Using the Drush command line tool
- Download and install Drush as described at https://github.com/drush-ops/drush.
Integrate Drush with PhpStorm by configuring it a s Command Line Tool:
- Open the Settings dialog box and click Command Line Tool Support.
- On the Command Line Tool Support page, click the Add button. In the Choose Tool to Add dialog box that opens, choose Drush and specify the tool's visibility. The available options are Project (available only in the current project) and Global (available across all PhpStorm projects). Click OK.
In the Drush dialog bo that opes, specify the path to the Drush executable file.
PhpStorm automatically fills in the default location, which is usually
C:/ProgramData/Drush/drush.baton Windows and
/usr/bin/drushon Mac OS or Linux. If you followed the standard installation procedure, the predefined path will be correct, just click OK, whereupon PhpStorm loads command definitions automatically and returns to the Command Line Tool Support page.
- In the Alias text box, specify the alias to use in calls of tool commands. Accept the default alias or edit it, if necessary.
- To activate the detected command set, select the Enable check box.
- To run a Drush command, choose Tools | Run Command... on the main menu or press Ctrl+Shift+X (Cmd-Shift-X on OS X).Ctrl+Shift+X (Cmd-Shift-X on OS X).
Last modified: 29 January 2015