You are here

function copyright_block_tokens in Copyright Block module 8

Same name and namespace in other branches
  1. 7.2 copyright_block.module \copyright_block_tokens()

Implements hook_tokens().

File

./copyright_block.module, line 30

Code

function copyright_block_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'copyright_statement') {
    $config = $options['config'];
    $separator = $config['separator'];
    $start_year = $config['start_year'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'dates':
          $current_year = date('Y');
          $start_year = !empty($start_year) ? $start_year : $current_year;
          $replacements[$original] = $start_year < $current_year ? $start_year . $separator . $current_year : $start_year;
          break;
      }
    }
  }
  return $replacements;
}