degov-8.x-2.0/modules/degov_media_document/degov_media_document.module

modules/degov_media_document/degov_media_document.module
<?php

use Drupal\degov_common\Common;

/**
 * Implements hook_preprocess().
 */
function degov_media_document_preprocess(&$variables, $hook, &$info) {
  if ($hook === 'media') {
    /* @var \Drupal\media\Entity\Media $media */
    $media = $variables['elements']['#media'];

    if ($media->bundle() === 'document') {
      /* @var \Drupal\file\Entity\File $file */
      $file = $media->field_document->entity;
      $file_ext = new SplFileInfo($file->getFilename());
      $variables['media_url'] = file_create_url($file->getFileUri());
      $variables['media_bytes'] = $file->getSize();
      $variables['media_size'] = format_size($file->getSize());
      // The format_size() function does not allow for changing the
      // decimal point, so do a simple string replace.
      if (\Drupal::languageManager()->getCurrentLanguage()->getId() == 'de') {
        $variables['media_size'] = str_replace('.', ',', $variables['media_size']);
      }
      $variables['media_mime'] = $file->getMimeType();
      $variables['media_extention'] = $file_ext->getExtension();
      $variables['media_aria_label'] = sprintf('%s (%s)', $file->getFilename(), $variables['media_size']);
    }
  }

  // Add template suggestions and libraries implemented in this module.
  Common::addThemeSuggestions($variables, $hook, $info, [
    'module_name' => 'degov_media_document',
    'entity_type' => 'media',
    'entity_bundles' => ['document'],
    'entity_view_modes' => ['usage', 'preview', 'search', 'embedded'],
  ]);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc