You are here

function oa_core_og_group_ref_process in Open Atrium Core 7.2

Process function of the og_group_ref field.

1 string reference to 'oa_core_og_group_ref_process'
oa_core_element_info in includes/oa_core.fields.inc
Implements hook_element_info().

File

includes/oa_core.fields.inc, line 26
Code for custom Form API fields in Open Atrium

Code

function oa_core_og_group_ref_process($element, &$form_state, &$complete_form) {
  global $user;
  $element += array(
    '#title' => t('Space'),
    '#description' => t('Select a space'),
  );
  if (empty($element['#use_select'])) {

    // Below is mocking what og/select2widget does so it thinks this is a
    // select2 element.
    $field = field_info_field('og_group_ref');
    $type = 'select2widgetajax';
    $required = !empty($element['#required']);
    $has_value = !empty($element['#default_value']);
    $instance = _oa_core_get_og_group_ref_mocked_field_instance();
    $settings = $instance['widget']['settings'];
    $id = 'NULL';
    $entity_labels = _oa_core_select2widget_process_entity_labels($element['#default_value']);
    $autocomplete_path = (!empty($element['#allow_current']) ? 'oacoreselect2widgetpanes' : 'oacoreselect2widget') . '/ajax/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $id . '?field_mode=all';
    $element = array(
      '#type' => 'textfield',
      '#default_value' => implode(',', $entity_labels),
      '#autocomplete_path' => $autocomplete_path,
      '#element_validate' => array(
        'oa_core_select2widget_entity_validate_field',
      ),
      '#settings' => $instance['widget']['settings'],
      '#maxlength' => 1024,
      '#init' => $entity_labels,
      '#field_name' => 'og_group_ref',
      '#language' => LANGUAGE_NONE,
      '#bundle' => $instance['bundle'],
      '#entity_type' => 'node',
      '#field' => $field,
      '#field_parents' => array(),
    ) + $element;
    if (!empty($element['#multiple'])) {
      $element['#field']['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
    }
    $element['#settings']['select2widgetajax']['width'] = '300px';
    $element['#settings']['select2widgetajax']['min_char'] = 0;
    $form_state['field'][$element['#field_name']][$element['#language']]['field'] = $field;
    $element = oa_core_exposed_og_group_ref_fix_cardinality($element, $form_state, $complete_form);
    $element = select2widget_entity_process_callback($element, $form_state, $complete_form);
  }
  else {
    $element['#type'] = 'select';
    $element['#options'][-1] = t(' - Current Space - ');
    if (empty($element['#required'])) {
      $element['#options'][0] = t(' - Any - ');
    }
    if (($groups = oa_core_get_groups_by_user($user, 'node')) && ($titles = oa_core_get_titles($groups, '', 'title', array(
      'title',
    ), TRUE, 100))) {
      $element['#options'] += $titles['titles'];
    }
  }
  $element += element_info($element['#type']);
  return $element;
}