You are here

function views_megarow_form_wrapper in Views Megarow 7

Wrap a form so that we can use it properly with AJAX. Essentially if the form wishes to render, it automatically does that, otherwise it returns so we can see submission results.

Return value

The output of the form, if it was rendered. If $form_state['ajax'] is set, this will use ctools_megarow_form_render so it will be a $command object suitable for ajax_render already.

The return will be NULL if the form was successfully submitted unless you specifically set re_render = TRUE. If ajax is set the form will never be redirected.

1 call to views_megarow_form_wrapper()
views_megarow_display_form_wrapper in ./views_megarow.module
This callback is just a testing wrapper to display an ajaxified form or its fallback if it's not called through AJAX.

File

./views_megarow.module, line 280

Code

function views_megarow_form_wrapper($form_id, &$form_state, $entity_id) {
  $form_state += array(
    're_render' => FALSE,
    'no_redirect' => !empty($form_state['ajax']),
  );
  $form = drupal_build_form($form_id, $form_state);

  // Add a callback to let the megarow being closed automatically if enabled.
  $form['#submit'][] = 'views_megarow_autoclose_megarow';
  if (!empty($form_state['ajax']) && empty($form_state['executed'])) {
    $output = drupal_render($form);
    $title = empty($form_state['title']) ? drupal_get_title() : $form_state['title'];
    return views_megarow_display($title, $output, $entity_id);
  }
  return $output;
}