As title says, I need to override few media module functions and add some extra conditions when selecting media. I wanted to create new module that extends media module and overrides those functions but without success.

I wanted to override function

function media_admin_list(&$parent_form)

and to add this line so media module will select media from logged in user

$query = db_select('file_managed', 'f')->extend('PagerDefault')->extend('TableSort');
$query->join('users', 'u', 'f.uid = u.uid');
$query->fields('f', array('fid'));
$query->fields('u', array('uid'));
$query->condition('f.status', FILE_STATUS_PERMANENT);
$query->condition('u.uid', $user_id, "=");

As you can see in code above, we have condition for selecting media from specific user.

Please advise how to override this function in my own module.


1 Answer 1


The best suggestion I can come up with is to use hook_form_alter() to alter the value of $form['admin']['#files'] (inspect the form array on the /admin/content/media page) by calling your own version of media_admin_list() with an altered query.

Something like:

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'media_admin') {
        $form['admin']['#files'] = custom_media_admin_list();

This is slightly inefficient as the original function has already run but I can't see a way to alter it before the initial form array has been built.

  • Thanks @Felix for your answer but this didn't solve my problem. Code goes through my custom function, but after that code goes through original function and I have same result again. Apr 15, 2014 at 12:17
  • Arr - in that case make your changes in an #after_build callback.
    – Felix Eve
    Apr 15, 2014 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.