You are here

function rrssb_tokens in Ridiculously Responsive Social Sharing Buttons 8.2

Same name and namespace in other branches
  1. 7.2 rrssb.module \rrssb_tokens()
  2. 7 rrssb.module \rrssb_tokens()

Implements hook_tokens().

These tokens are not advertised in hook_token_info because they are of no use outside this module.

File

./rrssb.module, line 28

Code

function rrssb_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  $urlencode = isset($options['urlencode']);
  if ($type == 'rrssb' && !empty($data['rrssb'])) {
    foreach ($tokens as $name => $original) {
      if (isset($data['rrssb'][$name])) {
        $replacements[$original] = $data['rrssb'][$name];
        if ($urlencode) {

          // URL encode, and create a markup object to prevent the token replacement from escaping a second time.
          $replacements[$original] = Markup::create(rawurlencode($replacements[$original]));
        }
      }
    }
  }

  // This issue https://www.drupal.org/node/2842780 has a patch to add site:logo.
  // In the meantime, add our own version.
  if ($type == 'rrssbsite') {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'logo-url':
          if ($logo = theme_get_setting('logo')) {
            global $base_url;
            $replacements[$original] = $base_url . $logo['url'];
          }
          break;
      }
    }
  }
  return $replacements;
}