You are here

function node_registration_toggle_flag in Node registration 7

Page callback for registration/%node_registration/toggle/ajax/%/%.

1 string reference to 'node_registration_toggle_flag'
node_registration_menu in ./node_registration.module
Implements hook_menu().

File

includes/node_registration.forms.inc, line 11
New registration forms. Public and admin.

Code

function node_registration_toggle_flag($registration, $ajax, $field, $new_value) {
  $ajax = $ajax == 'ajax';
  $registration->{$field} = (int) (bool) $new_value;
  $registration
    ->save();
  if ($ajax) {

    // Drupal 7.39+ is paranoid about their Ajax URLs.
    // @see ajax.options.success in ajax.js.
    if (function_exists('ajax_set_verification_header')) {
      ajax_set_verification_header();
    }

    // What a mess, just to reload the page. CTools doesn't help here either.
    $commands = array(
      ajax_command_prepend('head', '<script>location.reload()</script>'),
    );
    print drupal_json_encode($commands);
    exit;
  }
  drupal_goto();
}