Upgrading A Drupal 7 Module to Drupal 8 - The Info File

User External Invite Module Listing Page

I recently started trying to become more involved in the open source ecosystem. Previously, I had used a lot of community code and modules, but I didn't contribute much due to my lack of knowledge and expertise and not knowing where to start. Luckily, I started a job where I had a manager who maintained several modules and gladly gave me the reigns of one of them to maintain.

The module, User External Invite, is a simple module that allows you to invite users to a site that uses an external authentication method, and once they log in for the first time, they are granted their appropriate role. We used this module in our production service and thought it could be used by others, hence the d.o contrib project. 

While we still use Drupal 7 in production, like most other universities running Drupal, we are starting the Herculean effort of porting our whole 100+ module distribution to Drupal 8. Since the invite module is a fairly simple one with a couple of basic dependencies that are already ported or in D8 core, porting the module seemed like a good place to start. 

The Info File

It seems like most tutorials explaining how to create a module, no matter what version of Drupal, start out with the info file. This file used to be named your_module.info, but in Drupal 8 the format has changed to YAML and the filename looks something like your_module.info.yml. Porting your info file is probably the easiest part of the process. In Drupal 7 my info file looked like:

name = User External Invite
description = "Allows users with permissions to assign a role and email invitations to other users. Requires external authentication."
core = 7.x
dependencies[] = token
dependencies[] = entity

configure = admin/config/people/invite

And in Drupal 8:

name: User External Invite
type: module
description: 'Allows users with permissions to assign a role and email invitations to other users. Requires external authentication.'
core: 8.x
configure: user_external_invite.settings
 - token

One of the new parts of the info file you'll notice from above is the "type" key. You need to include this line in your info file with a value of either "module" or "theme" or "profile". When Drupal is building a list of modules, it parses through info files looking for this key.

I originally thought the change might be because modules might be able to be discovered in other directory structures, but by default, that wasn't the case. I still had to place my module in the modules folder for it to be auto-discovered. The modules folder has moved from /sites/all to just /modules, and while I'm sure there are options for more site configurations of module paths, I'm sticking to the defaults.

Just like in Drupal 7, remember not to put the packing information into your Git repository. I have made this whoopsie a few times, and it will confuse the update manager causing your users to miss updates. Once your module is uploaded and packaged for release, the packaging script will add something like the following: 

# Information added by Drupal.org packaging script on 2016-12-07
version: '8.2.4'
core: '8.x'
project: 'drupal'
datestamp: 1481136831

One thing that confused me at first was where the JS/CSS loading of assets went. You can no longer load those assets in module info files but you can curiously load them in theme info files. The loading of assets for modules has been moved to module_name.libraries.yml file which we will discuss later. 

You can find out more about setting up your Drupal 8 info file in the Drupal 8 docs: https://www.drupal.org/node/2000204.


The Drupal 7 version of User External Invite lists two dependencies: Token and Entity API. Most of the functionality in the Entity API module has been moved to Drupal 8 core with the rest being worked into core during point releases. 

I was going to give you a quick recap of whether or not I needed to include the D8 version of Entity API in my module, but after a few hours of going down a rabbit hole, I'll leave you in suspense until a future post in this series. I definitely know I'll still need the Token module, and so I will be using its codebase frequently as an example for porting my own module to D8. 

Module Listing Page

After saving your info file, you should see your module show up in the "admin/modules" path which is under an "Extend" menu item displayed with a puzzle piece icon. Since it's the only verb in the top-level admin menu, I'm not sure on the name change from modules to extend, but I do agree with the puzzle piece icon. One day Drupal 8 will be less of a mystery to me, but until then I'll keep trying to piece the puzzle together and report to you what I find.