Skip to content

Commit

Permalink
Issue #964: Allow relative paths in IIIF manifests. (#965)
Browse files Browse the repository at this point in the history
* Issue #964: Allow relative paths in IIIF manifests.

* Address PHPCS error.

* Fix missing use statement.
  • Loading branch information
alxp authored Aug 7, 2023
1 parent 4eef5f5 commit 11afd42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ islandora_iiif.settings:
iiif_server:
type: string
label: 'IIIF Server Url'
use_relative_paths:
type: boolean
label: 'Use relative paths in manifest.'

views.style.iiif_manifest:
type: views_style
Expand Down
9 changes: 9 additions & 0 deletions modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('Please enter the image server location without trailing slash. e.g. http://www.example.org/iiif/2.'),
'#default_value' => $config->get('iiif_server'),
];

$form['use_relative_paths'] = [
'#type' => 'checkbox',
'#title' => $this->t("Use relative file paths in manifest."),
'#description' => $this->t("Check this if your IIIF Server is configured to access files locally. If unchecked, the absolute URL will be given and the IIIF server will make requests to this site to retrieve images."),
'#default_value' => $config->get('use_relative_paths'),
];

return parent::buildForm($form, $form_state);
}

Expand All @@ -99,6 +107,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

$this->config('islandora_iiif.settings')
->set('iiif_server', $form_state->getValue('iiif_server'))
->set('use_relative_paths', $form_state->getValue('use_relative_paths'))
->save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ protected function getTileSourceFromRow(ResultRow $row, $iiif_address, $iiif_bas

// Create the IIIF URL for this file
// Visiting $iiif_url will resolve to the info.json for the image.
$file_url = $image->entity->createFileUrl(FALSE);
if ($this->iiifConfig->get('use_relative_paths')) {
$file_url = ltrim($image->entity->createFileUrl(TRUE), '/');
}
else {
$file_url = $image->entity->createFileUrl(FALSE);
}

$mime_type = $image->entity->getMimeType();
$iiif_url = rtrim($iiif_address, '/') . '/' . urlencode($file_url);

Expand Down

0 comments on commit 11afd42

Please sign in to comment.