Drupal
You can use PhpStorm as the IDE for Drupal development, including development of Drupal modules, themes, and the core. The supported versions are 6, 7, 8, and 9.
tip
For Drupal 10 projects, use version 9 in the IDE settings.
tip
This guide assumes that you already have Drupal downloaded and installed. For instructions about downloading and installing Drupal, refer to the official Drupal documentation.
Open Settings (CtrlAlt0S) | PHP | Frameworks.
Extend the Drupal node, select the Enable Drupal integration checkbox, and specify the parameters as follows:
Drupal installation path
Specify the path to the root directory that contains the installed Drupal core.
Set up PHP | Include paths
Select the Set up PHP | Include paths checkbox to have PhpStorm automatically add Drupal core directories to the project's include paths.
To configure the paths manually, open Settings (CtrlAlt0S) | PHP and edit the list of direectories on the Include path tab.
tip
When the Drupal integration is disabled, the paths are automatically excluded.
Version
Choose the version of Drupal to use, the supported versions are 6, 7, 8, and 9.
tip
For Drupal 10 projects, use version 9 in the IDE settings.
Click Apply to save the changes.
You can create a new Drupal project in PhpStorm from a Drupal Module template.
PhpStorm generates and configures 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 by choosing File | New Project in the main menu or clicking Create New Project on the PhpStorm Welcome screen.
In the left-hand pane, select Drupal Module.
In the right-hand pane, specify the Drupal support parameters.
When you open (File | Open in the main menu) an existing Drupal module project in PhpStorm, the IDE recognizes the Drupal-specific project structure and suggests activating Drupal support.
![drupalStructureDetected.png drupalStructureDetected.png](https://resources.jetbrains.com/help/img/idea/2024.3/drupalStructureDetected.png)
Click Enable Drupal Support to open the modal dialog and specify the parameters.
![Drupal settings dialog Drupal settings dialog](https://resources.jetbrains.com/help/img/idea/2024.3/Drupal_settings_dialog.png)
To provide proper code highlighting, PhpStorm needs to associate Drupal file formats with the PHP file type.
When you open a Drupal project in PhpStorm, the IDE detects the project type automatically and suggests associating Drupal file types with the PHP type.
![Associate Drupal files with the PHP file type Associate Drupal files with the PHP file type](https://resources.jetbrains.com/help/img/idea/2024.3/associate_drupal_files_with_php_type.png)
In the Settings dialog (CtrlAlt0S) , navigate to Editor | File Types.
On the File Types page that opens, select PHP on the Recognized File Types list.
In the File name patterns area to the right, click (
) and add one by one the
*.test
,*.install
,*.engine
,*.profile
, and*.theme
file name patterns.For more information, refer to File type associations.
PhpStorm provides full native support for 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 CtrlSpace.
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
module_invoke_all()
,module_invoke()
, ordrupal_alter()
.
View hook documentation.
Place the caret at the name of the hook and choose View | Quick Documentation Lookup or press Ctrl0Q.
tip
Documentation is taken from .api.php files provided by core and many other modules for reference purposes.
If PhpStorm recognizes the project to be a Drupal Module, or if the Drupal integration is enabled in an existing project, or when you create a new project from a Drupal Module template, PhpStorm automatically suggests applying the pre-configured Drupal Coding Standards (code style).
![Enable Drupal style formatting Enable Drupal style formatting](https://resources.jetbrains.com/help/img/idea/2024.3/enable_drupal_style_formatting.png)
You can also set the predefined code style manually on the Code Style: PHP page.
In the Settings dialog (CtrlAlt0S) , navigate to Editor | Code Style | PHP.
Click Set from and choose Drupal from the drop-down list that opens.
If applicable, customize the code style using the controls on the page.
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.
To get started, install PHP_CodeSniffer using any technique described in Install and configure PHP_CodeSniffer. Probably the easiest way is to install it with Composer.
Inside composer.json, add the
squizlabs/php_codesniffer
dependency record to therequire
orrequire-dev
key. To get code completion for the package name and version, press CtrlSpace.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press AltEnter and select whether you want to install a specific dependency or all dependencies at once.
Next, install Coder, which will provide Drupal-specific standards to PHP_CodeSniffer.
Inside composer.json, add the
drupal/coder
dependency record to therequire
orrequire-dev
key. To get code completion for the package name and version, press CtrlSpace.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press AltEnter and select whether you want to install a specific dependency or all dependencies at once.
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 Editor | Inspections page of the Settings dialog (CtrlAlt0S) . For more information, refer to Enable PHP_CodeSniffer as a PhpStorm inspection.
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.
![View Drupal API documentation View Drupal API documentation](https://resources.jetbrains.com/help/img/idea/2024.3/view_drupal_api_documentation.png)
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 in the official Drush documentation.
When you install Composer dependencies in a Drupal project, PhpStorm detects and configures Drush automatically and displays a respective notification in the Composer Log.
If you want to customize the tool, click
in the gutter to quickly jump to the PHP Command Line Tool Support settings page.
note
On Windows, automatic Drush detection requires a configured local PHP interpreter.
In the Settings dialog (CtrlAlt0S) , go to Tools | PHP Command Line Tool Support.
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 on Windows and/Drush /drush.bat /usr on macOS or Linux. If you followed the standard installation procedure, click OK to accept the predefined path./bin /drush 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 PHP Command Line Tool Support page. Optionally, click
to edit the tool properties, or
to customize the commands set. For more information, refer to Customize a tool.
Go to Tools | Run Command or press Ctrl twice.
In the Run Anything window that opens, type the call of the command in the
<drush> <command>
format.The command execution result is displayed in the Run tool window.
Gif
Click
on the Run tool window toolbar.
Drupal commands are defined in controller classes that extend DrushCommands
. To debug a command, it is crucial that you initiate a debugging session for 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, go to Run | Edit Configurations, then click
and choose PHP Script from the list.
In the 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
status
.
On the PhpStorm toolbar, select the created run/debug configuration and click
. The command execution will stop at the specified breakpoint.
Gif
PhpStorm provides close integration between Drupal, version 8, and Symfony. Through this integration, Symfony components are connected with Drupal infrastructure. To take advantage of this integration:
Install the Drupal Symfony Bridge plugin
In the Settings dialog (CtrlAlt0S) , navigate to the Plugins page. Click Browse Repositories, select the plugins and click Install. For more information, refer to Install plugins.
note
The Drupal Symfony Bridge plugin depends on the Symfony Support plugin, which will be installed automatically.
Enable annotations
To get advanced annotations support, install the PHP Annotations plugin as described in Install plugins.
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 Ctrl0B or choosing Navigate | Go To Declaration.
Full support for service containers described in yml files, including completion and navigation with Ctrl0B.
Support of the Twig template engine, which is now the default template engine for Drupal 8, including completion, navigation, and recognition of Drupal functions. See also Twig in Drupal 8.
Thanks for your feedback!