1 config.inc | public Config::set($key, $value, $include_overridden_value = FALSE) |
Sets a value in this configuration object.
Note that this will save a NULL value. If wanting to unset a key from the configuration, use Config::clear($key).
Parameters
string $key: Identifier to store value in configuration.
mixed $value: Value to associate with identifier.
bool $include_overridden_value: Set to TRUE to write the config value even if this key has been overridden (usually through settings.php). Overridden keys are ignored by default to prevent accidentally writing values that may be environment-specific or contain sensitive information that should not be written to config.
Return value
Config: The configuration object.
File
- core/
includes/ config.inc, line 885 - This is the API for configuration storage.
Class
- Config
- Defines the default configuration object.
Code
public function set($key, $value, $include_overridden_value = FALSE) {
// If setting a value that matches an override-provided one, don't actually
// write it to config.
$override_value = $this->getOverride($key);
if (isset($override_value) && ($override_value === $value) && !$include_overridden_value) {
return $this;
}
if (!$this->isLoaded) {
$this->load();
}
// The dot/period is a reserved character; it may appear between keys, but
// not within keys.
$parts = explode('.', $key);
if (count($parts) == 1) {
$this->data[$key] = $value;
}
else {
$data = &$this->data;
$last_key = array_pop($parts);
foreach ($parts as $part) {
if (!isset($data)) {
$data[$part] = array();
}
$data = &$data[$part];
}
$data[$last_key] = $value;
}
$this->validated = FALSE;
return $this;
}