DisplayGeneratedLinkBlock.php in Facets 8
File
tests/facets_query_processor/src/Plugin/Block/DisplayGeneratedLinkBlock.php
View source
<?php
namespace Drupal\facets_query_processor\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\State\StateInterface;
use Drupal\facets\Utility\FacetsUrlGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DisplayGeneratedLinkBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $urlGeneratorService;
protected $state;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FacetsUrlGenerator $facets_url_generator, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->urlGeneratorService = $facets_url_generator;
$this->state = $state;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('facets.utility.url_generator'), $container
->get('state'));
}
public function build() {
$url = $this->urlGeneratorService
->getUrl([
'owl' => [
'item',
],
], $this->state
->get('facets_url_generator_keep_active', FALSE));
$link = new Link('Link to owl item', $url);
return $link
->toRenderable() + [
'#cache' => [
'max-age' => 0,
],
];
}
}