function _potx_replace_variable in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \_potx_replace_variable()
- 7.3 potx.inc \_potx_replace_variable()
- 7.2 potx.inc \_potx_replace_variable()
Replaces variable values in included names with configuration data.
Variable values are nested configuration keys that will be replaced by their value or some of these special strings:
- '%key', will be replaced by the element's key.
- '%parent', to reference the parent element.
There may be nested configuration keys separated by dots or more complex patterns like '%parent.name' which references the 'name' value of the parent element.
Example patterns:
- 'name.subkey', indicates a nested value of the current element.
- '%parent.name', will be replaced by the 'name' value of the parent.
- '%parent.%key', will be replaced by the parent element's key.
Based on Drupal\Core\Config\TypedConfigManager::replaceVariable($value, $data).
Parameters
string $value: Variable value to be replaced.
mixed $data: Configuration data for the element.
Return value
string The replaced value if a replacement found or the original value if not.
1 call to _potx_replace_variable()
- _potx_config_replace_name in ./
potx.inc - Replaces variables in configuration name.
File
- ./
potx.inc, line 2751 - Extraction API used by the web and command line interface.
Code
function _potx_replace_variable($value, $data) {
$parts = explode('.', $value);
// Process each value part, one at a time.
while ($name = array_shift($parts)) {
if (!is_array($data) || !isset($data[$name])) {
// Key not found, return original value.
return $value;
}
elseif (!$parts) {
$value = $data[$name];
if (is_bool($value)) {
$value = (int) $value;
}
// If no more parts left, this is the final property.
return (string) $value;
}
else {
$data = $data[$name];
}
}
}