You are here

function entityreference_autofill_get_ajax_parents in Entity reference autofill 7

Find element parent as defined by entityreference_autofill_supported_widgets().

Parameters

array $parents: Parents array returned by entityreference_autofill_supported_widgets().

array &$element: The root element of $parents.

Return value

&array Array of references to where in $element to add AJAX callback.

1 call to entityreference_autofill_get_ajax_parents()
entityreference_autofill_field_widget_form_alter in ./entityreference_autofill.module
Implements hook_field_widget_form_alter().

File

./entityreference_autofill.module, line 71
Entity reference autofill module.

Code

function &entityreference_autofill_get_ajax_parents($parents, &$element) {
  $ajax_parents = array();

  // Empty arrays in the parent array are interpreted as element children.
  foreach ($parents as $key => $parent) {
    if (is_array($parent)) {
      $remainder = array_slice($parents, $key + 1);
      $parents = array_slice($parents, 0, $key);
      $element =& drupal_array_get_nested_value($element, $parents);
      foreach (element_children($element) as $key) {
        $sub_parents =& entityreference_autofill_get_ajax_parents($remainder, $element[$key]);
        $ajax_parents =& array_merge($ajax_parents, $sub_parents);
      }
      return $ajax_parents;
    }
  }
  $ajax_parents[] =& drupal_array_get_nested_value($element, $parents);
  return $ajax_parents;
}