Removed Include/Exclude facets option
This commit is contained in:
parent
df34155e27
commit
f747931c28
6 changed files with 1 additions and 256 deletions
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\advanced_search\Plugin\facets\widget;
|
||||
|
||||
use Drupal\facets\Plugin\facets\widget\LinksWidget;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\facets\Result\ResultInterface;
|
||||
|
||||
// This widget doesn't currently work, need more reviews.
|
||||
// Remove "*" to hide the registry of this widget to prevent it show up in Facets configuration
|
||||
/*
|
||||
* The links widget.
|
||||
*
|
||||
* @FacetsWidget(
|
||||
* id = "include_exclude_links",
|
||||
* label = @Translation("List of links that allow the user to include / exclude facets."),
|
||||
* description = @Translation("A simple widget that shows a list of +/- links."),
|
||||
* )
|
||||
*/
|
||||
class IncludeExcludeLinksWidget extends LinksWidget {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareLink(ResultInterface $result) {
|
||||
$facet = $result->getFacet();
|
||||
$facet_source_id = $facet->getFacetSourceId();
|
||||
$facet_manager = \Drupal::service('facets.manager');
|
||||
$facets = $facet_manager->getFacetsByFacetSourceId($facet_source_id);
|
||||
$raw_value = $result->getRawValue();
|
||||
$count = $result->getCount();
|
||||
$url = $result->getUrl();
|
||||
$exclude_facet = $this->getExcludeFacet($facet, $facets);
|
||||
$exclude_result = $this->getExcludeResult($exclude_facet, $raw_value);
|
||||
$exclude_url = $exclude_result ? $exclude_result->getUrl() : NULL;
|
||||
return [
|
||||
'#theme' => 'facets_result_item',
|
||||
'#is_active' => $result->isActive(),
|
||||
'#value' => [
|
||||
'text' => (new Link($result->getDisplayValue(), $url))->toRenderable(),
|
||||
'include' => (new Link(' ', $url))->toRenderable() + [
|
||||
'#attributes' => [
|
||||
'class' => ['facet-item__include', 'fa', 'fa-plus'],
|
||||
],
|
||||
],
|
||||
'exclude' => $exclude_url ? (new Link(' ', $exclude_url))->toRenderable() + [
|
||||
'#attributes' => [
|
||||
'class' => ['facet-item__exclude', 'fa', 'fa-minus'],
|
||||
],
|
||||
] : NULL,
|
||||
],
|
||||
'#show_count' => $this->getConfiguration()['show_numbers'] && ($count !== NULL),
|
||||
'#count' => $count,
|
||||
'#facet' => $facet,
|
||||
'#raw_value' => $raw_value,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for the excluded facet version of the included facet.
|
||||
*/
|
||||
protected function getExcludeResult($facet, $raw_value) {
|
||||
if ($facet) {
|
||||
foreach ($facet->getResults() as $result) {
|
||||
if ($result->getRawValue() === $raw_value) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for the excluded facet version of the included facet.
|
||||
*/
|
||||
protected function getExcludeFacet($include, $facets) {
|
||||
$field_identifier = $include->getFieldIdentifier();
|
||||
foreach ($facets as $facet) {
|
||||
if ($field_identifier === $facet->getFieldIdentifier() && $facet->getExclude()) {
|
||||
return $facet;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\advanced_search\Plugin\facets_summary\processor;
|
||||
|
||||
use Drupal\facets_summary\FacetsSummaryInterface;
|
||||
use Drupal\facets_summary\Processor\BuildProcessorInterface;
|
||||
use Drupal\facets_summary\Processor\ProcessorPluginBase;
|
||||
use Drupal\facets\FacetInterface;
|
||||
|
||||
/**
|
||||
* Provides a processor that shows the search query.
|
||||
*
|
||||
* @SummaryProcessor(
|
||||
* id = "show_active_excluded_facets",
|
||||
* label = @Translation("Show active excluded facets."),
|
||||
* description = @Translation("When checked, negated facets will appear in the summary."),
|
||||
* stages = {
|
||||
* "build" = 20
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ShowActiveExcludedFacets extends ProcessorPluginBase implements BuildProcessorInterface {
|
||||
|
||||
use ShowFacetsTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function condition(FacetInterface $facet) {
|
||||
return $facet->getExclude();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function classes() {
|
||||
return ['facet-summary-item--facet', 'facet-summary-item--exclude'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(FacetsSummaryInterface $facets_summary, array $build, array $facets) {
|
||||
return $this->buildHelper($build, $facets);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue