Developing for Features 3.x

Last updated on
17 September 2018

Features 3.x supports two types of plugins. The most straightforward way to extend the module's functionality is by creating a new plugin or extending an existing one.

Plugins have access to the public methods declared in FeaturesManagerInterface.

Assignment plugins

Assignment plugins control the configuration packaging process. They can do tasks including:

  • Create a package. See FeaturesManagerInterface::initPackage().
  • Assign configuration to a package or the install profile. See FeaturesManagerInterface::assignConfigPackage()
  • Unset configuration to prevent it being packaged.

Assignment plugins may have a configuration form.

Steps to write an assignment plugin include:

  • Write the plugin file. See the plugins that ship with the module for models to work from, such as the FeaturesAssignmentBaseType plugin. The plugin must include an assignPackages() method.
  • If the plugin requires configuration:
    • Write a configuration form. See AssignmentBaseForm for an example.
    • Add a routing for the form to a .routing.yml file. Example:
      features.assignment_base:
        path: '/admin/config/development/configuration/features/bundle/_base/{bundle_name}'
        defaults:
          _form: '\Drupal\features_ui\Form\AssignmentBaseForm'
          _title: 'Configure base package assignment'
          bundle_name: NULL
        requirements:
          _permission: 'administer site configuration'
    • Edit the plugin's annotation to specify the configuration route. Example: config_route_name = "features.assignment_base".
  • If you're contributing the plugin as a patch:
    • Regenerate the default bundle configuration to enable and/or set the default weight of the plugin as well as adding any configuration for the plugin.
    • Note that while a configuration form and related code like the routing go into Features UI, the assignment plugin itself and its configuration go into Features.

Generation plugins

The second type of plugin is for generating the packages along with their assigned configuration and an optional install profile.

Two generation plugins ship with Features, one to generate an archive and the other to write packages to the file system.

In the unlikely case that an additional generation plugin is needed, the steps for writing one are similar to those for writing one for an assignment plugin except that there are more required methods. See the existing plugins for examples.

Help improve this page

Page status: No known problems

You can: