Commit f32f77f3 authored by plach's avatar plach
Browse files

Issue #3130438 by stefanos.petrakis, andypost, longwave: Inject...

Issue #3130438 by stefanos.petrakis, andypost, longwave: Inject page_cache_kill_switch service to LanguageNegotiationBrowser

(cherry picked from commit b152620e)
parent 6c767cd3
......@@ -3,7 +3,9 @@
namespace Drupal\language\Plugin\LanguageNegotiation;
use Drupal\Component\Utility\UserAgent;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\language\LanguageNegotiationMethodBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -17,13 +19,29 @@
* config_route_name = "language.negotiation_browser"
* )
*/
class LanguageNegotiationBrowser extends LanguageNegotiationMethodBase {
class LanguageNegotiationBrowser extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface {
/**
* The language negotiation method id.
*/
const METHOD_ID = 'language-browser';
/**
* The page cache disabling policy.
*
* @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch
*/
protected $pageCacheKillSwitch;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static();
$instance->pageCacheKillSwitch = $container->get('page_cache_kill_switch');
return $instance;
}
/**
* {@inheritdoc}
*/
......@@ -41,7 +59,7 @@ public function getLangcode(Request $request = NULL) {
// could lead to wrong cached sites. Therefore disabling the internal page
// cache.
// @todo Solve more elegantly in https://www.drupal.org/node/2430335.
\Drupal::service('page_cache_kill_switch')->trigger();
$this->pageCacheKillSwitch->trigger();
return $langcode;
}
......
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