You can use PhpStorm as an IDE for Drupal development including modules, themes, and core. The supported versions are 6, 7, and 8.
PhpStorm provides integration between the Symfony2 and Drupal 8 while developing Drupal modules and core.
Downloading and installing Drupal
Setting up a Drupal project in PhpStorm
Option 1: Create a PhpStorm project with a Drupal module
You can create a PhpStorm project by a Drupal Module template, this project will be set up and configured in accordance with the Drupal requirements.
PhpStorm generates and configured a project stub in accordance with the selected Drupal version. For Drupal 8, a module_name.info.yml file is generated.
Open the New Project dialog
Choose the project type and location
Choose Drupal installation to use
Configure Include paths
Select the checkbox to have Drupal include paths automatically configured for the project. After you leave the dialog, the following paths will be added to the Include Paths list on the PHP page: <drupal installation root>/includes, <drupal installation root>/modules, and <drupal installation root>/sites/all/modules
Option 2: Import an existing Drupal module
When you open an existing Drupal module, PhpStorm recognizes the Drupal-specific structure and suggests activating the Drupal support.
Open your project
PhpStorm detects a Drupal-specific structure and shows a notification:
Enable Drupal support
Click Enable in the notification. In the Drupal Module dialog that opens, select the Enable Drupal integration checkbox and proceed as when creating a project with a Drupal module: specify the root folder of the Drupal installation, choose the version to use, and configure include paths.
Whether you enable the Drupal support in an existing PhpStorm project or create a new project with a Drupal module, PhpStorm checks if the development environment is configured properly for Drupal development.
Any detected inconsistency is reported in the Event Log tool window and as a popup For each discrepancy PhpStorm suggests a fix. To apply a suggestion, click the link next to the reported event.
Associating Drupal-specific files with the PHP file type
PhpStorm recognizes and treats files as php files and provides code highlighting based on file type associations.
Option 1: Use the Event log
In the Event Log tool window, click Fix next to the Drupal support: <*.file extension> files are not associated with PHP file type message.
Option 2: Use the File Types page
On the File Types page that opens, define file masks in the Registered Patterns area. See Set file type associations for details.
Changing the Drupal settings
Option 1: Enable or disable Drupal integration
In the Settings/Preferences dialog Ctrl+Alt+S, navigate to . On the Frameworks page that opens, toggle the Enable Drupal integration checkbox to activate or deactivate Drupal in the current PhpStorm project.
To use another Drupal installation, type the path to the relevant installation folder. Change the version if necessary.
Option 2: Update the include paths
On the PHP page that opens, make the required changes in the Include Paths area.
Using Drupal hooks in PhpStorm
PhpStorm provides full native support of Drupal hooks in .module files.
Use code completion for hook declarations
PhpStorm indexes any hook invocation whereupon hook names become available in code completion for creating hook implementations. To complete a declaration, start typing the hook name and press Ctrl+Space.
Navigate to hook invocations
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, and you can choose the one to jump to.
You will be navigated to the line where the relevant hook is invoked with
View hook documentation
Position the caret at the name of the hook and chooseor press Ctrl+Q.
Setting up Drupal code style in a PhpStorm project
PhpStorm automatically offers to apply the pre-configured Drupal Coding Standards (code style) if a project is recognized as a Drupal Module, or if the Drupal integration is enabled in an existing project, or when you create a new project with a Drupal Module. However, you can at any time change or customize this setting on the Code Style: PHP page of the Settings dialog.
Use the pre-configured Drupal code style in a project
In the Event Log tool window, click Set next to the Drupal-style formatting can be set for this project message.
You can also set the predefined code style on the Code Style: PHP page. In the Settings/Preferences dialog Ctrl+Alt+S, navigate to . Then, click Set from and choose Predefined | Drupal.
If applicable, customize the code style using the controls on the page.
Checking code against the Drupal coding standards
With PhpStorm, you can use the PHP_CodeSniffer tool, which detects coding standard issues, in combination with Coder, which provides a set of Drupal-specific standards to PHP_CodeSniffer. This will ensure that your code is clean, consistent, and free of some common errors.
From the composer.json context menu, choose . Alternatively choose from the main menu.
In the Manage Composer Dependencies Dialog that opens, select the squizlabs/php_codesniffer package from the Available Packages list, possibly using the search field.
Next, install Coder, which will provide Drupal-specific standards to PHP_CodeSniffer.
From the composer.json context menu, choose . Alternatively choose from the main menu.
In the Manage Composer Dependencies Dialog that opens, select the drupal/coder package from the Available Packages list, possibly using the search field.
The Coder package will be installed, and the corresponding Drupal standard will be selected for the PHP_CodeSniffer validation inspection automatically. If necessary, you can further customize the inspection on the page of the Settings/Preferences dialog Ctrl+Alt+S. See Configuring PHP_CodeSniffer as a PhpStorm inspection for details.
Viewing the Drupal API documentation from PhpStorm
In the PhpStorm editor, select the symbol you are interested in and choose Search in Drupal API from the context menu. The Drupal API Documentation opens.
Using the Drush command line tool from PhpStorm
PhpStorm integrates with the Drush command line shell and scripting interface, version 5.8 and later. Before you begin, download and install Drush as described at https://github.com/drush-ops/drush.
Configure Drush as a command line tool
Click on the toolbar.
In the Command Line Tools dialog, choose Drush from the list, and specify its visibility level (Project or Global).
When you click OK, the Drush dialog opens.
Specify the path to the Drush executable. The default location is commonly C:/ProgramData/Drush/drush.bat on Windows and /usr/bin/drush on macOS or Linux. If you followed the standard installation procedure, click OK to accept the predefined path.
In case of custom installation, type the path to the Drush executable file and click OK.
Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click to edit the tool properties, or to customize the commands set. See Customizing a tool for details.
Run Drush commands
From the main menu, chooseor press Ctrl twice.
In the Run Anything window that opens, type the call of the command in the
The command execution result is displayed in the Run Tool Window.
Terminate a command
Click on the Run Tool Window toolbar.
Debug Drush commands
Drupal commands are defined in controller classes that extend
DrushCommands. To debug a command, it is crucial that you debug the command itself, and not the controller class file it is defined in. Otherwise, the Drupal bootstrapping process will be skipped, and the execution will fail.
In the controller class corresponding to the selected command, click the editor gutter at a code line where you want to set a breakpoint.
Create a run/debug configuration that will run the drush tool with the selected command. In the main menu, select , then click and choose PHP Script from the list.
In the Run/Debug Configuration: PHP Script dialog, provide the run/debug configuration parameters.
In the File field, provide the path to the drush executable file.
In the Arguments field, type the actual command and its arguments, such as
On the PhpStorm toolbar, select the created run/debug configuration and click . The command execution will stop at the specified breakpoint.
Using Drupal 8 with Symfony2
PhpStorm provides close integration between Drupal, version 8, and Symfony2. Through this integration, Symfony2 components are connected with Drupal infrastructure. To take advantage of this integration:
Install the Drupal Symfony2 Bridge plugin
What coding assistance for Drupal 8 - Symfony2 integration is available?
Completion for major Drupal-specific parameters in <module_name>.info.yml files that contain information about Drupal modules.
Strings suitable for use inside Drupal-specific t() function are indexed across your project and offered for completion.
Completion for relevant yml key values in url() and other Drupal API functions, which makes search for the right value easier.
Navigation to the yml file by pressing Ctrl+B or choosing Navigate | Go To Declaration.
Full support for service containers described in yml files, including completion and navigation with Ctrl+B.