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

8.0.x
webchick 2014-05-03 22:29:57 -07:00
parent 340a0fa216
commit d6d80fb871
3 changed files with 14 additions and 9 deletions

View File

@ -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:

View File

@ -19,11 +19,14 @@ use Drupal\Component\Utility\String;
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 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn
}
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 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn
}
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 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn
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)');

View File

@ -38,13 +38,14 @@ class ExceptionControllerTest extends UnitTestCase {
$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.');