Updated on 16 January 2018
Effective development starts by knowing well the system capabilities, API's and the ecosystem, that will be described briefly below. One of the newcomer mistake is programming too much. If you need to implement a commonly used feature there are chances that there is a module for that.
Drupal has many satellite tools that will dramatically reduce the time needed for common programming tasks. The most used are exposed below. A complete list is available on the Development tools overview on Drupal.org.
Let's start by your most used tool!
A single reference here, even if Sublime and NetBeans are wonderful, nothing beats PHPStorm for a Drupal job.
Composer, Git, Vagrant, Xdebug, Drupal coding standards, REST support, Drupal indentation style and perfect autocompletion with inline documentation. It has also support for Symfony, Laravel, Blade, ...
Pricing: 199 € the first year.
Drush, Drupal Console and Phing are coming out of the box in the vendor/bin directory after a Composer install of this fork of the Composer template for Drupal project. They are intended to be used locally, so you make sure that you are using the right version with the Drupal Core (e.g. Drush 9 with core 8.4.x).
So, if you start from this Composer template, you will not need to install them.
Several other tools are also shipped with this template so just have a look at the readme.
Drush stands for Drupal Shell, it is the command line and scripting interface for Drupal. You can use it to speed up installing, developing and maintaining Drupal sites.
A major change since version 7 is that is should not be installed globally but locally, per website.
Install modules, generate content, rebuild cache ... find everything on Drush Commands.
List of the drush commands:
drush list, (or just
drush) then to get some help
drush help [command]
Some of the most used Drush commands, to be executed on the web/docroot directory :
drush cr- Cache rebuild (replaces the Drupal 7 drush cc all)
drush uli- User login: generates a one time login for
drush sql-dump- Creates a database dump
Drush and Composer tips
Use Composer commands (composer install, composer require, ...) at the root of your project, where the composer.json file is located (so parent of the web / docroot / public_html, ... directory).
Use Drush locally (and not globally) via the vendor directory but execute the command in the web directory.
The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
Scaffold code, get controllers and services and much more, some of the commands :
drupal gm- Generates scaffold code for a module (generate:module)
drupal gpb- Generates a Block Plugin (generate:plugin:block)
drupal gcn- Generates a Controller (generate:controller)
drupal dco- Displays current services for an application (debug:container)
List all the Drupal Console commands:
drupal list (or just
- Everybody loves cheat sheet! Drupal Console Cheat Sheet
- Drupal Console commands
- Drupal Console documentation
If you find yourself writing custom scripts to handle the packaging, deploying, or testing of your applications, then we suggest looking at Phing. Pre-packaged with numerous out-of-the-box operation modules (tasks), and an easy-to-use OO model to extend or add your own custom tasks.
Some of the commands, to be executed on the parent directory of the web/docroot :
./vendor/bin/phing install - Installs the website (make sure that you have your the build.properties.local file)
./vendor/bin/phing setup-dev (after an installation, or if you want to couple the two : ./vendor/bin/phing install-dev)
This will perform the following tasks:
- Configure Behat.
- Configure PHP CodeSniffer.
- Enable 'development mode'. This will:
- Enable the services in
- Show all error messages with backtrace information.
- Disable CSS and JS aggregation.
- Disable the render cache.
- Allow test modules and themes to be installed.
- Enable access to
- Enable development modules.
- Create a demo user for each user role.
List the available Phing build commands :
To dig your way out of the list commands, use grep:
drupal list | grep service
Drupal VM makes building Drupal development environments quick and easy, and introduces developers to the wonderful world of Drupal development on virtual machines or Docker containers (instead of crufty old MAMP/WAMP-based development).
It will install the following on an Ubuntu 16.04 (by default) linux VM: Apache or Nginx, PHP7+, MySQL5+ and optionnaly Solr, Elasticsearch, Varnish, Selenium, Redis, MaiHog, ...
PHP built in server
If you already have PHP and MySQL installed (not even Apache), you can still rely on the PHP built in server. Do not expect performances, but for fast tests it should do the trick if you do not want to vagrant provision / reload.
You should install manually solutions like MailHog or Mailcatcher to prevent sending mail to real users, Xdebug, ... or change your mind for DrupalVM.
MAMP (MacOSX), XAMPP (Windows and Unix)
Not a personal favourite, but could be used as a starting point if you are not familiar with the command line.
Most of the time, this command will do the trick
drupal site:mode dev
Drupal comes with great caching for production, but before you start development tasks, there is some configuration to prevent caching.
Displaying the Twig templates used by regions, blocks, nodes, ... is just one variable away in the development.services.yml.
Then cache rebuild
After, with Twig debug enabled
This is described in deep + other Twig techniques on the following links from Drupal.org.
- Debugging Twig templates
- Discovering and Inspecting Variables in Twig Templates
- Using attributes in templates
Test emails and prevent them to be sent to real users
Devel, Devel Generate Kint and Webprofiler modules
They all come with the Devel module.
- Devel - Helper functions for Drupal developers
- Devel Generate - Accelerate development of your site or module by quickly generating nodes, comments, terms, users, and more. See also the Demo Content module below.
- Kint - pretty print of variables with.
- Web Profiler - Port of the Symfony WebProfiler Bundle as a Drupal 8 module, do not use the standalone module, it is now part of the Devel module. Just FYI, see also the new 3.1 Symfony debug toolbar.
Improves the the default Toolbar, comes with two modules: Admin Toolbar and Admin Toolbar Extras Tools.
The Examples for Developers project aims to provide high-quality, well-documented API examples for a broad range of Drupal core functionality.
The demo_content module lets you import demo content entities from YAML files. It has support for modules, profiles and themes. It can create and update any content entity types: nodes, blocks, files, images, taxonomy terms, menu links..etc.
See example module and theme: https://github.com/arshad/demo_content_examples
Configuration management (you can also find former references to the term CMI), will allow you to export your configuration (content type and vocabularies structure, modules settings, ...), but not the content. It is provided by the Drupal core.
In Drupal 7, it was the role of the Features module. In Drupal 8, you should avoid the Features module for that use case
In Drupal, configuration is the collection of admin settings that determine how the site functions, as opposed to the content of the site. Configuration will typically include things such as the site name, the content types and fields, taxonomy vocabularies, and so on.
You can use Drush for configuration export (
drush cex) and import (
drush cim) or the UI.
Configuration management is a vast topic, it will be covered on a dedicated post, but you can find plenty of good resources.
Just make sure that you use the 'config' storage directory outside of the files directory (default configuration that can be changed in sites/default/settings.php) so you can version it.
- Configuration management (Drupal.org documentation)
- Advanced Configuration Management with Config Split et al. (Drupal Dev Days Seville 2017)
- Deploying Drupal: Patterns and Antipatterns (Drupal Dev Days Seville 2017)
Here is a September 2017 presentation about the specific case of sharing and overriding configuration in a Drupal 8 multisite by Jan Lemmens.
PHP Code Sniffer
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
- Drupal coding standards
- Install PHP Code Sniffer and Command line usage
- Configure Code Sniffer under PHPStorm
PHP Standards Recommendations (PSR's)
The PHP Standard Recommendation is a PHP specification published by the PHP Framework Interop Group. Similar to Java Specification Request for Java, it serves the standardization of programming concepts in PHP. The aim is to enable interoperability of components and to provide a common technical basis for implementation of proven concepts for optimal programming and testing practices. The PHP-FIG is formed by several PHP frameworks founders.
Each PSR is suggested by members and voted according to an established protocol to act consistently and inline with their agreed upon processes.
PHP: The right way
There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and insecure code. PHP: The Right Way is an easy-to-read, quick reference for PHP popular coding standards, links to authoritative tutorials around the Web and what the contributors consider to be best practices at the present time.
Drupal 8 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.
Simple Test, PHP Unit and Behat
Pieter Frenssen provides great learning material about testing:
- Getting up to speed with testing on Drupal 8 Workshop from Drupal Dev Days Seville 2017 by pfrenssen
About PHPUnit, Behat, Travis CI and Phing.
On GitHub: Fork of Drupal Composer template for CI that includes Behat and Travis, Behat examples used by the EC
- Testing small to medium sites with Behat
Blackfire empowers all developers and IT/Ops to continuously verify and improve their app’s
performance, throughout its lifecycle, by getting the right information at the right moment.
Heatmaps, Visitor Recordings, Conversion Funnels, Form Analytics, Feedback Polls and Surveys in one platform.
"API's" points to a non-existing url ( https://drupalship.org/drupal-api )
Thanks for the review, fixed.