About the project
I just finished a fairly large project that involved using Drupal 8 as the CMS backend for a RESTFul API. Overall it was a fun project as I learned a lot more about Drupal 8 and microservices. The wait was definetely worth it and much of the rewrite had to be done if you were to ask me. Drupal 7 was and still is a great choice but it's definetely not going to something something as we move towards a decoupled/microserviced architecture that many other system are heading towards. I have many opinions on this but that's for another article.
By Drupal 8 adopting much of the Symfony framework it opened up the door to many programming patterns like Object-Oriented and enhanced it's functional experience. Not only that but it also introduces a number of tools that overall enhance and increase a developers productivity. Also, you can't work on a project without using any tools today and as a developer I enjoy working with new tools, it's 2016 c'mon.
The first type of tools I was looking for is a package manager just to deal with the package dependencies and other meta data. I'm a fan of package managers. I like NPM and the way it manages packages and it's versions but that's for Node.js. PHP has Composer and it's awesome. You might be thinking, "How are you going to use composer with Drupal 8?" Well there is this great repository call Drupal Packagist for Drupal 7 and 8 that provides all projects from Drupal.org as packages for Composer. With Composer + Drupal Packagist I can require a module and it will be downloaded into the right directory with just a one or two commands:
composer require drupal/devel:8.*
I can also update modules and Drupal.
composer update drupal/* drupal/core
Composer really helps manage project dependencies in a nice and clean way. One this to note is that Drupal Packagist is gettings replaced by the official Drupal.org repo. If you would like to get started with Composer and Drupal checkout the following articles:
- Using Composer to install Drupal packages through Drupal.org
- Quick Tip: Set up Drupal 8 with Composer
- Using Drupal 8 and Composer Contribute
Also, if you are starting a new Drupal 8 project check out the Composer template for Drupal projects. It's a nice template that has the basic composer.json paths for Drupal and other configuration that can save you time.
When I first started working with Drupal, which is just about two year ago, I didn't know about Drush. I was managing a site all through the admin UI which isn't a bad thing but definitely not the most efficient way. I learned about Drush a few months after that and all I can say is that it's AMAZING. Yes, Drush is a CLI which means you have to use the terminal/command prompt which you should be comfortable with anyway.
Do you want to enable a module and all of it's requirements? Well just simply run:
drush en cool_module -y
Let it run and after a few seconds you are done! It would take you a lot more clicks and minutes if you were to use the admin UI.
Do you want to backup your code, files, and database into a single file? Just run:
You know what I'm going to say but I'l say it anyways: Drush is amazing!
There are more commands that make managing a Drupal site much easier and efficient. I would highly recommend you use this tool if you are not already using it. Checkout the following articles to learn more about Drush.
- How to Setup Drush for Drupal 8
- Introduction to Drupal 8 Tutorial 2: Setting Up Drush
- Updating Drupal using Drush
And hmmmm you can install Drush using Composer!
The first few articles I read about Drupal Console were a little confusing for me. I saw it as a replacement for Drush which I didn't like because I like Drush a lot. After giving it a try I realized that it's not ment to replace Drush but to go hand in hand with it, they complement each other. They are both command line tools that speed up development and management of a Drupal site. Yes, there are commands that accomplish the same task with ease but not all. To start out with Drupal Console is only available for Drupal 8 unlike Drush that is compatible with Drupal 6,7, and 8. I found Drupal Console to be useful during the development of a site due to it's command set to generate modules, controllers, forms, and more. I was no longer creating these files manually. With a few commands I had a full working module with a controller, configuration form, and default configuration.
Generate a module
Generate a controller for our module
Generate a configuration form
With 3 faily simple commands we have a custom module generated ready to be loaded coded. You no longer have to Google the basic structure of a Drupal 8 module and spend endless hours just getting through the basics. Drupal Console solves that problem. I really enjoyed working with Drupal Console, it made my development workflow much more efficient and overall easier because I didn't know much about Drupal 8.
Like I mentioned before, it's compliments Drush and it overall completes my Drupal development workflow. With Drupal Console I can generate my custom modules and with Drush I can enable it. Pantheon has an article comparing the capabilities of both of these tools.
If you are not using Drupal Console I sugguest you start thinking about it. Checkout the following articles to learn more about it:
- An Introduction to Drush and the Drupal Console
- Drupal Console Documentation
- Drupal Console: An Overview of the New Drupal CLI
Git is not necessary just just for Drupal development but it's for sure an important tools. Git, if you don't already know it, is a distributed version control system. I won't go over the full features of Git or why you should be using but just how it fits into my workflow. You should read the Getting Started guide on the offical Git page.
With Git, I can easily track any code changes, revert back to any previous commit, branch off to do a quick fix or experiment, and so much more. On top of that there are tools that can be used with Git to test and deploy your code automatically. It makes working with code so much easier.
So how exactly does this benefit Drupal 8 development? The short answer is in many ways but for me the main benefit was with configuration management. Drupal 8 comes with a powerful configuration API that "provides a central place for modules to store configuration data. This data can be simple configuration like your site name, or more complex information managed with configuration entities, such as views and content types." This configuration can be easily sync from development to production using Git. The closes thing Drupal 7 had was the Features module which is great but nothing closed to what Drupal 8 offers.
Checkout the following articles to learn more about configuration management:
- Configuration API in Drupal 8
- Configuration Workflow for Drupal 8 Sites
- Drupal 8 Configuration Workflows
In a later post I will talk more about my workflow using these tools.
Overall I think Drupal 8 is a major step forward. The development tools and the overall experience of the content management system are much better than Drupal 7 in my opinion. It brings benefits to developers allowing them to extend the system and to content editor by giving them a much richer content editing experience.