diff --git a/core/core.services.yml b/core/core.services.yml index 91689601dd85eb2983b50ea8386718cc827b082a..9e2e1889bdd52f6dc7341f652b71b9fe3861f291 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -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: diff --git a/core/lib/Drupal/Core/Controller/ExceptionController.php b/core/lib/Drupal/Core/Controller/ExceptionController.php index 4333ffef58ab67c1522ebc9d55436fd86c73612a..4c656aea271d0c27987a10c76b2f24cd5cd2009e 100644 --- a/core/lib/Drupal/Core/Controller/ExceptionController.php +++ b/core/lib/Drupal/Core/Controller/ExceptionController.php @@ -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)'); diff --git a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php index 7597dea27f18890795c2b27ba0a3d1a0efc84a5b..34f2af912423713c003edcad3d7648888b36be11 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php @@ -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.');