Skip to main content

Installing Module Structure for Drupal 8 with Console

Drupal console is a CLI (Command Line Interface) tool created to facilitate some complex operations. It works with interactive commands given from the command line. A Drupal 8 module requires a certain folder structure and the existence of certain files. We will use the drupal console to create the folders and files needed for a module.

Installing Drupal Console Using Composer

The installation described here was done on Ubuntu 18.04. First, let's do a general update with the composer update command:

First, after moving to the Drupal 8 folder, let's install the drupal console by giving the command:

composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader

Now let's run the commands below for installing Drupal Console Launcher:

curl https://drupalconsole.com/installer -L -o drupal.phar
mv drupal.phar /usr/local/bin/drupal
chmod +x /usr/local/bin/drupal

If everything went well, we should now have a command called drupal:

waiting

Now let's go back to our root folder and run the command:

drupal generate:module \
--module="turna" \
--machine-name="turna" \
--module-path="modules/custom" \
--description="Turna Util" \
--core="8.x" \
--package="Turna" \
--module-file \
--composer \
--test \
--twigtemplate
waiting

When we complete this process, our module will be ready to use.