function _configuration_replace_tokens in Configuration Management 6
Helper function to replace key/values using tokens
1 call to _configuration_replace_tokens()
- configuration_replace_tokens in ./
configuration.module - Find and replace identifier and token keys and values
File
- ./
configuration.module, line 1918 - Provide a unified method for defining site configurations abstracted from their data format. Various data formats should be supported via a plugin architecture such as XML, YAML, JSON, PHP
Code
function _configuration_replace_tokens(&$context) {
// Replace IDs with identifiers from the current executing pattern
$identifiers = configuration_get_data('identifiers');
if (is_scalar($context->item) && preg_match('/@([a-zA-Z0-9_]+)@/', $context->item, $match)) {
$value = str_replace($match[0], $identifiers[$match[1]], $context->item);
}
if (preg_match('/__([a-zA-Z0-9_]+)__/', $context->key, $match)) {
$key = str_replace($match[0], $identifiers[$match[1]], $context->key);
}
// Replace tokens
if (module_exists('token')) {
if (is_scalar($context->item) && !isset($value)) {
$value = token_replace($context->item, 'global', NULL, '@', '@');
}
if (!isset($key)) {
$key = token_replace($context->key, 'global', NULL, '__', '__');
}
}
// Replace the real data with new values
if (isset($value)) {
$context->item = $value;
}
if (isset($key)) {
configuration_context_process_property('#key', $key, $context);
}
}