
So we enter "yes".ĭo you confirm generation? (yes/no) :Ĭongratulations! You have just created your first console command in Drupal 8. Since we want to create user roles with our command, there should be a Drupal site. Is the command aware of the drupal site installation when executed?. However, it makes sense to add our command to the "user:role" namespace, so enter "user:role:create" and continue.Įnter the Command Class. It will add a console_command_demo section to your commands when you run drupal list. You should namespace your command with the module machine name followed by a word that best describes your command. :Ĭonsole_command_demo:default has been suggested.

console_command_demo) and hit "Enter".Įnter the Command name. Next we generate a command with: drupal generate:commandĮnter the machine name of the module you created a while ago (e.g. You can do without module file, feature, composer.json, dependencies, unit tests and template. You may wish to give it a better description. Enter "Console Command Demo" and accept the suggested machine name console_command_demo. We are going to do that the DrupalConsole way by running drupal generate:module, which will take us through interactive prompts. So, the first thing we need to do is create a module. In Drupal, a command is a PHP class that lives in a module. Would it not be nice to be able to create new roles from the command line too? That is exactly what we are going to do next, in order to help us understand a bit more about what makes up a command. The last one is user:role Adds/removes a role for a given user. If you run drupal list | grep user: you will see a list of user-related commands. Preferably, you should have read our introductory article.įrom the command line, change directory to the root of your site. This article assumes you have installed the DrupalConsole Launcher and Drupal 8. A console command should be as light as possible and not attempt to do too much. The DrupalConsole Launcher executes console commands from the terminal.
#Drupal console code#
As we have seen in our Introduction to DrupalConsole, it is designed for generating boilerplate code and interacting with a Drupal site.
#Drupal console install#
For details read the Drush install documentation page.DrupalConsole is a great CLI tool for Drupal 8.
#Drupal console how to#
How to Install Drushĭrush is just a PHP library and can be installed using Composer. You can use it to interact with a Drupal site and generate boilerplate code.

How to Install Drupal Consoleĭrupal Console can be installed into your Drupal site using Composer, follow the instructions over on the Drupal Console documentation page. With a few simple commands you can create a module or a custom entity type. One of its many strengths is the ability to generate boilerplate code. Drupal Console is a CLI tool for Drupal built using the Symfony Console library.
