Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.23 KB

4.4-essential-apis-configuration.md

File metadata and controls

44 lines (31 loc) · 1.23 KB

Configuration API

The configuration API is for storing and sharing system settings across environments. For local variables that shouldn't travel across environments (such as cron last run time), use the State API instead.

See the Configuration Management section for more details about managing configurations.

Reading from the config:

<?php
//Immutable Config (Read Only)
$config = \Drupal::config('system.performance');
$message = $config->get('message');

$page_cache = \Drupal::config('system.performance')->get('cache.page');
?>

Writing to the config:

<?php
//Mutable Config (Read / Write)
$config = \Drupal::service('config.factory')->getEditable('system.performance');

// Set a scalar value.
$config->set('cache.page.enabled', 1);

// Set an array of values.
$config->set('cache.page', ['enabled' => 1, 'max_age' => 5]);

// Save your data to the file system.
$config->save();
?>

Additional Resources