Part 3: Out with Features, in with Configuration Management

This article is part of a series called Drupal 8 Development Deconstructed about custom development with Drupal 8.

We're now going to create our Taxonomy Vocabulary.

No More Features

In Drupal 7, we used the Features module to export a wide variety of configuration structures, including Taxonomy Vocabulary structures. For Drupal 8, we can utilize components built right into Drupal Core to accomplish the same thing: Configuration Manager.

To start, we'll create our Taxonomy Vocabulary through the User Interface.

Create the Gender Vocabulary

Log into your Drupal site through the user interface as the super user, and navigate to admin/structure/taxonomy:

Click the "Add Vocabulary" button.

  • For the "Name" field, enter "Gender".
  • For the "Description" field, enter "Gender options for Gen Person".
  • Click the "Save" button.

Click on the "Manage Form Display" tab.

  • Drag "URL Alias" down to the "Disabled" section
  • Drag "Description" down to the "Disabled" section
  • Click the "Save" button.

Navigate to the "Configuration Synchronization" page (admin/config/development/configuration).

You'll see two new configuration files available:

  • core.entity_form_display.taxonomy_term.gender.default
  • taxonomy.vocabulary.gender


You'll see the configuration files that contain the changes made to the site when the Gender Vocabulary was created.

Make a note of these two configuration files.

Export the Gender Vocabulary Configuration to our custom module

We'll use Drupal Console to export these configuration changes to our module.

Shell into your VM, and navigate to the Drupal root directory of your project.

Execute the following commands:
drupal config:export:single taxonomy.vocabulary.gender /
--directory=modules/custom/gen_gender_vocabulary/config/install

drupal config:export:single core.entity_form_display.taxonomy_term.gender.default /
--directory=modules/custom/gen_gender_vocabulary/config/install

After you execute these two commands, you will find two files located within your module directory, in the folder "config/install". Edit each of these files, removing the "UUID" from both of them.

Why remove the UUIDs?

In Drupal 8, one of the basic precepts of the configuration management system is that the site owns its active configuration. A module can provide default configuration settings by providing one or more configuration files stored in the module's config/install folder. When that module is enabled on a site, the default configuration data is imported into the site's active configuration, where it is then assigned a UUID by the site at the time of installation. This is important, because by importing your module's default configuration settings into the site configuration settings it means that subsequent changes to your module's configuration are not automatically imported into a site; these will have to be handled through a hook_update_N.