You are here

function party_activity_modal_form_wrapper in Party 7

Modal Form Wrapper.

Parameters

$activity: The activity object to edit.

$js:

1 call to party_activity_modal_form_wrapper()
party_activity_modal_add_form_wrapper in modules/party_activity/party_activity.admin.inc
Modal add form wrapper.
1 string reference to 'party_activity_modal_form_wrapper'
PartyActivityUIController::hook_menu in modules/party_activity/party_activity.admin.inc
Overrides hook_menu() defaults. Main reason for doing this is that parent class hook_menu is optimized for entity type administration.

File

modules/party_activity/party_activity.admin.inc, line 211
Party Activity editing UI

Code

function party_activity_modal_form_wrapper($activity, $js = FALSE) {
  if (!$js) {
    return drupal_get_form('party_activity_form', $activity);
  }
  ctools_include('ajax');
  ctools_include('modal');

  // Work out Form title and operation.
  if (empty($activity->id)) {
    $op = 'create';
    $info = entity_get_info('party_activity');
    $title = t('Add !label', array(
      '!label' => $info['label'],
    ));
  }
  else {
    $op = 'edit';
    $title = t('Edit @label', array(
      '@label' => $activity->title,
    ));
  }
  $form_state = array(
    'title' => $title,
    'ajax' => TRUE,
    'build_info' => array(
      'args' => array(
        $activity,
        $op,
      ),
    ),
    'context' => array(
      'fc' => $_GET['fc'],
      'views_view' => $_GET['views_view'],
      'views_display' => $_GET['views_display'],
    ),
  );
  $commands = ctools_modal_form_wrapper('party_activity_form', $form_state);
  if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
    $updated = $form_state['party_activity'];

    // Overwrite the output if form submission was successfully executed.
    $commands = array();
    if (empty($form_state['context']['fc'])) {
      $commands[] = ctools_ajax_command_reload();
    }
    else {
      $view = views_get_view($form_state['context']['views_view']);
      $view
        ->set_display($form_state['context']['views_display']);
      module_load_include('inc', 'party_activity', 'party_activity.ajax');
      $commands[] = ctools_modal_command_dismiss();
      if ($form_state['op'] == 'create') {
        $commands[] = party_activity_command_fullcalendar_add($updated, $view);
      }
      else {
        $commands[] = party_activity_command_fullcalendar_update($updated, $view);
      }
    }
  }
  $output = array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
  ajax_deliver($output);
  drupal_exit();
}