From f747931c28526565dc2d83b90ae251476e9c10df Mon Sep 17 00:00:00 2001 From: Kyle Huynh Date: Wed, 1 Feb 2023 23:12:29 -0500 Subject: [PATCH] Removed Include/Exclude facets option --- advanced_search.info.yml | 2 +- advanced_search.module | 31 ------- .../widget/IncludeExcludeLinksWidget.php | 86 ------------------- .../processor/ShowActiveExcludedFacets.php | 47 ---------- ...item-list--include-exclude-links.html.twig | 58 ------------- ...sult-item--include-exclude-links.html.twig | 33 ------- 6 files changed, 1 insertion(+), 256 deletions(-) delete mode 100644 src/Plugin/facets/widget/IncludeExcludeLinksWidget.php delete mode 100644 src/Plugin/facets_summary/processor/ShowActiveExcludedFacets.php delete mode 100644 templates/facets/facets-item-list--include-exclude-links.html.twig delete mode 100644 templates/facets/facets-result-item--include-exclude-links.html.twig diff --git a/advanced_search.info.yml b/advanced_search.info.yml index c6189d6..11e8f24 100644 --- a/advanced_search.info.yml +++ b/advanced_search.info.yml @@ -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 diff --git a/advanced_search.module b/advanced_search.module index 25faa20..437dfba 100644 --- a/advanced_search.module +++ b/advanced_search.module @@ -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
  • 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(). */ diff --git a/src/Plugin/facets/widget/IncludeExcludeLinksWidget.php b/src/Plugin/facets/widget/IncludeExcludeLinksWidget.php deleted file mode 100644 index 47baa5d..0000000 --- a/src/Plugin/facets/widget/IncludeExcludeLinksWidget.php +++ /dev/null @@ -1,86 +0,0 @@ -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; - } - -} diff --git a/src/Plugin/facets_summary/processor/ShowActiveExcludedFacets.php b/src/Plugin/facets_summary/processor/ShowActiveExcludedFacets.php deleted file mode 100644 index 7d49798..0000000 --- a/src/Plugin/facets_summary/processor/ShowActiveExcludedFacets.php +++ /dev/null @@ -1,47 +0,0 @@ -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); - } - -} diff --git a/templates/facets/facets-item-list--include-exclude-links.html.twig b/templates/facets/facets-item-list--include-exclude-links.html.twig deleted file mode 100644 index 1c80658..0000000 --- a/templates/facets/facets-item-list--include-exclude-links.html.twig +++ /dev/null @@ -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 - */ -#} -
    - {% if facet.widget.type %} - {%- set attributes = attributes.addClass('item-list__' ~ facet.widget.type) %} - {% endif %} - {% if items or empty %} - {%- if title is not empty -%} -

    {{ title }}

    - {%- endif -%} - - {%- if items -%} - <{{ list_type }}{{ attributes }}> - {%- for item in less -%} - {{ item.value }}
  • - {%- endfor -%} - - {%- if more -%} - <{{ list_type }}{{ attributes }} style="display:none;margin-top:-1em"> - {%- for item in more -%} - {{ item.value }} - {%- endfor -%} - - {{ show_more_label }} - {%- endif -%} - {%- else -%} - {{- empty -}} - {%- endif -%} - {%- endif %} - -{% if facet.widget.type == "dropdown" %} - -{%- endif %} - diff --git a/templates/facets/facets-result-item--include-exclude-links.html.twig b/templates/facets/facets-result-item--include-exclude-links.html.twig deleted file mode 100644 index aeec313..0000000 --- a/templates/facets/facets-result-item--include-exclude-links.html.twig +++ /dev/null @@ -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 %} -{{ value['text'] }} - {% if show_count %} - ({{ count }}) - {% endif %} - {% if value['exclude'] is defined %} - {{ value['include'] }} {{ value['exclude'] }} - {% endif %} - -{% else %} -{{ value }} - {% if show_count %} - ({{ count }}) - {% endif %} -{% endif %} \ No newline at end of file