Book Image

Drupal 8 Configuration Management

Book Image

Drupal 8 Configuration Management

Overview of this book

Table of Contents (16 chapters)
Drupal 8 Configuration Management
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

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 following structure:

<?php
$definition = array(
  'label' => 'Maintenance mode',
  'type' => 'system.maintenance',
  'class' => '\Drupal\Core\Config\Schema\Mapping',
  'definition_class' => '\Drupal\Core\TypedData\MapDataDefinition...