public CommentController::redirectNode(EntityInterface $node)
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
File
- core/modules/comment/src/Controller/CommentController.php, line 172
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', array(
'entity_type' => 'node',
'entity' => $node->id(),
'field_name' => $field_name,
));
}
throw new NotFoundHttpException();
}
Please login to continue.