2

In order to be able to quickly edit Fullcalendar items, I altered the node edit form of the specific content type so the events are saved with AJAX and the page doesn't have to reload.

However, I don't know how to close the overlay afterwards. I found overlay_close_dialog(), but how do I implement this in my functions (I'm very new to Drupal coding)?

Until now I have:

<?php
/**
* Implements hook_form().
*/
function fullcalendar_ajax_node_save_form_alter(&$form, &$form_state, $form_id) {
  if( $form_id == 'agenda_item_node_form') {
     $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add to Apple Form'),
    '#weight' => 50,
      '#ajax' => array(
        'wrapper' => 'agenda-item-node-form',
        'callback' => 'fullcalendar_ajax_node_save_callback',
        'effect' => 'fade'
        ),
    '#submit' => 
      array (
        0 => 'node_form_submit',
      ),
    );
  }
  return $form;
}

function fullcalendar_ajax_node_save_callback($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
  return $form;
}
?>
0

The callback should be:

function fullcalendar_ajax_node_save_callback(&$form, &$form_state) {
  // Could check that the overlay is open? Part of core, so overkill
  if (module_exists('overlay') && overlay_get_mode() == 'child') {
     $current_path = current_path();
     overlay_close_dialog($current_path, 
        array('query' => drupal_get_query_parameters(NULL, array('q', 'render'))));
    $form_state['redirect'] = FALSE;
  }
}

See overlay.module, about line 148 function overlay_init() for an example in core that uses as much drupal API as possible.

  • Looks promising, but for now, it does nothing. The save works, as I get a message after a reload, but the overlay isn't closed. – user6503 Mar 23 '13 at 11:33
  • Does your callback get called? Netbeans plus debugger is invaluable to me - drupal.org/node/260854. Or use install devel module and use dpm(). #ajax + type = #submit all looks fine. Check the call back in the network tab of a browser inspector such as firebug. – Interlated Mar 23 '13 at 12:10
  • This is the output of the network tab. – user6503 Mar 24 '13 at 14:24
  • /system will send it to the system form. It is at least making a call. You have the option to use '#href' => 'bookreview/volunteer/' and pass it directly to a menu item. My guess is that it is node_form_submit that is being called, not your callback. In the examples module ajax_example_simplest is like yours without #submit. In the standard node processing, you add $form['#submit'][] = '' as the submit handler. – Interlated Mar 26 '13 at 13:24
  • In my case (where there is a confirmation) I had to simply add my handler at the first place of the #submit array, to execute before "add to cart confirmation", eg array_splice($form['#submit'], 0, 0, 'my_custom_callback'); – user25106 Jan 9 '14 at 15:07
0

https://api.drupal.org/api/drupal/modules!overlay!overlay.module/function/overlay_close_dialog/7

function fullcalendar_ajax_node_save_form_alter(&$form, &$form_state, $form_id) {
  if( $form_id == 'agenda_item_node_form') {
     $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add to Apple Form'),
    '#weight' => 50,
      '#ajax' => array(
        'wrapper' => 'agenda-item-node-form',
        'callback' => 'fullcalendar_ajax_node_save_callback',
        'effect' => 'fade'
        ),
    '#submit' => 
      array (
        0 => 'node_form_submit',
        1 => 'your_custom_callback'
      ),
    );
  }
  return $form;
}

function your_custom_callback($form, &$form_state) {

  $url = "<front>";
  if (module_exists('overlay') && overlay_get_mode() == 'child') {
    unset($_GET['destination']);
    overlay_close_dialog($url, array('external' => TRUE));
    $form_state['redirect'] = FALSE;
  } else {
    $form_state['redirect'] = $url;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy