media_metadata.module in D7 Media 6
This module provides metadata integration with the Media module.
File
media_metadata/media_metadata.moduleView source
<?php
/**
* @file
* This module provides metadata integration with the Media module.
*/
/**
* 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.
*
* @param 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.
*/
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]));
}
// @TODO: Add the file info here as well.
function media_metadata_form($form_state, $mimetype = '*') {
$form = module_invoke_all('media_metadata_form', $form_state, $mimetype);
$form['mimetype'] = array(
'#type' => 'value',
'#value' => $mimetype,
);
$form['#submit'] = array(
'media_metadata_form_submit',
);
}
function media_metadata_form_submit($form, &$form_state) {
$mimetype = $form_state['values']['mimetype'];
$keys = media_metadata_keys($mimetype);
$values = array();
foreach ($keys as $key) {
$values[$key] = $form_state['values'][$key];
}
// @TODO: Grab the file info and save the record.
}
Functions
Name | Description |
---|---|
media_metadata_form | |
media_metadata_form_submit | |
media_metadata_keys | Returns the metadata keys associated with a file stream mimetype. |