Add referencing entities into this entities renderable array Lets say I have a taxonomy called bands, and a taxonomy called band_members.

Band_members have an entity reference field relating each band member to a band.

When I view the bands taxonomy term page the band_members will not be listed.

I can modify the taxonomy term template and manually add them in there, however the bands need to be shown in popups, and the content for each popup is returned via AJAX using drupal_render(taxonomy_term_view($term)). This means any template changes won't show up. What I need to do is use a hook like hook_taxonomy_term_view_alter to add the band_members for that band into the renderable array.

However that will be quite a lot of work, and I though it seems like a fairly standard task to need to displayed referencing entities, so is there an easier way to do this?

In this example I've used taxonomies as an example, however this could apply to nodes, users or any other entities that reference each other.
Seems custom code was the easiest thing here after a bit of research...

function HOOK_taxonomy_term_view_alter(&amp;$build) {
    if($build['#term']-&gt;vocabulary_machine_name=='bands') {
        $units = load_bands_members($build['#term']-&gt;tid);
        $build['units'] = array(
            '#markup' =&gt; theme('bands_members', array('members' =&gt; $members))
        );

    }
}


The function load_band_members returns an array of taxonomy terms and looks like this:

function load_band_members($tid) {
    $tids = db_query("SELECT tid
        FROM taxonomy_term_data td
        INNER JOIN field_data_field_band b ON b.entity_id = td.tid
        WHERE td.vid = 6 AND b.field_band_tid = :tid", array(':tid'=&gt;$tid))-&gt;fetchCol();
    return $tids ? taxonomy_term_load_multiple($tids) : false;
}


I'm sure it would somehow be possible to get Drupal to render my band members for me, like it does on their own taxonomy term page, as opposed to me having to call my own custom render function but that will do for now...