You are here

entityreference_autofill_og.module in Entity reference autofill 7

Entity reference autofill OG module.

File

entityreference_autofill_og/entityreference_autofill_og.module
View source
<?php

/**
 * @file
 * Entity reference autofill OG module.
 */

/**
 * Implements hook_entityreference_autofill_supported_widgets().
 */
function entityreference_autofill_og_entityreference_autofill_supported_widgets() {

  // Add support for organic groups widget.
  // By setting value to NULL, no ajax wrapper will be
  // added to the field itself, but both group and
  // admin selection fields will be autofill-enabled.
  return array(
    'og_complex' => NULL,
  );
}

/**
 * Implements hook_entityreference_autofill_detach_ajax().
 */
function entityreference_autofill_og_entityreference_autofill_detach_ajax($field_name, $element, $context) {

  // Do not attach AJAX callback to OG admin fields.
  if (og_is_group_audience_field($field_name)) {
    if (isset($context['instance']['field_mode']) && $context['instance']['field_mode'] == 'admin') {
      return FALSE;
    }
  }
}

/**
 * Implements hook_entityreference_autofill_target_id_alter().
 */
function entityreference_autofill_og_entityreference_autofill_target_id_alter(&$target_id, &$form_state, $context) {

  // Fetch value from form input array instead of values.
  if (og_is_group_audience_field($context['field_name'])) {
    $field_parents = $form_state['triggering_element']['#parents'];
    $target_id = drupal_array_get_nested_value($form_state['input'], $field_parents);
  }
}