function oa_core_select2widget_ajax_callback in Open Atrium Core 7.2
Copy of select2widget_ajax_callback to add in All/current space.
1 string reference to 'oa_core_select2widget_ajax_callback'
- oa_core_menu in ./
oa_core.module - Implements hook_menu().
File
- ./
oa_core.module, line 215
Code
function oa_core_select2widget_ajax_callback($add_current_option, $field_name, $entity_type, $bundle_name, $entity_id = '') {
$string = '';
if (isset($_GET['search_string']) && !empty($_GET['search_string'])) {
$string = $_GET['search_string'];
}
$field = field_info_field('og_group_ref');
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
$matches = array();
$options = array();
$entity = NULL;
if ($entity_id !== 'NULL') {
$entity = entity_load_single($entity_type, $entity_id);
if (!$entity || !entity_access('view', $entity_type, $entity)) {
return MENU_ACCESS_DENIED;
}
}
// We pass in "all", which doesn't mean anything to og but skips the "default"
// and "admin" functionality that restricts based on user or not user groups.
$instance['field_mode'] = 'all';
// Just use default settings for selection criteria.
$settings = $instance['settings']['behaviors']['og_widget']['default']['widget_settings']['select2widgetajax'];
$handler = entityreference_get_selection_handler($field, $instance, $entity_type, $entity);
$entity_labels = $handler
->getReferencableEntities($string, $settings['match_operator'], 20);
$matches = array();
// Current for the pane config so current isn't hard coded (for cloning).
if ($add_current_option) {
$matches[] = array(
'id' => OA_SPACE_CURRENT,
'title' => _oa_core_select2widget_current_label(),
'data' => '<div class="reference-select2widget">' . _oa_core_select2widget_current_label() . '</div>',
);
}
// Add in an all option so users can see all content.
$matches[] = array(
'id' => 'All',
'title' => _oa_core_select2widget_all_label(),
'data' => '<div class="reference-select2widget">' . _oa_core_select2widget_all_label() . '</div>',
);
$matches = array_merge($matches, select2widget_render_modes($entity_labels, $settings['view_mode'], $field['settings']['target_type']));
drupal_json_output($matches);
}