Merge pull request #21 from digitalutsc/remove-include-exclude-facets

Removed Include/Exclude facets option
This commit is contained in:
Kyle Huynh 2023-02-02 01:05:47 -05:00 committed by GitHub
commit 64fe710adc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1 additions and 256 deletions

View file

@ -4,7 +4,7 @@ name: 'Advanced Search'
description: "Creates an Advanced Search block and other enhancements to search."
type: module
package: Islandora
core_version_requirement: ^9.3
core_version_requirement: ^8.8 || ^9 || ^10
dependencies:
- drupal:facets
- drupal:facets_summary

View file

@ -27,14 +27,6 @@ use Solarium\Core\Query\QueryInterface as SolariumQueryInterface;
*/
function advanced_search_theme() {
return [
'facets_item_list__include_exclude_links' => [
'template' => 'facets/facets-item-list--include-exclude-links',
'base hook' => 'facets_item_list',
],
'facets_result_item__include_exclude_links' => [
'template' => 'facets/facets-result-item--include-exclude-links',
'base hook' => 'facets_result_item',
],
'facets_result_item__summary' => [
'template' => 'facets/facets-result-item--summary',
'base hook' => 'facets_result_item',
@ -142,29 +134,6 @@ function advanced_search_views_pre_view(ViewExecutable $view, $display_id, array
$advanced_search_query->alterView(\Drupal::request(), $view, $display_id);
}
/**
* Implements hook_preprocess_facets_summary_item_list().
*/
function advanced_search_preprocess_facets_summary_item_list(&$variables) {
/*foreach ($variables['items'] as &$item) {
$item['attributes']['class'][] = 'facet-summary-item';
}*/
}
/**
* Implements hook_preprocess_facets_item_list().
*/
function advanced_search_preprocess_facets_item_list(&$variables) {
$widget = $variables['facet']->getWidget();
$soft_limit = $widget['config']['soft_limit'];
// Break into two groups less / more which can display be toggled as a single
// element change rather than showing / hiding all <li> elements individually.
// As its slow and causes the page to snap when loading.
$variables['less'] = array_slice($variables['items'], 0, $soft_limit);
$variables['more'] = array_slice($variables['items'], $soft_limit);
$variables['show_more_label'] = $widget['config']['soft_limit_settings']['show_more_label'];
}
/**
* Implements hook_preprocess_facets_result_item().
*/

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -1,58 +0,0 @@
{#
/**
* @file
* Default theme implementation for a facets item list.
*
* Available variables:
* - items: A list of items. Each item contains:
* - attributes: HTML attributes to be applied to each list item.
* - value: The content of the list element.
* - title: The title of the list.
* - list_type: The tag for list element ("ul" or "ol").
* - wrapper_attributes: HTML attributes to be applied to the list wrapper.
* - attributes: HTML attributes to be applied to the list.
* - empty: A message to display when there are no items. Allowed value is a
* string or render array.
* - context: A list of contextual data associated with the list. May contain:
* - list_style: The ID of the widget plugin this facet uses.
* - facet: The facet for this result item.
* - id: the machine name for the facet.
* - label: The facet label.
*
* @see facets_preprocess_facets_item_list()
*
* @ingroup themeable
*/
#}
<div class="facets-widget- {{- facet.widget.type -}} ">
{% if facet.widget.type %}
{%- set attributes = attributes.addClass('item-list__' ~ facet.widget.type) %}
{% endif %}
{% if items or empty %}
{%- if title is not empty -%}
<h3>{{ title }}</h3>
{%- endif -%}
{%- if items -%}
<{{ list_type }}{{ attributes }}>
{%- for item in less -%}
<li{{ item.attributes }}>{{ item.value }}</li>
{%- endfor -%}
</{{ list_type }}>
{%- if more -%}
<{{ list_type }}{{ attributes }} style="display:none;margin-top:-1em">
{%- for item in more -%}
<li{{ item.attributes }}>{{ item.value }}</li>
{%- endfor -%}
</{{ list_type }}>
<a href="#" class="facets-soft-limit-link">{{ show_more_label }}</a>
{%- endif -%}
{%- else -%}
{{- empty -}}
{%- endif -%}
{%- endif %}
{% if facet.widget.type == "dropdown" %}
<label id="facet_{{ facet.id }}_label">{{ 'Facet'|t }} {{ facet.label }}</label>
{%- endif %}
</div>

View file

@ -1,33 +0,0 @@
{#
/**
* @file
* Default theme implementation of a facet result item.
*
* Available variables:
* - value: The item value.
* - raw_value: The raw item value.
* - show_count: If this facet provides count.
* - count: The amount of results.
* - is_active: The item is active.
* - facet: The facet for this result item.
* - id: the machine name for the facet.
* - label: The facet label.
*
* @ingroup themeable
*/
#}
{% if value['text'] is defined %}
<span class="facet-item__value">{{ value['text'] }}
{% if show_count %}
<span class="facet-item__count">({{ count }})</span>
{% endif %}
{% if value['exclude'] is defined %}
<span class="facet-item__operators">{{ value['include'] }} {{ value['exclude'] }}</span>
{% endif %}
</span>
{% else %}
<span class="facet-item__value">{{ value }}</span>
{% if show_count %}
<span class="facet-item__count">({{ count }})</span>
{% endif %}
{% endif %}