diff --git a/includes/MediaYouTubeBrowser.inc b/includes/MediaYouTubeBrowser.inc index af9ebc8..1b25ffa 100644 --- a/includes/MediaYouTubeBrowser.inc +++ b/includes/MediaYouTubeBrowser.inc @@ -14,9 +14,7 @@ class MediaYouTubeBrowser extends MediaBrowserPlugin { * Implements MediaBrowserPluginInterface::access(). */ public function access($account = NULL) { - // @TODO: media_access() is a wrapper for file_entity_access(). Switch to the - // new function when Media 1.x is deprecated. - return media_access('create', $account); + return media_youtube_access('create', NULL, $account); } /** diff --git a/media_youtube.module b/media_youtube.module index c728e6a..e6a1ffd 100644 --- a/media_youtube.module +++ b/media_youtube.module @@ -308,9 +308,7 @@ function media_youtube_add_submit($form, &$form_state) { } // Redirect to the file edit page after submission. - // @TODO: media_access() is a wrapper for file_entity_access(). Switch to the - // new function when Media 1.x is deprecated. - if (media_access('update', $file)) { + if (media_youtube_access('update', $file)) { $destination = array('destination' => 'admin/content/file'); if (isset($_GET['destination'])) { $destination = drupal_get_destination(); @@ -324,6 +322,32 @@ function media_youtube_add_submit($form, &$form_state) { } /** + * Determine if a user may perform the given operation on the specified file. + * + * Enables compatibility with Media 1.x and 2.x by providing a wrapper around + * both media_access() and file_entity_access(). + * + * @return boolean + * TRUE if the operation may be performed, FALSE otherwise. + * + * @see media_access() + * @see file_entity_access() + */ +function media_youtube_access($op, $file = NULL, $account = NULL) { + if (function_exists('file_entity_access')) { + $access = file_entity_access($op, $file, $account); + } + elseif (function_exists('media_access')) { + $access = media_access($op, $account); + } + else { + $access = FALSE; + } + + return $access; +} + +/** * @TODO: Document this function. */ function media_youtube_video_search($options = array()) {