diff --git a/islandora_fits.module b/islandora_fits.module index 916096b7..87dd93d8 100644 --- a/islandora_fits.module +++ b/islandora_fits.module @@ -51,6 +51,7 @@ function islandora_fits_theme($existing, $type, $theme, $path) { 'fits' => [ 'variables' => [ 'title' => 'FITS data', + 'link' => NULL, 'data' => [], ], ], diff --git a/src/Plugin/Field/FieldFormatter/FitsFormatter.php b/src/Plugin/Field/FieldFormatter/FitsFormatter.php index 60909eb3..d4699d7a 100644 --- a/src/Plugin/Field/FieldFormatter/FitsFormatter.php +++ b/src/Plugin/Field/FieldFormatter/FitsFormatter.php @@ -79,7 +79,13 @@ class FitsFormatter extends FormatterBase { protected function viewValue(FieldItemInterface $item) { $fileItem = $item->getValue(); $file = File::load($fileItem['target_id']); - $contents = utf8_encode(file_get_contents($file->getFileUri())); + $url = Url::fromUri($file->url()); + $link = Link::fromTextAndUrl("Link to XML", $url); + $link = $link->toRenderable(); + $contents = file_get_contents($file->getFileUri()); + if (mb_detect_encoding($contents) != 'UTF-8') { + $contents = utf8_encode($contents); + } $xml = new \SimpleXMLElement($contents); $xml->registerXPathNamespace('fits', 'http://hul.harvard.edu/ois/xml/ns/fits/fits_output'); $fits_metadata = $this->islandora_fits_child_xpath($xml); @@ -133,8 +139,10 @@ class FitsFormatter extends FormatterBase { $renderable = [ '#theme' => 'fits', + '#title' => $this->t("FITS metadata"), + '#link' => $link, '#data' => $variables['islandora_fits_fieldsets'], - '#title' => $this->t("Fits Metadata"), + ]; return \Drupal::service('renderer')->render($renderable); } diff --git a/templates/fits.html.twig b/templates/fits.html.twig index 33bb8bda..d7ffc358 100644 --- a/templates/fits.html.twig +++ b/templates/fits.html.twig @@ -1,4 +1,5 @@

{{ title }}

+

{{ link }}

{{ data }}