You are here

function media_type_save in D7 Media 7

Update an existing media type or create a new one.

The default media types are currently 'Audio', 'Image', 'Video', and 'Other', which are defined in media_install().

Parameters

object &$type: $type is an object with the following fields: ->name => The name of the media asset type, such as 'video'; ->label => The human readable name; ->base => boolean: If the media type cannot be removed. ->type_callback => Function call to filter an instance to its bundle. ->type_callback_args => An array of args to be passed to type_callback. @return void;

4 calls to media_type_save()
MediaTypeTest::createType in test/media.types.test
media_admin_type_manage_form_submit in includes/media.admin.inc
media_install in ./media.install
Implements hook_install().
media_update_7002 in ./media.install
Create the media_type table from the media_types variable.

File

includes/media.types.inc, line 77
Helper functions related to media types. CRUD for saving their settings mainly.

Code

function media_type_save(&$type) {
  if (empty($type->name)) {
    throw new Exception('Enable to add type, name not provided');
  }
  $type = media_type_set_defaults($type);
  if (!is_array($type->type_callback_args)) {
    throw new Exception('type_callback_args should be an array');
  }
  $type->type_callback_args = serialize($type->type_callback_args);
  $ret = db_merge('media_type')
    ->key(array(
    'name' => $type->name,
  ))
    ->fields((array) $type)
    ->execute();

  // Clear the caches
  drupal_static_reset('media_type_get_types');
  drupal_static_reset('media_type_get_mime_map');
  return;
}