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

Allow OSD to show on restricted paged objects. #55

Draft
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
Draft
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 .github/workflows/build-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ["8.1"]
drupal-version: ["9.5.x", "10.0.x", "10.1.x"]
php-versions: ["8.1", "8.2"]
drupal-version: ["10.0.x", "10.1.x", "10.2.x-dev"]
allowed_failure: [false]
mysql: ["8.0"]

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gitlab-mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Mirror to Drupal.org GitLab

on:
push:
branches:
- 2.x
branches: [2.x]
tags: '*'

jobs:
build:
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"conflict": {
"drupal/core": "<9.1"
},
"suggest": {
"drupal/coi": "Some configuration fields work with Config Override Inspector."
},
"authors": [
{
"name": "Islandora Foundation",
Expand Down
4 changes: 3 additions & 1 deletion openseadragon.module
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function template_preprocess_openseadragon_formatter(&$variables) {
$variables['#attached']['library'] = [
'openseadragon/init',
];
$access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
$variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [
'basePath' => Url::fromUri($iiif_address),
'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'],
Expand All @@ -110,11 +111,12 @@ function template_preprocess_openseadragon_formatter(&$variables) {
* Implements template_preprocess_HOOK().
*/
function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {
$access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
$cache_meta = CacheableMetadata::createFromRenderArray($variables);

// Get the tile sources from the manifest.
$parser = \Drupal::service('openseadragon.manifest_parser');
$tile_sources = $parser->getTileSources($variables['iiif_manifest_url']);
$tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], $access_token);

if (empty($tile_sources)) {
$cache_meta->applyTo($variables);
Expand Down
7 changes: 7 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class Config implements ConfigInterface {

use RefinableCacheableDependencyTrait;

/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* The openseadragon config.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Form/OpenSeadragonSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $this->seadragonConfig->getIiifAddress(),
'#required' => TRUE,
'#description' => t('Please enter the image server location without trailing slash. eg: http://www.example.org/iiif/2.'),
'#config' => [
'key' => 'openseadragon.settings:iiif_server',
],
],
'manifest_view' => [
'#type' => 'select',
Expand Down
30 changes: 27 additions & 3 deletions src/IIIFManifestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ public function __construct(
*
* @param string $manifest_url
* The location of the IIIF manifest, which can include tokens.
* @param string $access_token
* The JWT Access token.
*
* @return array
* The URLs of all the tile sources in a manifest.
*/
public function getTileSources($manifest_url) {
public function getTileSources($manifest_url, $access_token = NULL) {

// Try to construct the URL out of a tokenized string
// if the node is available.
Expand All @@ -80,12 +82,34 @@ public function getTileSources($manifest_url) {
// If the URL is relative, make it absolute.
if (substr($manifest_url, 0, 4) !== "http") {
$manifest_url = ltrim($manifest_url, '/');
$manifest_url = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString() . $manifest_url;

// Check if the URL starts with "/fr/" and adjust accordingly.
// https://redmine.library.yorku.ca/issues/3957
if (strpos($manifest_url, '/fr/') === 0) {
// If the URL starts with "/fr/", don't trim the first slash.
$append_slash = '';
}
else {
// If the URL doesn't start with "/fr/", trim the first slash.
$append_slash = '/';
}

// Construct the absolute URL.
$manifest_url = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString() . $append_slash . $manifest_url;
}

try {
// Request the manifest.
$manifest_response = $this->httpClient->get($manifest_url);
if (empty($access_token)) {
$manifest_response = $this->httpClient->get($manifest_url);
}
else {
$manifest_response = $this->httpClient->request('GET', $manifest_url, [
'headers' => [
'Authorization' => 'Bearer ' . $access_token,
],
]);
}

// Decode the manifest json.
$manifest_string = (string) $manifest_response->getBody();
Expand Down
Loading