You are here

function type_style_tokens in Type Style 8

Implements hook_tokens().

File

./type_style.tokens.inc, line 15
Token hook implementations for the Type Style module.

Code

function type_style_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if (isset($data[$type]) && $data[$type] instanceof EntityInterface) {
    foreach ($tokens as $name => $original) {
      if (strpos($name, 'type-style-') === 0) {
        $style_name = str_replace('type-style-', '', $name);
        if ($style = type_style_get_style($data[$type], $style_name)) {
          $replacements[$original] = $style;
        }
      }
    }
  }
  return $replacements;
}