Media: Callback resource

Last updated on
30 April 2025

In your hook_media_register you declare callbacks for each of the functions that are needed by the registered type.

Specifically, the callback resource for resources expects data to be returned in an ordered format. This allows a module to define a tab inside of the the browser, a drawer, and the actual display pane. Your callback function should return code in the form:

<?php
  return array( 
    t('My files') => array(
      t('My Drawer') => media_resource_display_user_files_form($files, t('Your files')),     
    )
  );
?>

Here, an array is passed back. The first key in the array determines the tab title that this data is related to. If this tab does not exist, it is created. If it does exist the additional data is merged into the existing tab's data. The second key is the drawer or sub element title. The drawer title's data is a Drupal form array. Media provides default formatters that you can pass your resource listings to- here you see the media_resource_display_user_files_form() function which formats your data.

Media provides these basic display options:

  • media_resource_display_user_files_form() displays files in a list
  • media_resource_display_upload_form() displays an upload form

If you provide your own form, it is critical that you identify the resource that will be formatted with the following CSS classes: resource, select. These are the selectors that are used to find the selected resource and generated the formatter form for.

Help improve this page

Page status: Not set

You can: