Changing the Order of Drupal 7 Media Module File Browser Tabs

I am working on a site where the client requested that the Library tab be the first tab in the Media module's File browser pop up.  While this is a seemingly simple request, it is one that I have never run into.

I looked at the views, and in devel themer and at a bit of the module code.  I searched on the googles, the issue queues and the stack overflows, but could not find a solution.  After posting in the #drupal-media IRC channel, Brandon Neil came to the rescue pointing me towards hook_media_browser_plugin_info_alter()

Here is the original order of the file browser:

In order to change the order and hook into this function, I created a simple custom module, mediamenu.  In this module, I will be able to hook into the media module using the hook Brandon showed me, and change the weight of the tabs, re-ordering them. The module has a folder named mediamenu, and inside two files, named and mediamenu.module.  You can view and download these files from this github repo.

The .info file contains information about the module, name, description, version, which version of Drupal, and where to group it on the modules page.

name = Media Menu
description = This module organizes the tabs on the Media browser.
version = "7.x-1.0"
core = "7.x"
package = Media


In the .module file, we hook in and change the weights of the tabs, which will re-order them, the heaviest weight/lowest number first.

The first two items here are provided by the Media module, and the Media Browser view (Machine name: media_default).  The two tabs are made by the two displays of the view,  media_browser_1 and
media_browser_my_files.  The media_internet tab is provided by the module of the same name.  Upload is provided by the media module.

< ?php
 * Change Order of Media Browser Tabs
 * Implements hook_media_browser_plugin_info_alter().
function mediamenu_media_browser_plugin_info_alter(&$info) {
  $info['media_default--media_browser_1']['weight'] = '-10';
  $info['media_default--media_browser_my_files']['weight'] = '-9';
  $info['media_internet']['weight'] = '-8';
  $info['upload']['weight'] = '-7';

You may have additional tabs provided by other modules. You can find their machine name but looking at the source markup of the page, and looking for the data-tabid of the tab.

In conclusion

Once you have created or recreated these two files, in a folder called mediamenu, upload it to your site and enable it in the UI or drush en -y mediamenu.  Clear the caches and you should see your changes the next time you open the File browser.

Drupal Media Module - File Browser Re-ordered