First Impressions of the Drupal Console
One such tool is the Drupal console. Drupal console provides a command line interface (CLI) to perform actions and get information about our site. I would be surprised if it doesn’t make it into the list of “must-have tools” for most developers once D8 is released.
Most of my newfound interest in Drupal console came from watching Ryan Weaver’s session at DrupalCon LA about the Drupal 8 Lifecycle. He did an excellent job of showing how to debug much of Drupal using the console and other tools, so I encourage you to check out the video of his session.
### What is it for?
There seems to be a lot of confusion about why we should use the Drupal console when there is also Drush. So what’s the reason? It seems to be primarily the fact that the Drupal community built D8 with Symfony, which already has console component. It makes perfect sense to extend the Symfony console components to build Drupal console. With that said, let’s compare Drush and the Drupal console.
#### Drush strengths and common tasks
- Manage environments via aliases
- Import/export databases
- Merge file systems with rsync
- Update variables
#### Drupal Console strengths and elementary tasks
- Generate code
- Debug routes, services, rest resources and much more
#### Drush and Drupal Console shared strengths
- Manage modules
- Rebuild cache
- Manage configuration
The above list is by no means comprehensive, but I think you can see that despite the overlap, they do different things. I’m not saying that Drupal console couldn’t or won’t implement the same features as Drush, but for now it looks like we will probably be using both. In fact, there is even a Drupal console command to run a Drush command. It’s still not clear to me why you would want to do this, but I’d imagine it has something to do with writing scripts that use Drush commands.
Drupal Console Highlights
Developers hate repeating themselves. Despite that, we write the same base code every time we want to create a new module, entity, form, etc. Drupal console puts an end to this and gets us up to speed with the rest of the development world. We now have the option, with some simple commands, to generate all of these things and much more. Want to create a new module? Simple, just run `drupal generate:module`. How about a new config form? `drupal generate:form:config`.
The Drupal console is especially great for D8 because along with the compelling new architecture comes extra base code that would be a pain to type every single time.
Debugging Drupal 8 could be a series of posts in itself so I won’t get into much detail here. I think it’s enough to say that Drupal console gives us exact ways to see what’s going on on our site. If you look through the list of commands provided by Drupal console, you’ll notice that nearly every command has a ‘:debug’ option.
Some examples of things you can do are as follows.
List all modules
[prism:bash]drupal module:debug[/prism:bash] List all routes and the path to their class
[prism:bash]drupal router:debug[/prism:bash] List all configuration files for the site
If you try running any of these, you’ll notice that the output is somewhat long, even on a fresh install. The long length is because the Drupal console is showing everything for the entire site. Such an in-depth debugging could be useful, but there’s a good chance we want to see only the things related to a particular keyword. For instance, what if we need to see all configuration files related to views? We can do this by running any of these commands through the bash “grep” command. The bash "grep" command just lets us filter the results based on a keyword we enter. Let’s give it a shot.
[prism:bash]drupal config:debug | grep views[/prism:bash] ![Drupal Console debug output][Drupal Console debug output]
Now we have a much more focused list of files that relate only to views. You can see how the debug commands combined with the grep gives us a lot of power to get quickly the information we’re looking for when building sites.
The Drupal console is a very powerful tool that gives us the ability to quickly view information about our site, generate new code, manage our configuration and much more. It’s still very new, so I would expect the Drupal community to add more features in the near future. Personally, I think using it now can help speed up development by letting us write less and do more.
- [http://drupalconsole.com/](http://drupalconsole.com/) - [https://events.drupal.org/losangeles2015/sessions/routes-controllers-and-responses-basic-lifecycle-d8-request](https://events.drupal.org/losangeles2015/sessions/routes-controllers-and-responses-basic-lifecycle-d8-request) [Drupal Console debug output]: /sites/default/files/drupal_console_debug_output.png