Filling out Media API

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
aaron's picture

I just posted the following to the Media Code Sprint wiki. Here it is for reference and commentary. Please let me know if there are any problems with this functionality, or if you believe I have misinterpreted it.

Thanks,
Aaron

<?php
/**
*  Implementation of hook_media_register
*
*  To plug into the Media API, a module must first register itself, using
*  hook_media_register. This function will return an array of items keyed
*  by a unique machine name, usually using the module's name for the name
*  space.
*
*  Note that there are two places a module may register itself, both through
*  this hook. The first, a 'resource', will be to return a listing of files,
*  and the second, 'format', is to format a listing of files. The first type
*  of item will be displayed as a vertical tab, and the second as a tab along
*  the top.
*
*  Each item is an array that will define the following keyed values:
*    'module' => $module,
*        // Where $module is the name of the module that will handle this
*        // item. This defaults to the registering module.
*    'kind' => 'resource|format',
*        // Where the value is either 'resource' or 'format'. If 'resource',
*        // then we expect the functions called from later hooks to filter
*        // our file listings. If 'format', we expect the module to format
*        // a file listing appropriately.
*    'name' => t('string'),
*        // Where 'string' is a human readable name that will be displayed as
*        // a tab or drawer.
*    'description' => t('string'),
*        // Where 'string' is a human readable description that may be
*        // displayed, describing the file listing or display format.
*    'uri' => 'scheme://',
*        // Where 'scheme://' defaults to 'public://'. If the uri is anything
*        // but the default, then that module should require the Resource
*        // module. (See that module for a further definition of schemes,
*        // which may include examples like 's3://' or 'youtube://'.)
*    'types' => '[mime-types]',
*        // Where '[mime-types]' defaults to '*', and denotes any mime types
*        // this module will handle, separated by spaces. '*' means all.
*    'callbacks' => array('[kind]' => '[callback]'),
*        // where [kind] is the kind of hook this item is, being either
*        // 'resource' or 'format' as described earlier, and 'callback' is the
*        // function that will be called to handle the functionality.
*        // A 'resource' callback should return a file listing, and 'format'
*        // will theme a file listing passed to it.
*    'fields' => array('[field type]', '[field type]'),
*        // Where '[field type]' is a CCK field type this hook will handle,
*        // such as 'filefield' or 'imagefield', or 'attachments' for the
*        // default Upload module.
*/

function hook_media_register() {
  return array(
   
'media_user_files' => array(
     
'name' => t('User files'),
     
'description' => t('Format Drupal uploaded files.'),
     
'uri' => 'public://',
     
'kind' => 'resource',
     
'types' => '*',
     
'callbacks' => array(
       
'resource' => 'media_display_user_files',
       ),
     
'description' => t("Displays all of current user's files."),
     
'fields' => array('attachments', 'filefield'),
    ),
  );
}
?>

Media

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: