ComputerMinds Config tools

Categories

Component ID

2803125

Component name

ComputerMinds Config tools

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

1795

Component created

Component changed

Component body

Provides advanced configuration management workflow functionality, based around ComputerMinds' intended config management workflow.

Inspired by a combination of PreviousNext's Drush CMI tools, Configuration Synchronizer, Configuration development and Configuration Update Manager.

Usage

Drush

drush cm-config-tools-import.
drush cm-config-tools-export.

See drush help cm-config-tools-import and drush help cm-config-tools-export for full details.

PHP

(For example, from an update hook)

// Import configuration from all projects that contain a 'cm_config_tools' key.
Drupal::service('cm_config_tools')->import();

// Export configuration.
Drupal::service('cm_config_tools')->export();

Documentation

Configuration can be exported to code from active storage using the cm_config_tools module. This workflow allows precise control over what config to export, although it does require you as the developer to find and decide exactly what to export.

Note that the drush config-devel-module-dependencies command mentioned below requires the config_devel module and a patch. Development on a solution within cm_config_tools is underway.

  1. Including config in a module

    Add config items names to the managed subsection of a cm_config_tools section of your install profile's .info.yml file or a specific module's .info.yml file (creating it if necessary).

    See the Choosing config to export section below, but once you have added some basic items (e.g. at least a node type), running the following may suffice to suggest what related config you might need:

    drush config-devel-module-dependencies MYMODULE --active=1 --direction=both

    This lists anything that is dependent on the config you have already listed (e.g. field instances for a node type), as well as the dependencies of that (e.g. field storage config, but also view mode settings). So copy the config you want to export into that managed section.

    Dependencies will get added where necessary when exporting.

    Note that you may want to run that drush config-devel-module-dependencies command again when done to check there are not more config names you should list for export.

  2. Exporting config

    Once all the configuration you want exporting is added to the .info.yml file, enable the module and then run:

    drush cm-config-tools-export

  3. Reverting config

    To replace configuration with what is in code, run the following:

    drush cm-config-tools-import

    Or from PHP (e.g. in an update hook or /devel/php):

       // Import configuration from all projects containing a 'cm_config_tools' key.
       Drupal::service('cm_config_tools')->importAll();
    
  4. Deleting config

    Config can be deleted as part of the drush cm-config-tools-import command. Specify items to delete under a delete section within the cm_config_tools section in a module's info.yml file. Then run that command.

    Alternatively, deleting individual configuration can be done separately, for example:

    drush config-delete 'field.field.node.article.body'

    Or from PHP (e.g. in an update hook or /devel/php):

    Drupal::service('config.factory')->getEditable($config_name)->delete();
    

Replace 'MYMODULE' in these with your module name, or the name of the install profile.

Features and other configuration workflows

This module is probably not compatible with other configuration-managing projects. It is loosely based on old workflows used with the Features project in Drupal 7. With Features, creating a module is often done through the admin UI, which allows easy selection of what to export to a module. Unfortunately, this step is just a bit more manual with cm_config_tools as you have to create your module's .info.yml yourself (but with the help available). The equivalents of drush fuand drush fr are drush cmce and drush cmci, respectively.

This approach provides more control than synchronizing a complete directory of config, allowing only specific config to be controlled.

Choosing config to export

It is the developer's responsibility to be aware of what configuration should be exported to a module, but here is some help! Start by adding items you know you want, such as node.type.article. Then run the following drush command, which will list anything that is dependent on the listed config, and all the dependencies:

drush config-devel-module-dependencies MYMODULE --active=1 --direction=both

Other related configuration might also be found by running:

drush config-list | grep 'article'

Note that there could still be other config items that may reference articles without being named after them, so you could try querying the config table with SQL like this:

SELECT * FROM `config` WHERE `data` LIKE '%article%';

Drush command aliases

drush cmce is the alias for drush cm-config-tools-export.
drush cmci is the alias for drush cm-config-tools-import.
drush cd-md is the alias for drush config-devel-module-dependencies.
drush cdel is the alias for drush config-delete.

About the Developers

This project is currently maintained by developers at ComputerMinds - visit us at http://www.computerminds.co.uk. We at ComputerMinds pride ourselves on offering quality Drupal training, Drupal development and Drupal consulting. Go Drupal!