Prepopulating from an OG context currently only works for node entities, because the module uses the og_context() function with no arguments on line 217 of entityreference_prepopulate.module:
<?php
...
function entityreference_prepopulate_get_values_from_og_context($field, $instance, $flat_array = FALSE) {
$field_name = $field['field_name'];
if (!og_is_group_audience_field($field_name) || !$og_context = og_context()) {
return;
}
...
?>
When og_context() is called without arguments, it's first argument (node type) defaults to 'node'. So at the moment, this function only works for 'node' entities. If another entity type wants to use the same function, it won't work.
This can be easily fixed by changing og_context() to og_context($instance['entity_type']). This will look at the entity type of the field that it's dealing with, to figure out what it is.
Comments
Comment #1
m.stentaAttached is a patch against the current 7.x-1.x branch.
Comment #2
amitaibuDidn't you mean to pass the $field['settings']['target_type] ?
Comment #3
m.stentaHmm, maybe? What is the $field['settings']['target_type] value for?
I figured that the $instance is entity-specific, whereas the $field is not, so looking at the $instance['entity_type'] would reliably provide the entity type that the instance is tied to, which can then be passed to og_context(). Does that make sense?