Media: hook_media_register

Last updated on
30 April 2025

hook_media_register() is used to register functionality with the media module. It provides modules with the ability to declare resource containers, formatters and other options for the Media module. If you want to create a custom display of resources inside the Media browser, this is where you do it.

The hook consists of an array of items that are registered by the Media module:

<?php

  $registration = array(
    'media_upload_container' => array(
      // human readable name
      'name' => t('Media Upload container'),
      // kind of item, one of resource, format
      'kind' => 'container',
      // set the URI, optional
      'uri' => 'public://',
      // this is the default value, otherwise array of options
      'types' => '*',
      'description' => t('Drupal uploaded files'),
      // function to invoke when data is needed from this 
      'callbacks' => array(
        'resource' => 'media_upload_media_user_files_select',
      ),
      // human readable description
      'description' => t('Provides integration with Drupal\'s Upload module'),
      // cck field types that this works on
      'fields' => array('attachments', 'filefield'),
    ),
 );

?>

This is a basic implementation which demonstrates how to register your module with Media. The first item in the array is a unique identifier- use your module name and an additional name. This allows you to register multiple functions within your module.

  • name is a human readable name of the functionality. This is displayed on forms, so a good identifier here is helpful.
  • kind is the kind of functionality that your module provides. This is either 'resource', or 'format'.
  • uri defines the URI functions that your new function specifically works with. This defaults to 'public://'. Optional.
  • types are the file extension (mime) types that your module works with. Defaults to * or all file types.
  • description a more verbose description of what your functionality provides.
  • callbacks array of key => functions called for data.
  • fields what fields does this functionality operate on?
  • validation
  • display

Help improve this page

Page status: Not set

You can: