summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaurav Manerkar2018-02-25 14:38:33 (GMT)
committerGaurav Manerkar2018-02-25 14:38:33 (GMT)
commit7bed911ff1c8a46f3e86e1ce68730bf3c66cd925 (patch)
tree132477e79ce0b6f1b31cba1db17c236946fd6552
parentc14b308e06b26e868b3c6bfab244b95285c52587 (diff)
code review
-rw-r--r--src/Plugin/Block/PageHitsBlock.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Plugin/Block/PageHitsBlock.php b/src/Plugin/Block/PageHitsBlock.php
index b4f389f..587ac42 100644
--- a/src/Plugin/Block/PageHitsBlock.php
+++ b/src/Plugin/Block/PageHitsBlock.php
@@ -7,6 +7,9 @@ use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Session\AccountProxy;
+use Drupal\Core\Session\AccountProxyInterface;
+use Symfony\Component\HttpFoundation\RequestStack;
/**
* Provides a 'page_hits' block.
@@ -21,12 +24,16 @@ class PageHitsBlock extends BlockBase implements BlockPluginInterface, Container
protected $configfactory;
+ protected $account;
+
/**
* {@inheritdoc}
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, AccountProxyInterface $account,RequestStack $requestStack) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
- $this->configfactory = $config_factory;
+ $this->configfactory = $config_factory;
+ $this->account = $account;
+ $this->requestStack = $requestStack;
}
/**
@@ -37,7 +44,9 @@ class PageHitsBlock extends BlockBase implements BlockPluginInterface, Container
$configuration,
$plugin_id,
$plugin_definition,
- $container->get('config.factory')
+ $container->get('config.factory'),
+ $container->get('current_user'),
+ $container->get('request_stack')
);
}
@@ -46,15 +55,15 @@ class PageHitsBlock extends BlockBase implements BlockPluginInterface, Container
*/
public function build() {
$config = $this->configfactory->get('page_hits.settings');
- $ip = \Drupal::request()->getClientIp();
+ $ip = $this->requestStack->getCurrentRequest()->getClientIp();
$unique_visitor = 0;
$total_visitor = 0;
$total_visitor_by_user = 0;
$total_visitor_in_week = 0;
- $current_user = \Drupal::currentUser();
+ $current_user = $this->account;
global $base_url;
- $page_url = $base_url . \Drupal::request()->getRequestUri();
+ $page_url = $base_url . $this->requestStack->getCurrentRequest()->getRequestUri();
$result = [];
$node = \Drupal::request()->attributes->get('node');