You are here

function modal_forms_comment_reply in Modal forms (with ctools) 7

A modal comment callback.

1 string reference to 'modal_forms_comment_reply'
modal_forms_menu in ./modal_forms.module
Implements hook_menu().

File

./modal_forms.pages.inc, line 189
Page callbacks for the modal_forms module.

Code

function modal_forms_comment_reply($node, $js = NULL, $pid = NULL) {
  $output = array();
  $comment = array(
    'pid' => $pid,
    'nid' => $node->nid,
  );

  // Fall back if $js is not set.
  if (!$js) {
    return drupal_get_form('comment_node_' . $node->type . '_form', (object) $comment);
  }
  ctools_include('modal');
  ctools_include('ajax');
  $form_state = array(
    'build_info' => array(
      'args' => array(
        (object) $comment,
      ),
    ),
    // 'title' => t('Comment'),.
    'ajax' => TRUE,
    're_render' => FALSE,
    'no_redirect' => TRUE,
  );

  // Should we show the reply box?
  if ($node->comment != COMMENT_NODE_OPEN) {
    drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
    drupal_goto('node/' . $node->nid);
  }
  else {
    $output = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);

    // Remove output bellow the comment.
    unset($output['comment_output_below']);
  }
  if (!$form_state['executed'] || $form_state['rebuild']) {
    $output = ctools_modal_form_render($form_state, $output);
  }
  else {

    // We'll just overwrite the form output if it was successful.
    $output = array();

    // @todo: Uncomment once http://drupal.org/node/1587916 is fixed.
    // @codingStandardsIgnoreStart
    // @code
    // if (is_array($form_state['redirect'])) {
    //  list($path, $options) = $form_state['redirect'];
    //  $output[] = ctools_ajax_command_redirect($path, 0, $options);
    // }
    // @endcode
    // @codingStandardsIgnoreEnd
    if (isset($_GET['destination'])) {
      $output[] = ctools_ajax_command_redirect($_GET['destination']);
    }
    else {
      $output[] = ctools_ajax_command_reload();
    }
  }
  print ajax_render($output);
}