The Drupal Console is a suite of tools run from a command line interface (CLI) to generate boilerplate code and interact with a Drupal 8 or Drupal 9 installation. It's an essential tool for anyone writing code for Drupal.
Learn about the Drupal Console and what you can do with it.
Installing Drupal Console
To get up and running with Drupal Console, follow the instructions in the project's official documentation: Getting the project.
Tip: If you're running into difficulty installing Drupal Console with an existing site (and dependencies are not resolving), try passing the
--no-update flag, which will disable automatic updates of dependencies.
composer require drupal/console:~1.0 \ --prefer-dist \ --optimize-autoloader \ --sort-packages \ --no-update composer update
What does Drupal Console do?
For a complete list of commands run
drupal list, or view the documentation.
Drupal Console provides a number of commands for creating module scaffolding and boilerplate code. Generation commands will walk you through a set of interactive questions about what you want to generate. Then it will generate the required boilerplate to build the requested component. This can dramatically decrease the time it takes to write common components like plugins, services, or custom entity types.
Note: When using Drupal Console to generate a module or theme in Drupal 8+, you will need to edit the info file and add the
core_version_requirement key. For details, see Create an Info File for a Module and Describe Your Theme with an Info File.
Try out various Drupal Console's code scaffolding commands in the following tutorials:
- Create a Settings Form with a Module
- Define a New Plugin Type
- Create a Custom Content Entity
- Create a Configuration Entity
Interact with your Drupal installation
Drupal Console allows you to interact with your Drupal installation, from rebuilding caches, to listing routes, services, and modules, and interacting with the configuration management.
One of our favorite features is that Drupal Console will create lists of things like plugin types, events, and services available. Because it's being used in the context of your specific installation, that list will include options provided by any contributed modules not just Drupal core. This means the documentation provided by Drupal Console in the context of your site will be a bit more complete than what you might find online.
Learn to develop with Drupal
Drupal Console helps you learn to develop applications with Drupal. In addition to generating complex code, you can increase the verbosity of the code comments, to better understand the generated code and how to build on it, by using the
You can also use Drupal Console to explore the inner workings of your current installation using the
In this tutorial, we learned about some things you can do in a Drupal project with the command-line interface tool, Drupal Console.
Further your understanding
- Browse through the available commands and see if there's one that you could try out right now.