Getting the most out of PHPStorm for Drupal 8

Presentation by Kyle Einecker

About me

ctrlADel

@DBridgeChicago

About you

Currently using PHPStorm?

Currently using XDebug?

Using automated code testing or sniffing?

Plugins

git

.ignore

Symfony Plugin

Drupal Symfony Bridge

PHP Annotations

Key Promoter X

Git

Tool window

View > Tools Windows > Version control

  • Press the grey box in the bottom left of the window
  • Select Version control on bottom bar

History

Local history

Diff

Select any blue file in the git log view or git local changes view

ctrl+d

Linting and Sniffing

phpcs

Installation instructions
vs

stylelint

Drupal change record
New in 8.4
Will be available to contrib modules and themes eventually

eslint

Drupal documentation
PHPStorm configuration

sass-lint

Alternative to stylelint

PHPStorm plugin
Github repo
vs

Navigating code

Search everywhere

shift+shift

Hierarchy view

ctrl+h
PHPStorm documentation
Build a hierarchy

Copy path

Full path
ctrl+shift+c
/home/kyle/vms/drupal-vm/drupal/web/core/lib/Drupal/Core/Block/BlockBase.php
Relative path
ctrl+shift+alt+c
web/core/lib/Drupal/Core/Block/BlockBase.php:29

Function definition

Works on function calls and {@inheritdoc}
ctrl+q

Go to function deceleration

ctrl+b
ctrl+click

Find usages

alt+f7

Most actions

alt+enter

Gutter icons

I
Shows implementations of parent methods or children implementing a method.
O
Shows if a method is overriding a parent or is overridden by a child.
H
Shows hook documentation in *api.php, all implementations of the hook, and where the hook is called.

Code completion and boiler plates

Drupal console

Implement interface methods

ctrl+i

Implement interface methods #2

alt+enter
Result:

Use statements

Auto added when code competition is used
For other instances use alt+enter
alt+enter
Unused classes are shown in grey

Autocomplete options

ctrl+space
services.yml

Autocomplete options

ctrl+space
annotation blocks

Autocomplete options

ctrl+space
getting services from container

Refactor class names

shift+f6
Change class name and all instances of it in code
also available for functions and variables

Refactoring cont.

XDebug

Configuring XDebug

PHPStorm Documentation
Drupal Documentation

Enabling XDebug

Turn on browser extension
Turn on listening in PHPStorm

Set breakpoints

XDebug interface

Evaluate code

alt+f8
or right click > evaluate expression

Vendor mapping

Make sure vendor directories are mapped correctly in
File > Settings > Languages & Frameworks > PHP > Servers

Patching

Patching with composer

composer-patches
Applies patches through composer

Apply patches

VCS > Apply patch
VCS > Apply patch from clipboard

Quick patches for contrib modules

  1. composer install drupal/address --prefer-source
  2. Declare new VCS directory in PHPStorm
    File > Settings > Version control
  3. Changes to the address module now show in the Version Control window
  4. Use your favorite patching method to create a patch for address

phpcbf

Configuration

Setup instructions

Single File

parameters: --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md $FileDir$/$FileName$
working directory: $ProjectFileDir$

Current directory

parameters: --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md -l $FileDir$
working directory: $ProjectFileDir$

Other things PHPStorm does

Questions?