function _entityconnect_get_ref_fields in Entity connect 7
Same name and namespace in other branches
- 7.2 includes/entityconnect.utils.inc \_entityconnect_get_ref_fields()
Helper function to retieve all allowed entityreference fields.
1 call to _entityconnect_get_ref_fields()
- entityconnect_field_attach_form in ./
entityconnect.module - Implements hook_field_attach_form().
File
- ./
entityconnect.module, line 217 - Handles the main hooks used by entityconnect.
Code
function _entityconnect_get_ref_fields() {
$ref_fields = array();
foreach (field_info_fields() as $id => $field) {
// Add support for Entity reference module.
if ($field['type'] == 'entityreference' && $field['module'] == 'entityreference') {
$entity_reference_info = entityreference_get_selection_handler($field);
$entity_type = $entity_reference_info->field['settings']['target_type'];
$target_bundle = isset($entity_reference_info->field['settings']['handler_settings']['target_bundles']) ? $entity_reference_info->field['settings']['handler_settings']['target_bundles'] : NULL;
switch ($entity_type) {
case 'user':
if (user_access('administer users') && (user_access('entityconnect add button') || user_access('entityconnect edit button'))) {
$ref_fields[$id] = $field;
}
break;
case 'node':
if (isset($target_bundle) && count($target_bundle) == 1) {
if ((user_access('create ' . array_pop($target_bundle) . ' content') || user_access('administer nodes')) && (user_access('entityconnect add button') || user_access('entityconnect edit button'))) {
$ref_fields[$id] = $field;
}
}
elseif (user_access('entityconnect add button') || user_access('entityconnect edit button')) {
$ref_fields[$id] = $field;
}
break;
case 'taxonomy_term':
if (user_access('entityconnect add button') || user_access('entityconnect edit button')) {
$ref_fields[$id] = $field;
}
break;
case 'taxonomy_vocabulary':
if (user_access('entityconnect add button') || user_access('entityconnect edit button')) {
$ref_fields[$id] = $field;
}
break;
default:
// Entity construction kit support.
if (module_exists('eck')) {
$entity_info = entity_get_info($entity_type);
if (!empty($entity_info['module']) && $entity_info['module'] == 'eck') {
if (user_access('entityconnect add button') || user_access('entityconnect edit button')) {
$ref_fields[$id] = $field;
}
}
}
// Bean support.
if (module_exists('bean_admin_ui')) {
$entity_info = entity_get_info($entity_type);
if (!empty($entity_info['module']) && $entity_info['module'] == 'bean') {
if (user_access('entityconnect add button') || user_access('entityconnect edit button')) {
$ref_fields[$id] = $field;
}
}
}
break;
}
}
// Add support for Reference module.
if ($field['type'] == 'node_reference' && $field['module'] == 'node_reference' || $field['type'] == 'user_reference' && $field['module'] == 'user_reference') {
$ref_fields[$id] = $field;
}
}
return $ref_fields;
}