You are here

function _site_settings_build_token in Site Settings and Labels 8

Build the tokens from the site settings.

Parameters

array $site_settings: The site settings.

string $fieldset: The fieldset.

string $fieldtype: The field type.

mixed $values: A single string value or array of values.

string $suffix: A suffix to add to the token to handle array values.

Return value

array The array of tokens.

1 call to _site_settings_build_token()
site_settings_token_info in ./site_settings.tokens.inc
Implements hook_token_info().

File

./site_settings.tokens.inc, line 60
Builds placeholder replacement tokens for node-related data.

Code

function _site_settings_build_token(array $site_settings, $fieldset, $fieldtype, $values, $suffix = FALSE) {
  if (is_array($values)) {

    // Recursively get all values.
    foreach ($values as $key => $values) {
      $this_suffix = ($suffix !== FALSE ? $suffix . '-' : '') . $key;
      $site_settings = _site_settings_build_token($site_settings, $fieldset, $fieldtype, $values, $this_suffix);
    }
  }
  else {

    // Set description based on whether flat or array of data.
    if ($suffix !== FALSE) {
      $description = t('One of the values of "@type" within "@fieldset"', [
        '@type' => $fieldtype,
        '@fieldset' => $fieldset,
      ]);
    }
    else {
      $description = t('The value of "@type" within "@fieldset"', [
        '@type' => $fieldtype,
        '@fieldset' => $fieldset,
      ]);
    }

    // Store each value or subvalue as a token option.
    $key = $fieldset . '--' . $fieldtype . ($suffix !== FALSE ? '--' . $suffix : '');
    $label = _site_settings_token_label($key);
    $site_settings[$key] = [
      'name' => t("@label", [
        '@label' => $label,
      ]),
      'description' => $description,
    ];
  }
  return $site_settings;
}