SocialCommentController.php in Open Social 8
Same filename and directory in other branches
- 8.9 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.2 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.3 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.4 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.5 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.6 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.7 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 8.8 modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 10.3.x modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 10.0.x modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 10.1.x modules/social_features/social_comment/src/Controller/SocialCommentController.php
- 10.2.x modules/social_features/social_comment/src/Controller/SocialCommentController.php
Namespace
Drupal\social_comment\ControllerFile
modules/social_features/social_comment/src/Controller/SocialCommentController.phpView source
<?php
namespace Drupal\social_comment\Controller;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Url;
use Drupal\comment\CommentInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\comment\Controller\CommentController;
/**
* Controller routine override to change relevant bits in the password reset.
*/
class SocialCommentController extends CommentController {
/**
* Redirects comment links to the correct page depending on permissions.
*
* @inheritdoc
*/
public function commentPermalink(Request $request, CommentInterface $comment) {
if ($entity = $comment
->getCommentedEntity()) {
// Check access permissions for the entity.
/* @var \Drupal\Core\Entity\Entity $entity */
if (!$entity
->access('view')) {
throw new AccessDeniedHttpException();
}
/* @var \Drupal\Core\Url $url */
if ($url = $entity
->urlInfo('canonical')) {
// Redirect the user to the correct entity.
return $this
->redirectToOriginalEntity($url, $comment, $entity);
}
}
throw new NotFoundHttpException();
}
/**
* Redirects to the original entity when conditions are met.
*
* @param \Drupal\Core\Url $url
* The canonical url.
* @param \Drupal\comment\CommentInterface $comment
* The comment interface.
* @param \Drupal\Core\Entity\Entity $entity
* The Entity to redirect to.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* Returns the Redirect Response.
*/
public function redirectToOriginalEntity(Url $url, CommentInterface $comment = NULL, Entity $entity = NULL) {
$options = [];
if (isset($comment)) {
$options = [
'fragment' => 'comment-' . $comment
->id(),
];
}
return $this
->redirect($url
->getRouteName(), $url
->getRouteParameters(), $options);
}
}
Classes
Name![]() |
Description |
---|---|
SocialCommentController | Controller routine override to change relevant bits in the password reset. |