diff --git a/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php index 3dc6a3e..38dd91f 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php @@ -40,10 +40,19 @@ public function build(array $attributes) { if (isset($attributes[RouteObjectInterface::ROUTE_NAME]) && $attributes[RouteObjectInterface::ROUTE_NAME] == 'comment_reply' && isset($attributes['node'])) { $node = $attributes['node']; $uri = $node->uri(); - $breadcrumb[] = l($this->translation->translate('Home'), NULL); + $breadcrumb[] = l($this->t('Home'), NULL); $breadcrumb[] = l($node->label(), $uri['path']); return $breadcrumb; } } + /** + * Translates a string to the current language or to a given language. + * + * See the t() documentation for details. + */ + protected function t($string, array $args = array(), array $options = array()) { + return $this->translation->translate($string, $args, $options); + } + } diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index 1caea86..d3f4150 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -10,10 +10,8 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\Core\Access\CsrfTokenGenerator; +use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityManager; -use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\StringTranslation\TranslationManager; use Drupal\Node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -27,21 +25,7 @@ * * @see \Drupal\comment\Entity\Comment. */ -class CommentController implements ContainerInjectionInterface { - - /** - * The entity manager service. - * - * @var \Drupal\Core\Entity\EntityManager - */ - protected $entityManager; - - /** - * The url generator service. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; +class CommentController extends ControllerBase implements ContainerInjectionInterface { /** * The HTTP kernel. @@ -51,13 +35,6 @@ class CommentController implements ContainerInjectionInterface { protected $httpKernel; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationManager - */ - protected $translation; - - /** * The CSRF token manager service. * * @var \Drupal\Core\Access\CsrfTokenGenerator @@ -67,22 +44,13 @@ class CommentController implements ContainerInjectionInterface { /** * Constructs a CommentController object. * - * @param \Drupal\Core\Entity\EntityManager $entity_manager - * The entity manager. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator service. * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel * HTTP kernel to handle requests. - * @param \Drupal\Core\StringTranslation\TranslationManager $translation - * The translation manager. * @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token * The CSRF token manager service. */ - public function __construct(EntityManager $entity_manager, UrlGeneratorInterface $url_generator, HttpKernelInterface $httpKernel, TranslationManager $translation, CsrfTokenGenerator $csrf_token) { - $this->entityManager = $entity_manager; - $this->urlGenerator = $url_generator; + public function __construct(HttpKernelInterface $httpKernel, CsrfTokenGenerator $csrf_token) { $this->httpKernel = $httpKernel; - $this->translation = $translation; $this->csrfToken = $csrf_token; } /** @@ -90,10 +58,7 @@ public function __construct(EntityManager $entity_manager, UrlGeneratorInterface */ public static function create(ContainerInterface $container) { return new static( - $container->get('plugin.manager.entity'), - $container->get('url_generator'), $container->get('http_kernel'), - $container->get('string_translation'), $container->get('csrf_token') ); } @@ -122,10 +87,10 @@ public function commentApprove(Request $request, CommentInterface $comment) { $comment->status->value = COMMENT_PUBLISHED; $comment->save(); - drupal_set_message($this->translation->translate('Comment approved.')); + drupal_set_message($this->t('Comment approved.')); $permalink_uri = $comment->permalink(); $permalink_uri['options']['absolute'] = TRUE; - $url = $this->urlGenerator->generateFromPath($permalink_uri['path'], $permalink_uri['options']); + $url = $this->urlGenerator()->generateFromPath($permalink_uri['path'], $permalink_uri['options']); return new RedirectResponse($url); } @@ -202,58 +167,58 @@ public function commentPermalink(Request $request, CommentInterface $comment) { public function getReplyForm(Request $request, NodeInterface $node, $pid = NULL) { $uri = $node->uri(); $build = array(); - $account = $request->attributes->get('_account'); + $account = $this->currentUser(); - $build['#title'] = $this->translation->translate('Add new comment'); + $build['#title'] = $this->t('Add new comment'); // Check if the user has the proper permissions. if (!$account->hasPermission('post comments')) { - drupal_set_message($this->translation->translate('You are not authorized to post comments.'), 'error'); - return new RedirectResponse($this->urlGenerator->generateFromPath($uri['path'], array('absolute' => TRUE))); + drupal_set_message($this->t('You are not authorized to post comments.'), 'error'); + return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } // The user is not just previewing a comment. - if ($request->request->get('op') != $this->translation->translate('Preview')) { + if ($request->request->get('op') != $this->t('Preview')) { if ($node->comment->value != COMMENT_NODE_OPEN) { - drupal_set_message($this->translation->translate("This discussion is closed: you can't post new comments."), 'error'); - return new RedirectResponse($this->urlGenerator->generateFromPath($uri['path'], array('absolute' => TRUE))); + drupal_set_message($this->t("This discussion is closed: you can't post new comments."), 'error'); + return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } // $pid indicates that this is a reply to a comment. if ($pid) { // Check if the user has the proper permissions. if (!$account->hasPermission('access comments')) { - drupal_set_message($this->translation->translate('You are not authorized to view comments.'), 'error'); - return new RedirectResponse($this->urlGenerator->generateFromPath($uri['path'], array('absolute' => TRUE))); + drupal_set_message($this->t('You are not authorized to view comments.'), 'error'); + return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } // Load the parent comment. - $comment = $this->entityManager->getStorageController('comment')->load($pid); + $comment = $this->entityManager()->getStorageController('comment')->load($pid); // Check if the parent comment is published and belongs to the current nid. if (($comment->status->value == COMMENT_NOT_PUBLISHED) || ($comment->nid->target_id != $node->id())) { - drupal_set_message($this->translation->translate('The comment you are replying to does not exist.'), 'error'); - return new RedirectResponse($this->urlGenerator->generateFromPath($uri['path'], array('absolute' => TRUE))); + drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error'); + return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } // Display the parent comment. - $build['comment_parent'] = $this->entityManager->getRenderController('comment')->view($comment); + $build['comment_parent'] = $this->entityManager()->getRenderController('comment')->view($comment); } // The comment is in response to a node. elseif ($account->hasPermission('access content')) { // Display the node. - $build['comment_node'] = $this->entityManager->getRenderController('node')->view($node); + $build['comment_node'] = $this->entityManager()->getRenderController('node')->view($node); } } else { - $build['#title'] = $this->translation->translate('Preview comment'); + $build['#title'] = $this->t('Preview comment'); } // Show the actual reply box. - $comment = $this->entityManager->getStorageController('comment')->create(array( + $comment = $this->entityManager()->getStorageController('comment')->create(array( 'nid' => $node->id(), 'pid' => $pid, 'node_type' => 'comment_node_' . $node->getType(), )); - $build['comment_form'] = $this->entityManager->getForm($comment); + $build['comment_form'] = $this->entityManager()->getForm($comment); return $build; }