PHP API

Defining a schema for your configuration is not only for Drupal's internals, it may also help you while writing a custom module. For example, you might like to get the data type of a configuration object (say, for validation purposes or to print out information about the type).

In addition to the already known \Drupal::config($name) to load a single configuration object, there is \Drupal::service('config.typed'). Using this function, you can access the definition of a configuration object's data structure.

To load the type definition of, for example, system.maintenance, we could use the following code:

<?php
$definition = \Drupal::service('config.typed')->getDefinition('system.maintenance');
?>

This would result in an array that contains the ...

Get Drupal 8 Configuration Management now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.