You are here

function thunder_media_file_create in Thunder 8.2

Same name and namespace in other branches
  1. 8.5 modules/thunder_media/thunder_media.module \thunder_media_file_create()
  2. 8.3 modules/thunder_media/thunder_media.module \thunder_media_file_create()
  3. 8.4 modules/thunder_media/thunder_media.module \thunder_media_file_create()
  4. 6.0.x modules/thunder_media/thunder_media.module \thunder_media_file_create()
  5. 6.1.x modules/thunder_media/thunder_media.module \thunder_media_file_create()

Implements hook_ENTITY_TYPE_create().

File

modules/thunder_media/thunder_media.module, line 14
Contains media related functions.

Code

function thunder_media_file_create(File $entity) {
  $config = \Drupal::config('thunder_media.settings');
  if ($config
    ->get('enable_filename_transliteration')) {
    $pathinfo = pathinfo($entity
      ->getFilename());

    /** @var \Drupal\pathauto\AliasCleaner $aliasCleaner */
    $aliasCleaner = \Drupal::service('pathauto.alias_cleaner');

    // Check for needed pathinfo array keys.
    if (!empty($pathinfo['filename']) && !empty($pathinfo['extension'])) {
      $cleanFilename = $aliasCleaner
        ->cleanString($pathinfo['filename']) . '.' . $pathinfo['extension'];
      $entity
        ->setFilename($cleanFilename);
    }
  }
}