Speeding up Drupal 8 module creation using Drupal Console
Though Drupal 8 is technically advanced compared to its predecessor, writing a module involves a lot of boilerplate code. There were many gotcha moments when I forgot to add a namespace and got puzzling errors. Fortunately, all that code can be generated automatically using a tool called the Drupal Console. Drupal Console is another cool addition to the Proudly Found Elsewhere school of thought as it leverages the Symfony Console component to handle the CLI part.
Note that Drupal Console supports only Drupal 8.0.0-beta4 at the time of writing this.
Get the latest version:
$ curl -LSs http://drupalconsole.com/installer | php
Move it to somewhere convenient so that it can be used throughout the system:
$ mv console.phar /usr/local/bin/drupal
Go to the drupal root directory of any Drupal 8 beta4 setup and run:
d8$ drupal list Drupal version Drupal Console 0.5.2 - prod Usage: [options] command [arguments] Options: --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction (-n) Do not ask any interactive question. --bootstrap-file (-b) Path to Drupal bootstrap file (core/includes/boostrap.inc). --shell (-s) Launch the shell. --env (-e) The Environment name. (default: "prod") --no-debug Switches off debug mode. Available commands: cr Rebuild and clear all site caches. drush Run drush into console help Displays help for a command list Lists commands cache cache:rebuild Rebuild and clear all site caches. config config:debug Show the current configuration container container:debug Displays current services for an application generate generate:command Generate commands for the console generate:controller Generate controller generate:entity:config Generate EntityConfig generate:entity:content Generate EntityContent generate:form:config Generate ConfigFormBase generate:module Generate a module generate:plugin:block Generate plugin block generate:plugin:imageeffect Generate image effect plugin generate:service Generate service router router:debug Displays current routes for an application router:rebuild Rebuild routes
Drupal Console currently supports generating PSR-4 compliant code for plugins, controllers, modules, services, entities and forms.It also has basic debugging commands for listing current configuration and routes. Never write a Drupal 8 module from scratch again. Use Drupal Console instead!