You are here

function file_entity_file_mimetype_mapping_alter in File Entity (fieldable files) 7

Same name and namespace in other branches
  1. 7.3 file_entity.file.inc \file_entity_file_mimetype_mapping_alter()
  2. 7.2 file_entity.file.inc \file_entity_file_mimetype_mapping_alter()

Implements hook_file_mimetype_mapping_alter().

File

./file_entity.module, line 634
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_file_mimetype_mapping_alter(&$mapping) {

  // Fix the mime type mapping for ogg.
  // @todo Remove when http://drupal.org/node/1239376 is fixed in core.
  $new_mappings['ogg'] = 'audio/ogg';

  // Add support for m4v.
  // @todo Remove when http://drupal.org/node/1290486 is fixed in core.
  $new_mappings['m4v'] = 'video/x-m4v';

  // Add support for mka and mkv.
  // @todo Remove when http://drupal.org/node/1293140 is fixed in core.
  $new_mappings['mka'] = 'audio/x-matroska';
  $new_mappings['mkv'] = 'video/x-matroska';
  foreach ($new_mappings as $extension => $mime_type) {
    if (!in_array($mime_type, $mapping['mimetypes'])) {

      // If the mime type does not already exist, add it.
      $mapping['mimetypes'][] = $mime_type;
    }

    // Get the index of the mime type and assign the extension to that key.
    $index = array_search($mime_type, $mapping['mimetypes']);
    $mapping['extensions'][$extension] = $index;
  }
}