Last updated 30 October 2012. Created on 3 September 2009.
Edited by arthurf, HongPong, Frank Ralf. Log in to edit this page.

Overview
Media Mover is a set of modules which allows website administrators to easily create complex file conversion processes. The core of Media Mover is the API which creates a set of rules allowing multiple modules to interact with a file.

Media Mover is a system for file processing. Media Mover connects a set of operations (defined by modules) which interact with a file. A file is harvested from some location (node, ftp, local directory, etc) and is passed through the set of operations which is called a configuration; each operation of the configuration is called a step. Steps are the generic term for an action- an action is the specific operation (eg: saving a file to a CCK field) on the file. Actions are defined by modules to operate on files, steps are parts of a configuration.

hook_media_mover()
The main Media Mover hook is visually similar to the way that Drupal 6 menus are defined. Modules simply return a set of data regarding an action to Media Mover which allows Media Mover to call appropriate functions at the right time.

The following example is from the mm_dir() module- this provides harvesting and save files to local directories.

/**
 * Implementation of hook_media_mover().
 *
 * @return array
 */
function mm_dir_media_mover() {
  $items = array();
  $items['harvest'] = array(
    'description' => t('Harvest files from a local directory'),
    'callback' => 'mm_dir_harvest',
    'configuration' => 'mm_dir_config_harvest',
    'harvest' => true,
  );
  $items['store'] = array(
    'description' => t('Store files to a local directory'),
    'callback' => 'mm_dir_save',
    'configuration' => 'mm_dir_config_storage',
  );
  return $items;
}

$items[NAME] identifies the specific action. The individual items for each action- description, configuration, callback, harvest provide information about what to do with this action. It is worth noting that NAME does not have to be unique across all modules, it merely needs to be unique in your module.

  • description: describes the action.
  • configuration: callback to a function that returns a form array. Expects: $configuration->steps[X]. This is not required- some actions do not have settings.
  • callback: callback to a function that runs the actual action. Expects $step, $file.
  • delete: (optional) callback function that will handle deletion of the file created for this specifc step. Expects $step, $file.
  • harvest: (optional) boolean, is this a harvesting action? NOTE: terminology is changing to "select" rather than harvest
  • harvest_from_node: (optional) boolean, configurations that harvest data from nodes can be run on single nodes. If your action supports harvesting from a single node (meaning that you have written code that will support it), set this value to TRUE, otherwise this is an unnecessary property

Technically, all of these items are optional, however, in a normal implementation, you will need description, configuration, and callback to integrate your function.

Programatically using Media Mover or leveraging Media Mover without the UI
If you have a file that you would like to process through Media Mover (with a defined configuration or one created in code) you can do so by using the media_mover_api_file_process() function. Create a new $file object, making sure to set the property: $file->passthrough = true; This will prevent the $file from being saved during a $file->save() call. Additionally, you can pass in your own configuration defined via code. This is currently not documented beyond here.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.