Making FinishResponseSubscriber dependent on the language_manager service

8.0.x
Katherine Bailey 2012-07-28 20:54:12 -07:00
parent 33b5c4b6ef
commit 5d8b06a17f
3 changed files with 16 additions and 3 deletions

View File

@ -55,6 +55,8 @@ class CoreBundle extends Bundle
$container->register('legacy_controller_subscriber', 'Drupal\Core\EventSubscriber\LegacyControllerSubscriber')
->addTag('kernel.event_subscriber');
$container->register('finish_response_subscriber', 'Drupal\Core\EventSubscriber\FinishResponseSubscriber')
->addArgument(new Reference('language_manager'))
->setScope('request')
->addTag('kernel.event_subscriber');
$container->register('request_close_subscriber', 'Drupal\Core\EventSubscriber\RequestCloseSubscriber')
->addTag('kernel.event_subscriber');

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Language\LanguageManager;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -16,6 +17,12 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/
class FinishResponseSubscriber implements EventSubscriberInterface {
private $language_manager;
public function __construct(LanguageManager $language_manager) {
$this->language_manager = $language_manager;
}
/**
* Sets extra headers on successful responses.
*
@ -30,7 +37,7 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
$response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', false);
// Set the Content-language header.
$response->headers->set('Content-language', language_manager(LANGUAGE_TYPE_INTERFACE)->langcode);
$response->headers->set('Content-language', $this->language_manager->getLanguage(LANGUAGE_TYPE_INTERFACE)->langcode);
// Because pages are highly dynamic, set the last-modified time to now
// since the page is in fact being regenerated right now.

View File

@ -10,8 +10,12 @@ namespace Drupal\Core\Language;
use Symfony\Component\HttpFoundation\Request;
/**
* The LanguageManager service intializes the language types passing in the
* Request object, which can then be used for e.g. url-based language negotiation.
* Class responsible for initializing each language type.
*
* This service is dependent on the 'request' service and can therefore pass the
* Request object to the code that deals with each particular language type.
* This means the Request can be used directly for things like url-based language
* negotiation.
*/
class LanguageManager {