function _oa_core_select2widget_process_entity_labels in Open Atrium Core 7.2
Turn the current values to labels for select2 init/default value.
3 calls to _oa_core_select2widget_process_entity_labels()
- oa_core_og_group_ref_process in includes/
oa_core.fields.inc - Process function of the og_group_ref field.
- oa_core_og_group_ref_views_handler_filter_entityreference_autocomplete::value_form in plugins/
views/ oa_core_og_group_ref_views_handler_filter_entityreference_autocomplete.inc - oa_core_select2widget_entity_validate_field in includes/
oa_core.fields.inc - Validate the entities as real, including custom all/current.
File
- includes/
oa_core.fields.inc, line 123 - Code for custom Form API fields in Open Atrium
Code
function _oa_core_select2widget_process_entity_labels($value) {
$target_entities = is_array($value) ? $value : explode(',', $value);
$entity_labels = array();
foreach ($target_entities as &$target_entity) {
if (is_numeric($target_entity)) {
$entity = entity_load_single('node', $target_entity);
if (entity_load_single('node', $target_entity)) {
$label = entity_label('node', $entity);
$key = "{$label} - {$target_entity}";
// Labels containing commas or quotes must be wrapped in quotes.
if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
$key = '"' . str_replace('"', '""', $key) . '"';
}
$entity_labels[$target_entity] = $key;
}
}
elseif (preg_match("/.+\\((\\d+)\\)/", $target_entity, $matches)) {
$entity_labels[$matches[1]] = check_plain($target_entity);
}
elseif ($target_entity == 'All') {
$entity_labels['All'] = _oa_core_select2widget_all_label();
}
elseif ($target_entity == OA_SPACE_CURRENT || ($target_entity = _oa_core_select2widget_current_label())) {
$entity_labels[OA_SPACE_CURRENT] = _oa_core_select2widget_current_label();
}
}
return $entity_labels;
}