D8 - Same As It Ever Was
Updated: May 30, 2019
Drupal 8 is new and really different from Drupal 7. The documentation on drupal.org isn’t complete or thorough yet, and most of the blog posts I’ve come across are from 2014 or 2015 and are obsolete.
I’m going to give some tasks and examples the way we’d do them in Drupal 7 and then how we do them in Drupal 8. We’ll assume you already have a Drupal 8 install up and running - that is pretty well documented and easy. I’m using the Standard install profile.
Our pretend application will be a very simple auto insurance quote generator. We’ll need some permissions, form alters, AJAX forms, config entities, custom content types, and lots of other things I’m sure we could just whip out in Drupal 7 that might give us trouble in D8.
We’ll start with creating a module. This is pretty well documented, but in the interest of being thorough, we’ll go start to finish in D8.
First, install Drupal Console [https://drupalconsole.com/]! It’s wonderful and helpful and, frankly, with all of the configuration that Drupal 8 needs, I can’t imagine how irritating it would be having to set everything up without it. Due to overlapping Composer dependencies, remember to install your Drupal Console before installing any modules or themes, otherwise you might need to delete your composer.lock file and vendor directory and run a composer install to set the dependencies up correctly.
I like to change my sync directory in Drupal 8 to /sync so that I don’t have to worry about anything going on in sites/default/files (where it goes by default). Also, it makes .gitignore easier to set up!
We might need to add a custom role to our module. For this example, we’ll need an “agent” role.
Now we have a module with a custom permission and a custom role. Next, we’ll add a custom content type and make some alterations to its form.