Account created on 25 January 2014, over 10 years ago
#

Merge Requests

Recent comments

πŸ‡«πŸ‡·France urashima82

Hello, I'm sending a new patch because I was facing an issue when I tried to display comments. Due to a strange behavior of the comment_count property, the comments are not always shown.

I replace that by an entity query and it works.

To respond to @bigboy, I was facing the same redirect problem. To solve that, I used the hook_form to add my custom submit method.
Here is en example, feel free to improved it :

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $comment_forms = [
    'comment_comment_form',
    'comment_comment_edit_form',
    'comment_comment_delete_form',
  ];
  if (in_array($form_id, $comment_forms)) {
    $form['actions']['submit']['#submit'][] = 'my_module_comment_fix_form_submit';
  }
}

function my_module_comment_fix_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $route_params = \Drupal::routeMatch()->getParameters();
  if ($route_params->has('entity')) {
    $node = \Drupal::routeMatch()->getParameter('entity');
  }
  else {
    // Get the comment entity.
    $comment = \Drupal::routeMatch()->getParameter('comment');
    // Get the node entity.
    $node = $comment->getCommentedEntity();
  }
  // Get translated url.
  $url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $node->id()]);
  $form_state->setRedirectUrl($url);
}
Production build 0.69.0 2024