You are here

function media_metadata_keys in D7 Media 6

Returns the metadata keys associated with a file stream mimetype.

The hook_media_metadata_keys of all implementing modules will be invoked with the mimetype to build a list of keys to be collected and saved for file resources of that mimetype.

Parameters

string $mimetype: The file mimetype to return the keys. If '*' is passed, then only the keys stored for all mimetypes will be returned. @param boolean $exclusive If TRUE, then only the keys exclusive to that metadata will be returned. Otherwise, also include all metadata for the wildcard '*' mimetype. @param boolean $reset If TRUE, then rebuild the static cache of keys. @return array An array of unique metadata keys that will be saved for that mimetype.

1 call to media_metadata_keys()
media_metadata_form_submit in media_metadata/media_metadata.module

File

media_metadata/media_metadata.module, line 26
This module provides metadata integration with the Media module.

Code

function media_metadata_keys($mimetype = '*', $exclusive = FALSE, $reset = FALSE) {
  static $keys;

  // Build our static cache.
  if (is_null($keys)) {
    $keys = array();

    // Collect all metadata keys for the wildcard/all '*' mimetype.
    $keys['*'] = module_invoke_all('media_metadata_keys', '*');
  }

  // If NULL is passed, assume it's the wildcard.
  if (is_null($mimetype)) {
    $mimetype = '*';
  }

  // Don't call module_invoke_all more than necessary; use the static variable.
  if (isset($mimetype) && $mimetype != '*' && ($reset || is_null($keys[$mimetype]))) {

    // Build a unique array from all modules implementing hook_metadata_keys.
    $keys[$mimetype] = array_unique(module_invoke_all('media_metadata_keys', $mimetype));
  }

  // Return either the keys for that mimetype, or the merged array of keys for
  // the mimetype and for all '*' mimetypes, depending on $exclusive.
  return $exclusive || $mimetype == '*' ? $keys[$mimetype] : array_unique(array_merge($keys['*'], $keys[$mimetype]));
}