public function mentionPermalink(MentionsInterface $mentions) {
    if ($entity = $mentions->getMentionedEntity()) {
      // Check access permissions for the entity.
      if (!$entity->access('view')) {
        throw new AccessDeniedHttpException();
      }
      $entity_url = $entity->toUrl('canonical');
      return new RedirectResponse($entity_url->setAbsolute()->toString());
    }
    throw new NotFoundHttpException();
  }