1 layout.admin.inc layout_ajax_form_save_dialog($form, $form_state)

AJAX handler that saves a form in a dialog and updates the underlying form.

This is meant for generic use. It depends on a few variables in $form_state:

  • $form_state['ajax_rebuild_form']: The function name that builds the underlying form that will be updated.
  • $form_state['ajax_update']: An array of keys representing the portion of the form that should be updated.
  • $form_state['redirect']: If specified, the redirect location will be opened as a dialog, acting as a tool to open a sequence of forms in dialogs.

See also

layout_ajax_form_update()

File

core/modules/layout/layout.admin.inc, line 2571
Administrative functions for Layout module.

Code

function layout_ajax_form_save_dialog($form, $form_state) {
  /* @var Layout $layout */
  $layout = $form_state['layout'];
  /* @var LayoutMenuItem $menu_item */
  $menu_item = isset($form_state['menu_item']) ? $form_state['menu_item'] : '';

  $commands = array();
  $commands[] = ajax_command_close_modal_dialog();

  // If errors occurred in the dialog, show messages and re-display.
  if (form_get_errors()) {
    $html = '';
    $html .= theme('status_messages');
    $html .= backdrop_render($form);
    $title = isset($form['#title']) ? $form['#title'] : backdrop_get_title();
    $commands[] = ajax_command_open_modal_dialog($title, $html, array('dialogClass' => 'layout-dialog'));
  }
  else {
    // If there is a part of the page that needs to be updated, update it.
    if (!empty($form_state['ajax_update'])) {
      $update_ajax = layout_ajax_form_update($form, $form_state);
      $commands = array_merge($commands, $update_ajax['#commands']);
    }

    // If there is a second action that needs to be executed, open the next page.
    elseif (!empty($form_state['redirect'])) {
      $dialog_ajax = layout_ajax_form_open_dialog($form, $form_state);
      $commands = array_merge($commands, $dialog_ajax['#commands']);
    }

    // Clear out previous messages.
    if ($message = layout_locked_message($layout, 'layout')) {
      backdrop_set_message($message, 'warning');
    }
    elseif ($message = layout_locked_message($menu_item, 'menu_item')) {
      backdrop_set_message($message, 'warning');
    }
    $commands[] = ajax_command_remove('#messages');
    $commands[] = ajax_command_html('#layout-messages', theme('status_messages'));
  }

  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}