You are here

function tablefield_rebuild_form_ajax in TableField 7.2

Same name and namespace in other branches
  1. 7.3 tablefield.module \tablefield_rebuild_form_ajax()
  2. 7 tablefield.module \tablefield_rebuild_form_ajax()

AJAX callback to rebuild the number of rows/columns.

The basic idea is to descend down the list of #parent elements of the clicked_button in order to locate the tablefield inside of the $form array. That is the element that we need to return.

1 string reference to 'tablefield_rebuild_form_ajax'
tablefield_field_widget_form in ./tablefield.module
Implements hook_widget_form().

File

./tablefield.module, line 1316
Provides a set of fields that can be used to store tabular data with a node.

Code

function tablefield_rebuild_form_ajax($form, $form_state) {
  $parents = $form_state['triggering_element']['#array_parents'];

  // We do not want to go as deep as rebuild/rebuild or import/import,
  // i.e. the triggering buttons.
  array_pop($parents);
  array_pop($parents);
  $rebuild = drupal_array_get_nested_value($form, $parents);

  // We don't want to re-send the format/_weight options.
  unset($rebuild['format']);
  unset($rebuild['_weight']);

  // We need to avoid sending headers or the multipart form
  // will make it fail. So, we need to explicitly define the
  // whole response to ajax_deliver().
  return array(
    '#type' => 'ajax',
    '#header' => FALSE,
    '#commands' => array(
      ajax_command_insert(NULL, drupal_render($rebuild)),
      ajax_command_prepend(NULL, theme('status_messages')),
    ),
  );
}