Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Media types is a bundle for media entities.
You can add a new media type via the media_type_save() function.
$type = new StdClass();
$type->name = 'mymediatype';
$type->label = 'My Media Type';
$type->base = TRUE; // @todo what?
$type->type_callback_args = array(
'match_type' => 'all', // @todo what?
'mimetypes' => array(), // An array of regex patterns e.g. /^audio/
'extensions' => array(), // An array of extensions
'streams' => array() // An array of streams @todo what?
);
$type = media_type_save($type);