Skip to content
Snippets Groups Projects
Commit f32f77f3 authored by Francesco Placella's avatar Francesco Placella
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
Branches
Tags
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment