Skip to content

Commit

Permalink
959-iiif-width-height-caching Islandora IIIF: Add search endpoint con…
Browse files Browse the repository at this point in the history
…fig to manifest.
  • Loading branch information
alxp committed Nov 20, 2023
1 parent 847fb4f commit ec29a45
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/islandora_iiif/config/schema/islandora_iiif.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ views.style.iiif_manifest:
type: sequence
sequence:
type: string
label: "Tile source field(s)"
iiif_ocr_file_field:
type: sequence
sequence:
type: string:
label: "IIIF hOCR file field"
structured_text_term:
type: string
label: "Structured text term"
search_endpoint:
type: string
label: "Search endpoint path"
28 changes: 28 additions & 0 deletions modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ public function render() {

$content_type = 'json';

// Add a search endpoint if one is defined
$this->addSearchEndpoint($json, $url_components);

// Give other modules a chance to alter the manifest.
$this->moduleHandler->alter('islandora_iiif_manifest', $json, $this);

Expand Down Expand Up @@ -459,6 +462,23 @@ public function getEntityTitle(string $content_path): string {
return $entity_title;
}

protected function addSearchEndpoint(array &$json, array $url_components) {
$url_base = $this->getRequest()->getSchemeAndHttpHost();
$hocr_search_path = $this->options['search_endpoint'];
$hocr_search_url = $url_base . '/' . ltrim($hocr_search_path, '/');

$hocr_search_url = str_replace('%node', $url_components[1], $hocr_search_url);

$json['service'][] = [
"@context" => "http://iiif.io/api/search/0/context.json",
"@id" => $hocr_search_url,
"profile" => "http://iiif.io/api/search/0/search",
"label" => t("Search inside this work"),
];


}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -539,6 +559,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
'#required' => FALSE,
'#description' => $this->t('Term indicating the media that holds structured text, such as hOCR, for the given object. Use this if the text is on a separate media from the tile source.'),
];

$form['search_endpoint'] = [
'#type' => 'textfield',
'#title' => $this->t("Search endpoint path."),
'#description' => $this->t("If there is a search endpoint to search within the book that returns IIIF annotations, put it here. Use substitutions %node and %keywords.<br>E.g., paged-content-search/%node?search-in-pages=%keywords"),
'#default_value' => $this->options['search_endpoint'],
'#required' => FALSE,
];
}

/**
Expand Down

0 comments on commit ec29a45

Please sign in to comment.