Drupal Utilities: Drush, Composer and Drupal Console
Hello everyone! Today I wanted to talk to you about some utilities that I have used for Drupal and I consider, today, indispensable and very useful for development in the CMS.
Composer
Composer is like cheese to a mouse, but that mouse being Drupal. It is a dependency management tool in PHP. It allows us to declare libraries that our project needs to download, update or delete them in a very simple way. Drupal 8 already uses composer in the core to manage dependencies, but it is possible to use composer for the entire project as we will see below. In summary, composer is capable of downloading the most current versions (or those that we specify) of the libraries that we indicate, in addition to their dependencies.
Facility
- To install composer we will do it by executing the following command.
curl -sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/composer
- If we have installed drupal from drupal-project, it will come directly to us with composer installed and ready to use throughout our project.
composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
Drupal-project is nothing more than a template made in composer, which downloads the libraries and dependencies used by the version of Drupal specified in the command.
Honestly, with what I have been using Drupal for, I see composer as something essential when facing a project. It saves us time and headaches, avoiding version incompatibilities between libraries and other third-party libraries, etc. With composer we have control, from a single file, composer.json. Well, actually there are 2 ;)
Drush
Along with composer, it is one of the tools that I have used the most. Drush is a command line tool that allows us to maintain our beautiful drupal site. It is a fast alternative to navigation through the UI, avoiding the slow and continuous use of the mouse. It has a looong list of commands, very well documented for most tasks. We can also create our own commands to perform more complex tasks.
InstalaciΓ³n
- Through the official website: http://docs.drush.org/en/master/install/
- Using composer:
composer global require drush/drush sudo ln -s ~/.composer/vendor/drush/drush/drush /usr/bin/drush
If we have installed drupal from drupal-project, it will come directly to us with the installed tool.
Examples
- drush in file_version # We install a module
- drush pmu file_version # We uninstall a module
- drush cr # Empty the caches
- drush updb # Update the database
- drush uli # We get auto-generated login link
Drush is that tool that you use so many times that if they take it away from you, the world would collapse on you. It saves us a lot of time by avoiding using UI constantly.
Drupal Console
It is another command line tool, based on the Symfony console . The drupal console makes our lives easier when performing certain tasks, whether generating PHP, YML, as well as other types of files, saving us development time. One of the facilities it offers that caught my attention the most was the automatic creation of modules. Obviously, it does not create a module out of thin air (maybe in a few millennia...), but it does create the entire directory and file path, including the xx_module_name.info.yml file. It is worth stopping by its documentation , translated into multiple languages, and taking a look.
Facility
- Global installation with composer
composer global require drupal/console
Like Drush, this utility comes installed with drupal-project.
Examples
- drupal -V # Drupal Console Version
- drupal generate:module # We generate structure of a module
- drupal database:drop # Drop all tables from a database
- drupal site:maintenance # Switch to maintenance mode
Drupal Console is a tool that has a lot of potential, although it is true that I have not yet used even 10% of its full potential. It takes away heavy and repetitive tasks such as database management.