Commit d6d80fb8 authored by webchick's avatar webchick
Browse files

Issue #2257745 by martin107 | ParisLiakos: Switch t() to ->t() in ExceptionController.

parent 340a0fa2
......@@ -602,7 +602,7 @@ services:
arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot']
exception_controller:
class: Drupal\Core\Controller\ExceptionController
arguments: ['@content_negotiation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer']
arguments: ['@content_negotiation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer', '@string_translation']
calls:
- [setContainer, ['@service_container']]
exception_listener:
......
......@@ -19,11 +19,14 @@
use Symfony\Component\Debug\Exception\FlattenException;
use Drupal\Core\ContentNegotiation;
use Drupal\Core\Utility\Error;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* This controller handles HTTP errors generated by the routing system.
*/
class ExceptionController extends HtmlControllerBase implements ContainerAwareInterface {
use StringTranslationTrait;
/**
* The content negotiation library.
......@@ -66,11 +69,12 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn
* @param \Drupal\Core\Page\HtmlFragmentRendererInterface $fragment_renderer
* The fragment rendering service.
*/
public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer) {
public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer, TranslationInterface $string_translation) {
parent::__construct($title_resolver);
$this->negotiation = $negotiation;
$this->htmlPageRenderer = $renderer;
$this->fragmentRenderer = $fragment_renderer;
$this->stringTranslation = $string_translation;
}
/**
......@@ -151,8 +155,8 @@ public function on403Html(FlattenException $exception, Request $request) {
}
else {
$page_content = array(
'#markup' => t('You are not authorized to access this page.'),
'#title' => t('Access denied'),
'#markup' => $this->t('You are not authorized to access this page.'),
'#title' => $this->t('Access denied'),
);
$fragment = $this->createHtmlFragment($page_content, $request);
......@@ -211,8 +215,8 @@ public function on404Html(FlattenException $exception, Request $request) {
}
else {
$page_content = array(
'#markup' => t('The requested page "@path" could not be found.', array('@path' => $request->getPathInfo())),
'#title' => t('Page not found'),
'#markup' => $this->t('The requested page "@path" could not be found.', array('@path' => $request->getPathInfo())),
'#title' => $this->t('Page not found'),
);
$fragment = $this->createHtmlFragment($page_content, $request);
......@@ -306,8 +310,8 @@ public function on500Html(FlattenException $exception, Request $request) {
drupal_set_message($message, $class, TRUE);
}
$content = t('The website has encountered an error. Please try again later.');
$output = DefaultHtmlPageRenderer::renderPage($content, t('Error'));
$content = $this->t('The website has encountered an error. Please try again later.');
$output = DefaultHtmlPageRenderer::renderPage($content, $this->t('Error'));
$response = new Response($output);
$response->setStatusCode(500, '500 Service unavailable (with message)');
......
......@@ -38,13 +38,14 @@ public function test405HTML() {
$html_page_renderer = $this->getMock('Drupal\Core\Page\HtmlPageRendererInterface');
$html_fragment_renderer = $this->getMock('Drupal\Core\Page\HtmlFragmentRendererInterface');
$title_resolver = $this->getMock('Drupal\Core\Controller\TitleResolverInterface');
$translation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
$content_negotiation = $this->getMock('Drupal\Core\ContentNegotiation');
$content_negotiation->expects($this->any())
->method('getContentType')
->will($this->returnValue('html'));
$exception_controller = new ExceptionController($content_negotiation, $title_resolver, $html_page_renderer, $html_fragment_renderer);
$exception_controller = new ExceptionController($content_negotiation, $title_resolver, $html_page_renderer, $html_fragment_renderer, $translation);
$response = $exception_controller->execute($flat_exception, new Request());
$this->assertEquals($response->getStatusCode(), 405, 'HTTP status of response is correct.');
$this->assertEquals($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment