From 78b9b42bc0bd437fd92d0a888dd644f4424aa490 Mon Sep 17 00:00:00 2001 From: Willow Gillingham Date: Wed, 27 Apr 2022 13:16:46 -0700 Subject: [PATCH 1/2] test --- .../src/Plugin/views/style/IIIFManifest.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 073ca04e8..fa57dd1fb 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -2,6 +2,7 @@ namespace Drupal\islandora_iiif\Plugin\views\style; +use Drupal\Core\Entity\EntityManager; use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; @@ -85,7 +86,7 @@ class IIIFManifest extends StylePluginBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger, \Drupal\islandora\IslandoraUtils $utils) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->serializer = $serializer; @@ -94,6 +95,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->fileSystem = $file_system; $this->httpClient = $http_client; $this->messenger = $messenger; + $this->utils = $utils; } /** @@ -109,7 +111,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('config.factory')->get('islandora_iiif.settings'), $container->get('file_system'), $container->get('http_client'), - $container->get('messenger') + $container->get('messenger'), + $container->get('islandora.utils') ); } @@ -151,6 +154,18 @@ public function render() { $json['sequences'][0]['canvases'][] = $tile_source; } } + if (count($this->view->result) < 1) { + $pathinfo = $this->request->getPathInfo(); + $node_id_str = str_replace(['/node/', '/manifest'], '', $pathinfo); + if ($node_id_str) { + $node = \Drupal::entityTypeManager()->getStorage('node')->load($node_id_str); + // Get the node's media that is a "Service File" since that is what + // the view is restricted to. + $service_file_term = array_pop(\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['field_external_uri' => 'http://pcdm.org/use#ServiceFile', 'vid' => 'islandora_media_use'])); + $node_media = $this->utils->getMediaWithTerm($node, $service_file_term); + $json['sequences'][0]['canvases'][] = $this->getTileSourceFromRow(NULL, $iiif_address, $iiif_base_id, $node_media); + } + } } unset($this->view->row_index); @@ -162,22 +177,24 @@ public function render() { /** * Render array from views result row. * - * @param \Drupal\views\ResultRow $row - * Result row. + * @param MIXED $row + * Result row \Drupal\views\ResultRow usually coming from the view - or can be NULL when overridden. * @param string $iiif_address * The URL to the IIIF server endpoint. * @param string $iiif_base_id * The URL for the request, minus the last part of the URL, * which is likely "manifest". + * @param object $override_media + * The "result's" media when not coming from the view results. * * @return array * List of IIIF URLs to display in the Openseadragon viewer. */ - protected function getTileSourceFromRow(ResultRow $row, $iiif_address, $iiif_base_id) { + protected function getTileSourceFromRow($row, $iiif_address, $iiif_base_id, $override_media = NULL) { $canvases = []; foreach ($this->options['iiif_tile_field'] as $iiif_tile_field) { $viewsField = $this->view->field[$iiif_tile_field]; - $entity = $viewsField->getEntity($row); + $entity = is_null($override_media) ? $viewsField->getEntity($row) : $override_media; if (isset($entity->{$viewsField->definition['field_name']})) { From f727895a46b6b39044bdd5364c82c5f572beb0ec Mon Sep 17 00:00:00 2001 From: Willow Gillingham Date: Thu, 12 May 2022 10:44:02 -0700 Subject: [PATCH 2/2] removed any facets javascript override --- .../islandora_advanced_search.module | 16 -- .../js/facets/facets-views-ajax.js | 147 ------------------ .../js/facets/soft-limit.js | 70 --------- 3 files changed, 233 deletions(-) delete mode 100644 modules/islandora_advanced_search/js/facets/facets-views-ajax.js delete mode 100644 modules/islandora_advanced_search/js/facets/soft-limit.js diff --git a/modules/islandora_advanced_search/islandora_advanced_search.module b/modules/islandora_advanced_search/islandora_advanced_search.module index cbf52667a..a389a29dc 100644 --- a/modules/islandora_advanced_search/islandora_advanced_search.module +++ b/modules/islandora_advanced_search/islandora_advanced_search.module @@ -42,22 +42,6 @@ function islandora_advanced_search_theme() { ]; } -/** - * Implements hook_library_info_alter(). - */ -function islandora_advanced_search_library_info_alter(&$libraries, $extension) { - if ($extension == 'facets') { - // Override facets module javascript with customizations. - $path = '/' . drupal_get_path('module', 'islandora_advanced_search') . '/js/facets'; - $libraries['soft-limit']['js'] = [ - "$path/soft-limit.js" => [], - ]; - $libraries['drupal.facets.views-ajax']['js'] = [ - "$path/facets-views-ajax.js" => [], - ]; - } -} - /** * Implements hook_search_api_solr_converted_query_alter(). */ diff --git a/modules/islandora_advanced_search/js/facets/facets-views-ajax.js b/modules/islandora_advanced_search/js/facets/facets-views-ajax.js deleted file mode 100644 index 0b04ea33d..000000000 --- a/modules/islandora_advanced_search/js/facets/facets-views-ajax.js +++ /dev/null @@ -1,147 +0,0 @@ -//# sourceURL=modules/contrib/islandora/modules/islandora_advanced_search/js/facets/facets-view.ajax.js -/** - * @file - * Overrides the facets-view-ajax.js behavior from the 'facets' module. - */ -(function ($, Drupal) { - "use strict"; - - // Generate events on push state. - (function (history) { - var pushState = history.pushState; - history.pushState = function (state, title, url) { - var ret = pushState.apply(this, arguments); - var event = new Event("pushstate"); - window.dispatchEvent(event); - return ret; - }; - })(window.history); - - function reload(url) { - // Update View. - if (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) { - var view_path = drupalSettings.views.ajax_path; - $.each(drupalSettings.views.ajaxViews, function (views_dom_id) { - var views_parameters = Drupal.Views.parseQueryString(url); - var views_arguments = Drupal.Views.parseViewArgs(url, "search"); - var views_settings = $.extend( - {}, - Drupal.views.instances[views_dom_id].settings, - views_arguments, - views_parameters - ); - var views_ajax_settings = - Drupal.views.instances[views_dom_id].element_settings; - views_ajax_settings.submit = views_settings; - views_ajax_settings.url = - view_path + "?" + $.param(Drupal.Views.parseQueryString(url)); - Drupal.ajax(views_ajax_settings).execute(); - }); - } - - // Replace filter, pager, summary, and facet blocks. - var blocks = {}; - $( - ".block[class*='block-plugin-id--islandora-advanced-search-result-pager'], .block[class*='block-plugin-id--views-exposed-filter-block'], .block[class*='block-plugin-id--facet']" - ).each(function () { - var id = $(this).attr("id"); - var block_id = id - .slice("block-".length, id.length) - .replace(/--.*$/g, "") - .replace(/-/g, "_"); - blocks[block_id] = "#" + id; - }); - Drupal.ajax({ - url: Drupal.url("islandora-advanced-search-ajax-blocks"), - submit: { - link: url, - blocks: blocks, - }, - }).execute(); - } - - // On location change reload all the blocks / ajax view. - window.addEventListener("pushstate", function (e) { - reload(window.location.href); - }); - - window.addEventListener("popstate", function (e) { - if (e.state != null) { - reload(window.location.href); - } - }); - - /** - * Push state on form/pager/facet change. - */ - Drupal.behaviors.islandoraAdvancedSearchViewsAjax = { - attach: function (context, settings) { - window.historyInitiated = true; - - // Remove existing behavior from form. - if (settings && settings.views && settings.views.ajaxViews) { - $.each(settings.views.ajaxViews, function (index, settings) { - var exposed_form = $( - "form#views-exposed-form-" + - settings.view_name.replace(/_/g, "-") + - "-" + - settings.view_display_id.replace(/_/g, "-") - ); - exposed_form - .once() - .find("input[type=submit], input[type=image]") - .not("[data-drupal-selector=edit-reset]") - .each(function (index) { - $(this).unbind("click"); - $(this).click(function (e) { - // Let ctrl/cmd click open in a new window. - if (e.shiftKey || e.ctrlKey || e.metaKey) { - return; - } - e.preventDefault(); - e.stopPropagation(); - var href = window.location.href; - var params = Drupal.Views.parseQueryString(href); - // Remove the page if set as submitting the form should always take - // the user to the first page (facets do the same). - delete params.page; - // Include values from the form in the URL. - $.each(exposed_form.serializeArray(), function () { - params[this.name] = this.value; - }); - href = href.split("?")[0] + "?" + $.param(params); - window.history.pushState(null, document.title, href); - }); - }); - }); - } - - // Attach behavior to pager, summary, facet links. - $("[data-drupal-pager-id], [data-drupal-facets-summary-id], [data-drupal-facet-id]") - .once() - .find("a:not(.facets-soft-limit-link)") - .click(function (e) { - // Let ctrl/cmd click open in a new window. - if (e.shiftKey || e.ctrlKey || e.metaKey) { - return; - } - e.preventDefault(); - window.history.pushState(null, document.title, $(this).attr("href")); - }); - - // Trigger on sort change. - $('[data-drupal-pager-id] select[name="order"]') - .once() - .change(function () { - var href = window.location.href; - var params = Drupal.Views.parseQueryString(href); - var selection = $(this).val(); - var option = $('option[value="' + selection + '"]'); - params.sort_order = option.data("sort_order"); - params.sort_by = option.data("sort_by"); - href = href.split("?")[0] + "?" + $.param(params); - window.history.pushState(null, document.title, href); - }); - }, - }; -})(jQuery, Drupal); diff --git a/modules/islandora_advanced_search/js/facets/soft-limit.js b/modules/islandora_advanced_search/js/facets/soft-limit.js deleted file mode 100644 index a81a267ce..000000000 --- a/modules/islandora_advanced_search/js/facets/soft-limit.js +++ /dev/null @@ -1,70 +0,0 @@ -//# sourceURL=modules/contrib/islandora/modules/islandora_advanced_search/js/facets/soft-limit.js -/** - * @file - * Overrides the soft-limit.js behavior from the 'facets' module. - * As when having many facets the original version causes the page to slow down and snap to hidden when rendering. - */ -(function ($) { - - 'use strict'; - - Drupal.behaviors.facetSoftLimit = { - attach: function (context, settings) { - if (settings.facets.softLimit !== 'undefined') { - $.each(settings.facets.softLimit, function (facet, limit) { - Drupal.facets.applySoftLimit(facet, limit, settings); - }); - } - } - }; - - Drupal.facets = Drupal.facets || {}; - - /** - * Applies the soft limit UI feature to a specific facets list. - * - * @param {string} facet - * The facet id. - * @param {string} limit - * The maximum amount of items to show. - * @param {object} settings - * Settings. - */ - Drupal.facets.applySoftLimit = function (facet, limit, settings) { - var zero_based_limit = (limit - 1); - var facet_id = facet; - var facetsList = $('ul[data-drupal-facet-id="' + facet_id + '"]'); - - // In case of multiple instances of a facet, we need to key them. - if (facetsList.length > 1) { - facetsList.each(function (key, $value) { - $(this).attr('data-drupal-facet-id', facet_id + '-' + key); - }); - } - - // Add "Show more" / "Show less" links. - facetsList.filter(function () { - return $(this).next('ul').length == 1; // Has expanding list. - }).each(function () { - var facet = $(this); - var expand = facet.next('ul'); - var link = expand.next('a'); - var showLessLabel = settings.facets.softLimitSettings[facet_id].showLessLabel; - var showMoreLabel = settings.facets.softLimitSettings[facet_id].showMoreLabel; - link.text(showMoreLabel) - .once() - .on('click', function () { - if (!expand.is(":visible")) { - expand.slideDown(); - $(this).addClass('open').text(showLessLabel); - } - else { - expand.slideUp(); - $(this).removeClass('open').text(showMoreLabel); - } - return false; - }) - }); - }; - -})(jQuery);