Creating a IntelliJ IDEA project with a Drupal module

You can create a IntelliJ IDEA project that will be set up and configured in accordance with the Drupal requirements.
This is done by creating a project by a Drupal Module template.

Choose
File | New | Project
on the main menu
or click the New Project button on the Welcome screen.
The Project Category and Options dialog opens.

In the left-hand pane, choose PHP from the list,
then choose Drupal Module in the right-hand pane, and then click Next.

On the second page of the wizard,
specify the project name and the folder where it will be created and provide the following Drupal-specific information:

Specify the root folder of the Drupal installation in the Drupal installation path.
Type the path manually or click the Browse button and select the relevant folder in the dialog box that opens.

Select the Set up PHP | Include paths check box to have Drupalinclude paths automatically configured for the project.
The following paths will be added to the Include Paths list
on the PHP page of the Settings dialog box:

<drupal installation root>/includes

<drupal installation root>/modules

<drupal installation root>/sites/all/modules

The include paths are added to the list after you leave the dialog box.

From the Version drop-down list, choose the version of Drupal to use,
the
supported versions are 6, 7, and 8
.

You can update integration settings at any time later in the File | Settings for Windows
and Linux or IntelliJ IDEA | Preferences for OS X.

IntelliJ IDEA generates a project stub in accordance with the selected Drupal version.
For Drupal 8, a module_name.info.yml file is generated where information about the module is provided.

Importing a Drupal project

Besides creating a project anew according to the Drupal Module template, you can open an existing Drupal project in IntelliJ IDEA.
IntelliJ IDEA recognizes the Drupal-specific structure and suggests activating the Drupal support in the project.

Open the folder with the required Drupal project by choosing File | Open Directory.

As soon as IntelliJ IDEA detects the Drupal-specific structure in the project, the following message is displayed in a pop-up window:
Click the Enable link.

In the Drupal Module dialog box that opens, select the Enable Drupal integration check box
and proceed as when creating a project with a Drupal module:

Specify the root folder of the Drupal installation in the Drupal installation path.

Select the Set up PHP | Include paths check box to have Drupalinclude paths automatically configured for the project.

From the Version drop-down list, choose the version of Drupal to use,
the
supported versions are 6, 7, and 8
.

You can update integration settings at any time later in the File | Settings for Windows
and Linux or IntelliJ IDEA | Preferences for OS X.

Configuring the Drupal-specific development environment

Whether you enable the Drupal support in an existing IntelliJ IDEA
project or create a new project with a Drupal module, IntelliJ IDEA 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 pop-up.
For each discrepancy IntelliJ IDEA suggests a fix. To apply a suggestion, click the link next to the reported
event.

Configuring file associations

To enable code highlighting, you need to set some additional file type associations
to make IntelliJ IDEA recognize and treat them as php files. Do one of the following:

In the Event Log tool window, click the Fix link next to the
Drupal support: <*.file extension> files are not associated with PHP file type message.

Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or
IntelliJ IDEA | Preferences for OS X,
and
click File Types under Editor.

In the Registered Patterns area, add the patterns that defined Drupal files to be recognized as php files.
To do that, click the Add button and type the pattern in the Add Wildcard dialog box that opens.

Changing the Drupal settings

No matter whether you enable the Drupal support in an existing IntelliJ IDEA project
or create a new Drupal module,
you can update the Drupal settings at any time on the Drupal page
of the Settings / Preferences Dialog.

Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or
IntelliJ IDEA | Preferences for OS X,
and
click Drupal under Languages&Frameworks.

Click Drupal and make the necessary changes on the Drupal page that opens:

To turn off the Drupal integration, clear the Enable Drupal integration check box. Note that this automatically excludes the folders
specified as include paths.

Change the Drupal installation directory and the version of Drupal to use.

To change the include paths, click PHP and make the required changes in the Include Paths area
of the PHP page that opens.
Note that is the Drupal integration for is disabled, the paths are automatically excluded.

To change the code style settings, click Code Style, and then click PHP.
On the Code Style: PHP page that opens, update the settings as necessary.