Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D10-78 / D10-28: D10 support #17

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This module requires the following modules/libraries:
## Installation

Install as usual, see
[this](https://drupal.org/documentation/install/modules-themes/modules-8) for
[this](https://www.drupal.org/docs/extending-drupal/installing-modules) for
further information.

## Usage
Expand All @@ -39,7 +39,7 @@ view of 'Content: Collection(s)'.
* Change the 'Pager' settings to only show a specific number of items, 1.

This module will allow switching view modes for the current member of the compound object,
not just the compound object itself (provided by the menu router).
not just the compound object itself (provided by the menu router).

## Troubleshooting/Issues

Expand Down
2 changes: 1 addition & 1 deletion dgi_members.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'DGI Members'
type: module
description: 'Facilitates display of compounds objects'
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: 'DGI'
dependencies:
- islandora:islandora
2 changes: 1 addition & 1 deletion dgi_members.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ compound_parts:
js:
js/compound_parts.js: {}
dependencies:
- core/jquery.once
- core/once
116 changes: 61 additions & 55 deletions js/compound_parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,58 @@
* Contains client side logic for dgi_members.
*/

(function ($, Drupal, drupalSettings) {
(function ($, Drupal, drupalSettings, once) {
'use strict';

Drupal.behaviors.compound_members = {
attach: function (context, settings) {
$(document).once('compound_controller_ajax_begin').each(this.ajaxBegin);
$(document).once('compound_controller_add_labels').each(this.appendLabels);
$(".object-metadata").once('compound_controller_click_callback').each(this.metadataToggleClick);
$(document).once('compound_controller_update_active').each(this.updateActiveMetadataDisplay);
},
Drupal.behaviors.dgi_members_compound_parts = {
attach: function (context) {
once('dgi_members-compound_controller', 'body').forEach(() => {
Drupal.dgi_members.compound_members.ajaxBegin();
Drupal.dgi_members.compound_members.appendLabels();
Drupal.dgi_members.compound_members.updateActiveMetadataDisplay();
});

function _click(e, active_selector, hide_selector, show_selector) {
e.preventDefault();
$('.object-metadata').removeClass('element-active');

$(active_selector).addClass('element-active');
$(hide_selector).addClass('hidden')
$(show_selector).removeClass('hidden');
}

once('dgi_members-compound_controller_metadata-element', '.object-metadata.element-compound', context).forEach((element) => {
$(element).on('click', function (e) {
_click(
e,
'.object-metadata.element-compound',
".compound-member-metadata",
".compound-object-metadata",
);
});
});
once('dgi_members-compound_controller_metadata-part', '.object-metadata.part-metadata', context).forEach((element) => {
$(element).on('click', function (e) {
_click(
e,
'.object-metadata.part-metadata',
".compound-object-metadata",
".compound-member-metadata",
);
});
});
}
};

Drupal.dgi_members = Drupal.dgi_members || {};
Drupal.dgi_members.compound_members = {
/**
* Toggle on or off the ajax spinner.
*/
toggleSpinner: function () {
var toggle_element = ".multi-object-navigation header i";
$(toggle_element).toggleClass('visually-hidden');
$(".multi-object-navigation .view-content.solr-search-row-content").toggleClass('ajax-active');
let $nav = $('.multi-object-navigation');
$nav.find("header i").toggleClass('visually-hidden');
$nav.find(".view-content.solr-search-row-content").toggleClass('ajax-active');
},

/**
Expand All @@ -29,38 +63,7 @@
ajaxBegin: function () {
$(document).ajaxSend(function (event, xhr, settings) {
if (settings.url.startsWith("/views/ajax?")) {
Drupal.behaviors.compound_members.toggleSpinner();
}
});
},

/**
* Construct the metadata toggle elements.
*
* @returns {string}
* HTML Markup representing the toggle elements.
*/
toggleSwitch: function () {
return "<span class='metadata-toggle'><a href='#' class='object-metadata part-metadata'>" + Drupal.t("Part") + "</a><a href='#' class='object-metadata element-compound'>" + Drupal.t("Compound") + "</a></span>"
},

/**
* Attach click handlers to the different metadata displays.
*/
metadataToggleClick: function () {
$(this).on('click', function (e) {
e.preventDefault();
$('.object-metadata').removeClass('element-active');

if ($(e.currentTarget).hasClass('element-compound')) {
$('.element-compound').addClass('element-active');
$(".compound-member-metadata").addClass('hidden');
$(".compound-object-metadata").removeClass('hidden');
}
if ($(e.currentTarget).hasClass('part-metadata')) {
$('.part-metadata').addClass('element-active');
$(".compound-member-metadata").removeClass('hidden');
$(".compound-object-metadata").addClass('hidden');
Drupal.dgi_members.compound_members.toggleSpinner();
}
});
},
Expand All @@ -69,12 +72,11 @@
* Append the metadata labels to each panel.
*/
appendLabels: function () {
$(".compound-object-metadata").find('.panel-heading').append(
Drupal.behaviors.compound_members.toggleSwitch()
);

$(".compound-member-metadata").find('.panel-heading').append(
Drupal.behaviors.compound_members.toggleSwitch()
$(".compound-object-metadata, .compound-member-metadata").find('.panel-heading').append(
`<span class='metadata-toggle'>
<a href='#' class='object-metadata part-metadata'>${Drupal.t("Part")}</a>
<a href='#' class='object-metadata element-compound'>${Drupal.t("Compound")}</a>
</span>`
);
},

Expand All @@ -85,17 +87,21 @@
* including in the compound navigator block and the 'Parts' sidebar block.
*/
updateActiveMetadataDisplay: function () {
const $ec = $('.object-metadata.element-compound');
const $pm = $('.object-metadata.part-metadata');
const ac = 'element-active';

if (drupalSettings.dgi_members.has_members) {
$(".compound-object-metadata").addClass('hidden');
$('.object-metadata.element-compound').removeClass('element-active');
$('.object-metadata.part-metadata').addClass('element-active');
$ec.removeClass(ac);
$pm.addClass(ac);
}
else {
$('.object-metadata.element-compound').addClass('element-active');
$('.object-metadata.part-metadata').removeClass('element-active');
$ec.addClass(ac);
$pm.removeClass(ac);
}

$(".active-node-" + drupalSettings.dgi_members.active_nid).closest('div.views-row').addClass('active-member');
$(`.active-node-${drupalSettings.dgi_members.active_nid}`).closest('div.views-row').addClass('active-member');
}
};
})(jQuery, Drupal, drupalSettings);
})(jQuery, Drupal, drupalSettings, once);
3 changes: 1 addition & 2 deletions src/DgiMembersEntityOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Drupal\taxonomy\TermInterface;

/**
* Class DgiMembersEntityOperations.
*
* Utility service to perform compound object related operations.
*/
class DgiMembersEntityOperations {
Expand Down Expand Up @@ -169,6 +167,7 @@ public function membersQueryExecute() {
$to_return = $this->entityTypeManager
->getStorage('node')
->getQuery()
->accessCheck()
->condition('field_member_of', $entity->id())
->sort('field_weight')
->execute();
Expand Down