You are here

function dfp_tokens in Doubleclick for Publishers (DFP) 8

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

Implements hook_tokens().

File

./dfp.tokens.inc, line 38
Builds placeholder replacement tokens for DFP Ad tag data.

Code

function dfp_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'dfp_tag') {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'slot':
          if (!empty($data['dfp_tag'])) {
            $replacements[$original] = $data['dfp_tag']
              ->getSlot();
          }
          break;
        case 'network_id':
          $config = \Drupal::config('dfp.settings');
          $replacements[$original] = $config
            ->get('network_id');
          $bubbleable_metadata
            ->addCacheableDependency($config);
          break;
      }
    }
  }
  return $replacements;
}