This presentation introduces the Drupal 8 configuration management system (CMI). Learn why configuration management is one of the most eagerly anticipated features of Drupal 8, and how it has the potential to completely change the workflow we use for building sites with Drupal. By addressing a number of long-standing issues in Drupal, CMI helps to separate content from configuration, provides a simple user interface for transporting configuration changes between multiple instances of the same site, and gives developers a consistent way to store and retrieve configuration in their code that is guaranteed to work with the rest of management tools provided.
Here's what we'll cover in this presentation:
- What is configuration management, and what problems does it solve
- The CMI user interface, and changes for site-builders
- The CMI API, and changes for modules developers
- What you can start learning now to ensure you're ready to use CMI
13. Content An article page, uploaded files
Session
State
Configuration
Logged in status, shopping carts
Last cron run
Everything else
14. Challenge
• Developer:
• Wants to work on code
• Wants to change the config
• Wants to deploy across environments
• Client:
• Wants to work on content
• Doesn’t want to lose work
16. Current Situation
Drupal 7 Configuration
How do we currently manage configuration in Drupal?
• Features
• Install/Update hooks
• Install Profiles
17. Current Situation
Features
• Features ‘Overridden’ sadness
• Adding Features support for modules is not easy
• Export and import of certain configurations as modules
19. Current Situation
Install Profiles
• Combine Features modules and install hooks
• Full site setup out of the box
• Limited Drupal API available
• Doesn’t always work as planned
21. Drupal 8 CM
Configuration Management
• Move configuration management into core
• Allow storage of configuration in files
• Allow the transfer of configuration between environments
• Create an API to allow custom configurations
• Integrate UUID into core so certain configurations can be given machine names
34. Drupal 8 CM
Behind The Scenes
• Active configuration is stored in the database
• Clicking Export collates the configuration that each module
defines and combines it with the current active configuration
• Export contains the active configuration in the form
of YAML files
35. Drupal 8 CM
Behind The Scenes
• YAML files are used to store the configuration
• Used to store and compare the current configuration
• By default the directories are stored in the location /sites/default/files/
config_<hash>/
38. Configuration API
Configuration Schema
• Needed to define what your configuration will hold
• Used to define what types of data the configuration will contain
• See more at: https://drupal.org/node/1905070
40. Configuration API
system.schema.yml
Schema name
- Used to reference this configuration
- Also shows the configuration filename
“system.site.yml”
system.site:
type: mapping
label: 'Site information'
mapping:
uuid:
type: string
label: 'Site UUID'
name:
type: label
label: 'Site name'
41. Configuration API
Container data type
- ‘mapping’ is for key value sets
- allows for associative arrays of
different data types
system.site:
type: mapping
label: 'Site information'
mapping:
uuid:
type: string
label: 'Site UUID'
name:
type: label
label: 'Site name'
system.schema.yml
42. Configuration API
system.site:
type: mapping
label: 'Site information'
mapping:
uuid:
type: string
label: 'Site UUID'
name:
type: label
label: 'Site name'
Label
- Used as an interface label
system.schema.yml
44. Configuration API
Simple Configuration
• Can be single values or arrays of values
• Used to store global configuration options
• Easy to implement:
• Create schema YAML file in
< module >/config/install/schema
• Create config YAML file
< module >/config/install
48. Configuration API
Configuration Entities
• Used to store custom entity configurations
• More complex and therefore harder to implement
• Used for configurations that have multiple entries
Example: Views, Image cache settings, Contact form
categories
49. Configuration API
Contact Category Interface
namespace Drupalcontact;
use DrupalCoreConfigEntityConfigEntityInterface;
/**
* Provides an interface defining a contact category entity.
*/
interface CategoryInterface extends ConfigEntityInterface {
}
51. Configuration API
class Category extends ConfigEntityBase implements CategoryInterface {
/**
* The category ID.
*
* @var string
*/
public $id;
/**
* The category label.
*
* @var string
*/
public $label;
/**
* List of recipient e-mail addresses.
*
* @var array
*/
public $recipients = array();
/**
* An auto-reply message to send to the message author.
*
* @var string
*/
public $reply = '';
/**
* Weight of this category (used for sorting).
*
* @var int
*/
public $weight = 0;
56. Configuration API
Workflow
• Staging config should become part of your
codebase
• New configuration changes should be exported
and integrated into code base
• Configuration in code should then be used to move
configuration between servers