Не добавляются комментарии из формы подгруженной аяксом на страницу views

Главные вкладки

Аватар пользователя Navigator Navigator 15 февраля 2015 в 7:58

Есть страница views на которой выводятся ноды. Нужно сделать, возможность добавления комментариев без перехода на страницу самой ноды. Я сделал подгрузку формы комментариев аяксом. Вроде все должно работать, но нет, комментарии не добавляются. Просто происходит переход на страницу с формой комментирования (.../comment/reply/12#comment-form) и все. В этой форме комментарий уже добавляется.
Почему так происходит? Ведь код у подгружаемой аяксом и той на которую переходит одинаковый.

Комментарии

Аватар пользователя Navigator Navigator 15 февраля 2015 в 17:37

"<a href="mailto:sas@drupal.org">sas@drupal.org</a>" wrote:
Делали этим https://www.drupal.org/project/ajax_comments или этим - https://www.drupal.org/project/ajax_form_entity?[/quote]
Нет, сначала было сделано с помощью "drupal_get_form", но это отказалось работать.
Затем попробовал изменить функцию "modal_forms_comment_reply" из модуля "modal_forms". Получилось, подгружается, работает, но не получается заставить работать аякс.

<?php/**
 * A modal comment callback.
 */
function modal_forms_comment_reply($js = NULL, $node, $pid = NULL) {
  $output = array();
  $comment = array(
    'pid' => $pid,
    'nid' => $node->nid,
  );

  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.
    //if (is_array($form_state['redirect'])) {
    //  list($path, $options) = $form_state['redirect'];
    //  $output[] = ctools_ajax_command_redirect($path, 0, $options);
    //}
    if (isset($_GET['destination'])) {
      $output[] = ctools_ajax_command_redirect($_GET['destination']);
    }
    else {
      $output[] = ctools_ajax_command_reload();
    }
  }

  print ajax_render($output);
}?>