function _cer_find_channels in Corresponding Entity References 7.2
The purpose of this function is to answer this question: I am a field instance. Which other fields reference the entity that owns me? And of those instances, which ones can I reference? The answer is returned as an array of CER keys: "entity1 bundle1 field1 entity2 bundle2 field2".
Parameters
array $instance: Field instance info, as returned by field_info_instance().
Return value
array
1 call to _cer_find_channels()
- cer_settings_form in ./
cer.admin.inc - The settings form.
File
- ./
cer.admin.inc, line 163 - Administrative functionality, separated for performance purposes.
Code
function _cer_find_channels($instance) {
$channels = array();
$my_id = $instance['entity_type'] . ' ' . $instance['bundle'] . ' ' . $instance['field_name'];
$my_info = field_info_field($instance['field_name']);
$my_targets = _cer_get_target_bundles($my_info);
$my_target_type = $my_info['settings']['target_type'];
$referrers = _cer_find_referrers($instance['entity_type'], $instance['bundle']);
foreach ($referrers as $referrer) {
if (isset($referrer['bundles'][$my_target_type])) {
if (empty($my_targets)) {
$bundles = $referrer['bundles'][$my_target_type];
}
else {
$bundles = array_intersect($referrer['bundles'][$my_target_type], $my_targets);
}
foreach ($bundles as $bundle) {
$channels[] = "{$my_id} {$my_target_type} {$bundle} " . $referrer['field_name'];
}
}
}
return $channels;
}