diff --git a/.github/workflows/build-2.x.yml b/.github/workflows/build-2.x.yml index 23abfd8..7c34aa6 100644 --- a/.github/workflows/build-2.x.yml +++ b/.github/workflows/build-2.x.yml @@ -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"] diff --git a/.github/workflows/gitlab-mirror.yml b/.github/workflows/gitlab-mirror.yml index 1693362..38a5306 100644 --- a/.github/workflows/gitlab-mirror.yml +++ b/.github/workflows/gitlab-mirror.yml @@ -2,8 +2,8 @@ name: Mirror to Drupal.org GitLab on: push: - branches: - - 2.x + branches: [2.x] + tags: '*' jobs: build: diff --git a/composer.json b/composer.json index 8d02970..66819d1 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,9 @@ "conflict": { "drupal/core": "<9.1" }, + "suggest": { + "drupal/coi": "Some configuration fields work with Config Override Inspector." + }, "authors": [ { "name": "Islandora Foundation", diff --git a/openseadragon.module b/openseadragon.module index 161e42d..caff59b 100644 --- a/openseadragon.module +++ b/openseadragon.module @@ -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'], @@ -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); diff --git a/src/Config.php b/src/Config.php index 572910e..279c1cc 100644 --- a/src/Config.php +++ b/src/Config.php @@ -15,6 +15,13 @@ class Config implements ConfigInterface { use RefinableCacheableDependencyTrait; + /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + /** * The openseadragon config. * diff --git a/src/Form/OpenSeadragonSettingsForm.php b/src/Form/OpenSeadragonSettingsForm.php index 0641d5a..88bb4b0 100644 --- a/src/Form/OpenSeadragonSettingsForm.php +++ b/src/Form/OpenSeadragonSettingsForm.php @@ -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', diff --git a/src/IIIFManifestParser.php b/src/IIIFManifestParser.php index fc98f6a..56820ae 100644 --- a/src/IIIFManifestParser.php +++ b/src/IIIFManifestParser.php @@ -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. @@ -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('', [], ['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('', [], ['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();