UrlProcessorPluginBase.php in Facets 8
File
src/UrlProcessor/UrlProcessorPluginBase.php
View source
<?php
namespace Drupal\facets\UrlProcessor;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\facets\Exception\InvalidProcessorException;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\ProcessorPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
abstract class UrlProcessorPluginBase extends ProcessorPluginBase implements UrlProcessorInterface, ContainerFactoryPluginInterface {
protected $filterKey = 'f';
protected $separator;
protected $request;
protected $entityTypeManager;
protected $activeFilters = [];
public function getFilterKey() {
return $this->filterKey;
}
public function getSeparator() {
return $this->separator;
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->request = clone $request;
$this->entityTypeManager = $entity_type_manager;
if (!isset($configuration['facet'])) {
throw new InvalidProcessorException("The url processor doesn't have the required 'facet' in the configuration array.");
}
$facet = $configuration['facet'];
$facet_source_config = $facet
->getFacetSourceConfig();
$this->filterKey = $facet_source_config
->getFilterKey() ?: 'f';
$this->separator = ':';
if (isset($configuration['separator'])) {
$this->separator = $configuration['separator'];
}
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('request_stack')
->getMasterRequest(), $container
->get('entity_type.manager'));
}
public function getActiveFilters() {
return $this->activeFilters;
}
public function setActiveFilters(array $active_filters) {
$this->activeFilters = $active_filters;
}
public function setActiveItems(FacetInterface $facet) {
if (isset($this->activeFilters[$facet
->id()])) {
foreach ($this->activeFilters[$facet
->id()] as $value) {
$facet
->setActiveItem(trim($value, '"'));
}
}
}
}