Lead Image © iofoto, fotolia.com

Lead Image © iofoto, fotolia.com

Drush vs. Drupal Console

What's the Dif?

Article from ADMIN 34/2016
By
Let's take a stroll through the brave new world of Drupal 8, now with Drupal Console; lowering the learning curve for the newbie and the seasoned pro alike.

We have officially entered the world of Drupal 8. With it comes both the old and the new, and in the new category there is a fresh command-line tool for developers. It's called Drupal Console . There are a lot of questions about it, like the ones you just asked yourself: "What happened to Drush?" "Why do I need to switch to Drupal Console?"

Do not fret, I'm here to help. I'll explain the similarities and differences between the two. I'll also show you a few new things that Drupal Console brings to the table to improve your developer experience in the Drupal 8 era.

Drupal [1] is an open source content management system (CMS) that powers some of your favorite websites. Drush [2] and Drupal Console [3] are both command-line tools that interact with an existing Drupal installation or help you get one up and running. Both of these tools help developers increase their productivity by reducing the time it takes to do the same tasks without them. They are extensible with custom-written commands and personalization of configuration files. Beyond that, these two tools begin to diverge from each other ever so slightly.

The shift in Drupal 8 to the Symfony framework [4] has made things different, much different even to the veteran Drupal developer. Drupal Console is written with both the veteran and the new-to-Drupal developer in mind. Its primary purpose is to assist a developer's transition to the world of Drupal 8, and it is only intended to be used with Drupal 8 – mainly for development reasons, much less in the context of a production website.

What does this mean for Drush? Well, not too much. Drush still functions much like it always has, and is still deeply part of the Drupal ecosystem. In the areas that the two overlap, I would recommend using whichever one you are more comfortable with. But before you form an opinion let's get Drupal Console installed and take it for a spin.

Installing

Getting console installed is easy. If you have curl installed, you can get Drupal Console running with these three commands:

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

Once installed you can run the init command to load some basic configurations in your user's ~/.console folder. These configuration files will allow you to add a personal touch to your environment once you know how you want console to behave. For the purpose of this article, go ahead and run the init command now.

drupal init --override

Great, now you have a fully working version of Drupal Console. You can output a list of available commands at any time by running:

drupal list

You can also use the help command to get more information on the usage of any commands. For example you could ask for help like this:

drupal help site:install

Getting Started

Let's get to the fun stuff, shall we? You're going to need an active Drupal 8 site to work in. If you don't already have one installed, I recommend just using the built in Quick Start script that was provided when we ran the previous init command. Do it like this:

drupal chain --file=~/.console/chain/quick-start.yml

This command will download Drupal 8, launch a web server, and then install Drupal. Console will report back once your temporary site is ready to use.

Now that you have a working site lets try some of the commands. Similar to Drush, you can use Drupal Console to interact with a working Drupal site. You can download and install modules, get a database dump, even export and import configuration.

Just to get comfortable lets do something easy: We'll download the Devel module and install it. Make sure you are in the Drupal root folder and then run these two commands:

drupal module:download devel
drupal module:install devel

That's it!

Generate Command

Now for what I'm most excited about: the generate command. Generate will help you write a custom module by creating a starting point from boilerplate code. Think along the lines of "just add [a Drupal drop of] water" development. From the root of your working Drupal 8 site, run this command to begin the process of creating a new custom module:

drupal generate:module

Console will prompt you with several questions that will assist you in setting up the skeleton of this new module. It asks you for things like the module's name, description, path, and even your new module's dependencies. This "setup wizard" has smart defaults and in most cases you can just press enter all the way through. Once that's complete you're on your way to writing your module, unless of course you want a little more help. All you need to do is ask.

Much like the generate:module command, you can fire similar commands to help fortify your newly created module. For example, if your module needs to output a form, use the command drupal generate:form, and you'll be guided into setting up that structure in your module. Need some help creating a rule? Use drupal generate:plugin:rulesaction to get started. Generate helps you create pretty much anything: permissions, form alters, rules, field formatters, etc. Plus, it's not limited to just generating modules. You can create themes and install profiles as well.

Drupal Console is truly impressive. Kudos to the maintainers and contributors of this project. It provides a low entry point to the Drupal 8 learning curve. It gets a developer up and running much faster. Even after becoming proficient at writing modules or themes, it just makes sense to keep using a tool like this.

Less time doing redundant tasks and more time enjoying what the world of Drupal 8 has to offer!

The Author

Jeremy Rasmussen has enjoyed solving problems using Drupal since 2008. He works for Lever Pulley in Salt Lake City, Utah, as the Director of Web Development. When he's not building something with Drupal, he's usually riding a bike, playing with the dogs, or enjoying life from a hammock.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus