Develop
Tools for developers

Drupal tools for developers

IDE

Let's start with your most used tool!

Two references here:

PHPStorm

Nothing beats PHPStorm (opens in a new tab) for a Drupal job. Composer, Git, Docker, Xdebug, Drupal coding standards, web services support, Drupal indentation style and perfect autocompletion with inline documentation.

Also, it has support for many plugins Twig, Symfony, Laravel, Blade, Gitignore, Markdown, ... It's not free, but you can get a free license if you are a student (opens in a new tab) or an open source contributor (opens in a new tab).

VSCode

It is free and has a lot of plugins, that still need to be configured to get a similar level of integration as PHPStorm.

Examples of plugins:

Configuring Visual Studio Code for Drupal (opens in a new tab)

Configure your development environment

Caching

Drupal comes with great caching for production, but before you start development tasks, there is some configuration to prevent caching.

Disable Drupal caching during development (opens in a new tab)

Twig debug

Displaying the Twig templates used by regions, blocks, nodes, ...

development.services.yml
parameters:
  twig.config:
    debug: true

Then cache rebuild drush cr

It's even simpler with Drupal 10.1.0 Simplifying the frontend developer experience in Drupal with a click of the button (opens in a new tab)

Other Twig techniques are available on the following links from Drupal.org.

Debugging

Var dumper

Symfony dumper is available out of the box via

dump($myVar);

Use Devel (opens in a new tab) that provides var dumper improvements with Kint (opens in a new tab).

composer require --dev drupal/devel
composer require --dev kint-php/kint
drush en devel

then configure it in /admin/config/development/devel and use in code kint($myVar) or ksm($myVar).

Step debugger

Install XDebug (opens in a new tab)

Debugging all the things with Xdebug, DDEV, PhpStorm, PhpUnit (opens in a new tab) - DrupalEasy

Drush CLI

Drush is a command line shell interface for Drupal. To require it in your project, use Composer. It is advised to require it per project and not globally, so you can use different versions of Drush for different projects.

composer require drush/drush

Then you can use it with vendor/bin/drush.

To dig your way out of the list of commands, use grep. E.g.: drupal list | grep service Drush can be extended with your own commands, so contributed modules are often providing specific commands.

Here is a short list of most used Drush commands.

Site installation from configuration

drush si -y standard --sites-subdir default --account-name admin --account-pass admin --existing-config

Cache

  • Cache rebuild drush cr
  • Cache clear drush cc then select which one
  • Cache get drush cg [cid] [bin] or set drush cs [cid] [bin]

User login

  • as user 1 drush uli (user-login)
  • as another user drush uli --uid 2 or drush uli [name]

Configuration

  • export drush cex
  • import drush cim
  • partially import drush cim --partial --source=/path/to/module/config/install

Database

  • Open SQL CLI drush sql:cli
  • SQL Query drush sql:query ["SELECT * FROM users"]
  • Sanitize (remove or obfuscate user data) drush sql:sanitize
  • Database update drush updb
  • SQL dump drush sql:dump --result-file=auto --gzip

Delete entities

  • Delete all article nodes drush entity:delete node --bundle=article

Sync environments

  • Sync DB, skip tables drush sql:sync @self.prod @self --skip-tables-list=redirect_404,cache_*
  • rsync files, exclude files drush rsync @self.prod:%files/ @self:%files/ --exclude-paths=css:js:php/twig

Evaluate PHP code

  • drush php-eval "echo drupal_get_installed_schema_version('my_module');"

Queue

  • List queues drush queue:list
  • Run a queue drush queue:run [name]

Logs

  • Filter the logs interactively drush watchdog:list

More Drush 11 commands (opens in a new tab)

Testing

The ultimate guide to write tests for Drupal 8 modules, themes and profiles. It aims to provide sample code and methods to write different types of testings available in core.

https://drupadocs.gitbooks.io/testing/ (opens in a new tab)

PHPUnit

PHPUnit in Drupal (opens in a new tab)

Pest for Drupal

YouTube (opens in a new tab) - GitHub (opens in a new tab)

Profiling and monitoring

Report fixes and deprecations for Drupal upgrade

Code quality

Static analyzer

PHPStan for Drupal (opens in a new tab)

Coding standards

PHP Code Sniffer (opens in a new tab) is a library that tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

Check Drupal coding standards

phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md /file/to/drupal/example_module

Automatically fix coding standards

phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md /file/to/drupal/example_module

Modules for developers

Review the Developer Experience projects section.

Read more