You are here

function file_download_tokens in File Download 8

File

./file_download.module, line 142
.

Code

function file_download_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $token_service = \Drupal::token();
  $replacements = [];
  if ($type == 'file' && !empty($data['file'])) {

    /** @var \Drupal\node\NodeInterface $node */
    $file = $data['file'];
    foreach ($tokens as $name => $original) {
      switch ($name) {

        // Simple key values on the node.
        case 'type':
          $parts = explode('/', $file
            ->getMimeType());
          $replacements[$original] = $parts[1];
          break;
      }
    }
  }
  return $replacements;
}