public function CommentController::redirectNode in Drupal 8
Same name and namespace in other branches
- 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 198
Class
- CommentController
- Controller for the comment entity.
Namespace
Drupal\comment\ControllerCode
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();
}