Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Latest commit

 

History

History
49 lines (35 loc) · 1.38 KB

4.4-essential-apis-configuration.md

File metadata and controls

49 lines (35 loc) · 1.38 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();

// Or 
 $config = \Drupal::configFactory()->getEditable('system.performance')
      ->set('cache.page', ['enabled' => 1, 'max_age' => 5])
      ->save();
?>

Additional Resources