You are here

function extlink_extra_tokens in External Links Extra 8

Same name and namespace in other branches
  1. 7 extlink_extra.module \extlink_extra_tokens()

Implements hook_tokens().

File

./extlink_extra.module, line 491

Code

function extlink_extra_tokens($type, $tokens, array $data = [], array $options = []) {
  if ($type == 'extlink') {
    $replacements = [];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'external-url':
          $replacements[$original] = urldecode($data['extlink']['external_url']);
          break;
        case 'back-url':
          $replacements[$original] = urldecode($data['extlink']['back_url']);
          break;
        case 'timer':

          /** @var \Drupal\Core\Render\RendererInterface $renderer */
          $renderer = \Drupal::service('renderer');
          $timer_markup = extlink_extra_timer_markup();
          $replacements[$original] = $renderer
            ->render($timer_markup);
          break;
      }
    }
    return $replacements;
  }
}