ExposedFilterDataBlock.php in Exposed Filter Data 8
File
src/Plugin/Block/ExposedFilterDataBlock.php
View source
<?php
namespace Drupal\exposed_filter_data\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\views\Entity\View;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ExposedFilterDataBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $request;
protected $moduleHandler;
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->request = $request;
$this->moduleHandler = $module_handler;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('request_stack')
->getCurrentRequest(), $container
->get('module_handler'));
}
public function build() {
$build = [];
if ($params = $this->request->query
->all()) {
$this->moduleHandler
->alter('exposed_filter_data_params', $params);
$build = [
'#theme' => 'exposed_filter_data_block',
'#filters' => $params,
'#attached' => [
'library' => [
'exposed_filter_data/exposed_filter_data.block',
],
],
];
}
return $build;
}
public function getCacheMaxAge() {
return 0;
}
}