You are here

function tft_preprocess_media in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x tft.module \tft_preprocess_media()

Implements hook_preprocess_media().

File

./tft.module, line 727
Contains tft.module.

Code

function tft_preprocess_media(&$variables) {
  $media = $variables['media'];
  if ($media
    ->hasField('tft_file')) {
    $file = $media
      ->get('tft_file');
    if (!$file
      ->isEmpty()) {
      $file = File::load($file
        ->getValue()[0]['target_id']);
      if ($ext = _mimetype_mapping($file
        ->getMimeType())) {
        $variables['attributes']['class'][] = "file-ext-{$ext}";
        $variables['attributes']['class'][] = 'media-with-icon';
      }
    }
  }
}