You are here

public function CommentController::redirectNode in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::redirectNode()
  2. 9 core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::redirectNode()

Redirects legacy node links to the new path.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node object identified by the legacy URL.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirects user to new url.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

1 string reference to 'CommentController::redirectNode'
comment.routing.yml in core/modules/comment/comment.routing.yml
core/modules/comment/comment.routing.yml

File

core/modules/comment/src/Controller/CommentController.php, line 190

Class

CommentController
Controller for the comment entity.

Namespace

Drupal\comment\Controller

Code

public function redirectNode(EntityInterface $node) {
  $fields = $this->commentManager
    ->getFields('node');

  // Legacy nodes only had a single comment field, so use the first comment
  // field on the entity.
  if (!empty($fields) && ($field_names = array_keys($fields)) && ($field_name = reset($field_names))) {
    return $this
      ->redirect('comment.reply', [
      'entity_type' => 'node',
      'entity' => $node
        ->id(),
      'field_name' => $field_name,
    ]);
  }
  throw new NotFoundHttpException();
}