You are here

function entityreference_view_widget_ajax in Entity Reference View Widget 7

Same name and namespace in other branches
  1. 7.2 entityreference_view_widget.module \entityreference_view_widget_ajax()

Custom #ajax callback.

1 string reference to 'entityreference_view_widget_ajax'
entityreference_view_widget_menu in ./entityreference_view_widget.module
Implements hook_menu().

File

./entityreference_view_widget.module, line 73

Code

function entityreference_view_widget_ajax() {

  // Reset the cache of IDs. Drupal rather aggressively prevents id duplication
  // but this causes it to remember IDs that are no longer even being used.
  // Taken from Views.
  if (isset($_POST['ajax_html_ids'])) {
    unset($_POST['ajax_html_ids']);
  }

  // Include the node.pages when processing the form
  form_load_include($form_state, 'inc', 'node', 'node.pages');
  list($form, $form_state) = ajax_get_form();
  drupal_process_form($form['#form_id'], $form, $form_state);
  $form_parents = func_get_args();

  // Retrieve the element to be rendered.
  $form = drupal_array_get_nested_value($form, $form_parents);
  $output = drupal_render($form);
  $js = drupal_add_js();
  $settings = call_user_func_array('array_merge_recursive', $js['settings']['data']);
  $commands = array();
  $commands[] = ajax_command_replace(NULL, $output, $settings);
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}