Skip to content

Commit

Permalink
Allow OSD to show on restricted paged objects.
Browse files Browse the repository at this point in the history
- Alternate implementation of Islandora#51
- Resolves yorkulibraries/yudl_drupal_theme#78
  • Loading branch information
ruebot committed Aug 25, 2023
1 parent 8cd4b26 commit be9936b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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
15 changes: 13 additions & 2 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 @@ -85,7 +87,16 @@ public function getTileSources($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

0 comments on commit be9936b

Please sign in to comment.