function CommentController::redirectNode

Same name in other branches
  1. 9 core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::redirectNode()
  2. 8.9.x core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::redirectNode()
  3. 10 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 174

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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.