Skip to content
Snippets Groups Projects
Commit ed270683 authored by nterbogt's avatar nterbogt Committed by Nathan ter Bogt
Browse files

Coding standards and cleanups.

parent f027047f
Branches
Tags
No related merge requests found
......@@ -2,13 +2,12 @@
namespace Drupal\smartip_language_detection\Plugin\LanguageNegotiation;
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\smart_ip\SmartIp;
use Drupal\smartip_language_detection\Entity\SmartIpLanguageMapping;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -17,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
* @LanguageNegotiation(
* id = Drupal\smartip_language_detection\Plugin\LanguageNegotiation\SmartIpLanguageDetection::METHOD_ID,
* weight = -1,
* name = @Translation("IP address"),
* name = @Translation("Smart IP"),
* description = @Translation("Uses Smart IP to get language based on visitor's IP address."),
* config_route_name = "smartip.language_detection"
* )
......@@ -30,20 +29,20 @@ class SmartIpLanguageDetection extends LanguageNegotiationMethodBase implements
const METHOD_ID = 'smartip-language-detection';
/**
* The state service.
* The page cache kill switch.
*
* @var \Drupal\Core\State\StateInterface
* @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch
*/
protected $state;
protected $pageCacheKillSwitch;
/**
* Constructs a new SmartIpLanguageDetection instance.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $page_cache_kill_switch
* The page cache kill switch service.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
public function __construct(KillSwitch $page_cache_kill_switch) {
$this->pageCacheKillSwitch = $page_cache_kill_switch;
}
/**
......@@ -51,7 +50,7 @@ class SmartIpLanguageDetection extends LanguageNegotiationMethodBase implements
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$container->get('state')
$container->get('page_cache_kill_switch')
);
}
......@@ -65,11 +64,10 @@ class SmartIpLanguageDetection extends LanguageNegotiationMethodBase implements
return $langcode;
}
\Drupal::service('page_cache_kill_switch')->trigger();
$this->pageCacheKillSwitch->trigger();
// We can't use the service here because it uses sessions, and they hurt us.
$ip = \Drupal::request()->getClientIp();
$location = SmartIp::query($ip);
$location = SmartIp::query($request->getClientIp());
// Defensive checking for country code.
if (!isset($location['countryCode'])) {
......
......@@ -4,7 +4,6 @@ namespace Drupal\smartip_language_detection;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\smartip_language_detection\Form\SmartIpLanguageDetectionForm;
/**
* Provides a listing of Smart IP language mapping entities.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment