Media module function overriting, user can see only own media 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(&amp;$parent_form)


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

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


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.

Thanks.
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(&amp;$form, &amp;$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.