function media_install in D7 Media 7
Same name and namespace in other branches
- 8 media.install \media_install()
- 7.4 media.install \media_install()
- 7.2 media.install \media_install()
- 7.3 media.install \media_install()
Implements hook_install().
File
- ./
media.install, line 158 - Install, update and uninstall functions for the Media module.
Code
function media_install() {
// @todo We may need to disable the media bundle & field in hook_disable.
// Define the default type to be used if no other type is found. Give it a
// high weight to ensure it runs last.
$types['default'] = new stdClass();
$types['default']->name = 'default';
$types['default']->label = "Other";
$types['default']->base = TRUE;
$types['default']->weight = 1000;
$types['default']->type_callback_args = array(
'match_type' => 'any',
'mimetypes' => array(
'/.*/',
),
);
// Define the common media types: image, audio, and video.
$types['image'] = new stdClass();
$types['image']->name = 'image';
$types['image']->label = "Image";
$types['image']->base = TRUE;
$types['image']->type_callback_args = array(
'match_type' => 'all',
'mimetypes' => array(
'/^image/',
),
'extensions' => array(
'jpg',
'jpeg',
'gif',
'png',
'tiff',
),
'streams' => array(
'public',
'private',
),
);
$types['audio'] = new stdClass();
$types['audio']->name = 'audio';
$types['audio']->label = "Audio";
$types['audio']->base = TRUE;
$types['audio']->type_callback_args = array(
'match_type' => 'all',
'mimetypes' => array(
'/^audio/',
),
'extensions' => array(
'mp3',
'ogg',
'wma',
),
'streams' => array(
'public',
'private',
),
);
$types['video'] = new stdClass();
$types['video']->name = 'video';
$types['video']->label = "Video";
$types['video']->base = TRUE;
$types['video']->type_callback_args = array(
'match_type' => 'all',
'mimetypes' => array(
'/^video/',
),
'extensions' => array(
'mov',
'mp4',
'avi',
),
'streams' => array(
'public',
'private',
),
);
// Create the defined types.
foreach ($types as $name => $type) {
media_type_save($type);
// @todo By default, we hide the file display in the 'small' view mode for
// legacy reasons. Does it still make sense to do so? See
// http://drupal.org/node/1051090.
$bundle_settings = field_bundle_settings('file', $name);
$bundle_settings['extra_fields']['display']['file']['media_small'] = array(
'weight' => 0,
'visible' => FALSE,
);
field_bundle_settings('file', $name, $bundle_settings);
}
// Set permissions.
$roles = user_roles();
foreach ($roles as $rid => $role) {
user_role_grant_permissions($rid, array(
'view media',
));
}
// Updates the type field for the first MEDIA_UPDATE_RECORDS_ON_INSTALL files.
$invalid_files = media_type_invalid_files_count();
if ($invalid_files <= MEDIA_UPDATE_RECORDS_ON_INSTALL) {
media_type_batch_update(FALSE, MEDIA_UPDATE_RECORDS_ON_INSTALL);
}
$invalid_files = media_type_invalid_files_count();
if ($invalid_files > 0) {
// Not all files could be converted. Display a persistant nag message on
// every page for the administrator, urging them to finish the process.
media_variable_set('show_file_type_rebuild_nag', TRUE);
}
}