function site_settings_tokens in Site Settings and Labels 8
Implements hook_tokens().
File
- ./
site_settings.tokens.inc, line 100 - Builds placeholder replacement tokens for node-related data.
Code
function site_settings_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$token_service = \Drupal::token();
$replacements = [];
if ($type == 'site_settings') {
// Allow developers to pass the settings to token replace so they can
// modify them first potentially. If not passed, just make the defaults
// available.
if (!empty($data['site_settings'])) {
$settings = $data['site_settings'];
}
else {
$site_settings = \Drupal::service('site_settings.loader');
$settings = $site_settings
->loadAll();
}
foreach ($tokens as $name => $original) {
$value = FALSE;
// Break apart name.
$name_parts = explode('--', $name);
$fieldset = $name_parts[0];
$type = $name_parts[1];
// We may be deep into a multidimensional array.
if (isset($name_parts[2]) && !empty($name_parts[2])) {
// Break apart the on our separator to get the series of array keys we
// need to navigate down.
$additional_depth = $name_parts[2];
$keys = explode('-', $additional_depth);
if (isset($settings[$fieldset][$type])) {
$setting = $settings[$fieldset][$type];
$value = _site_settings_retrieve_deep_value($setting, $keys);
$replacements[$original] = $value;
}
}
elseif (isset($settings[$fieldset][$type])) {
// Flat setting value.
$value = $settings[$fieldset][$type];
}
// No setting value found.
$replacements[$original] = $value;
}
}
return $replacements;
}