From d8390851a68429af9ac107ec9e9b7678934523ee Mon Sep 17 00:00:00 2001
From: Dorian Merz <merz@ub.uni-leipzig.de>
Date: Mon, 7 Sep 2020 15:11:15 +0200
Subject: [PATCH] refs #18292 [finc] refactor data-templates and
 RecordDataFormatterFactory in finc

* removes templates for simple escaped and translated data, this can be achieved via options in simple SpecLine
* add alterable separator to authors template
* replace data-dateSpan with RecordHelper SpecLine
---
 .../Root/RecordDataFormatterFactory.php       | 265 +++++++-----------
 .../DefaultRecord/data-authors.phtml          |   2 +-
 .../DefaultRecord/data-escapeHtml.phtml       |   8 -
 .../data-escapeHtmlCommaSep.phtml             |   9 -
 .../DefaultRecord/data-transEsc.phtml         |   8 -
 .../DefaultRecord/data-transEscCommaSep.phtml |   7 -
 .../RecordDriver/SolrLido/data-dateSpan.phtml |   1 -
 7 files changed, 103 insertions(+), 197 deletions(-)
 delete mode 100644 themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtml.phtml
 delete mode 100644 themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtmlCommaSep.phtml
 delete mode 100644 themes/finc/templates/RecordDriver/DefaultRecord/data-transEsc.phtml
 delete mode 100644 themes/finc/templates/RecordDriver/DefaultRecord/data-transEscCommaSep.phtml
 delete mode 100644 themes/finc/templates/RecordDriver/SolrLido/data-dateSpan.phtml

diff --git a/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php b/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
index c959eec5b6e..74409d373d8 100644
--- a/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
+++ b/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
@@ -197,15 +197,13 @@ class RecordDataFormatterFactory
             'Title',
             'getTitleDetails'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Dates of publication',
-            'getDateSpan',
-            'data-escapeHtml.phtml'
+            'getDateSpan'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Summary',
-            'getSummary',
-            'data-escapeHtml.phtml'
+            'getSummary'
         );
         $spec->setTemplateLine(
             'Published',
@@ -225,15 +223,13 @@ class RecordDataFormatterFactory
         );
         /* finc: remove 'Online Access' in record-details #13770 - VE */
         /* $spec->setTemplateLine('Online Access', true, 'data-onlineAccess.phtml'); */
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Item Description',
-            'getGeneralNotes',
-            'data-escapeHtml.phtml'
+            'getGeneralNotes'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Production Credits',
-            'getProductionCredits',
-            'data-escapeHtml.phtml'
+            'getProductionCredits'
         );
         $spec->setTemplateLine(
             'Set Multipart',
@@ -250,10 +246,10 @@ class RecordDataFormatterFactory
             'getISSNs',
             'data-issn.phtml'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Notes',
             'getAdditionalNotes',
-            'data-escapeHtml.phtml',
+            null,
             [
                 'useCache' => true
             ]
@@ -310,15 +306,13 @@ class RecordDataFormatterFactory
             'RecordHelper',
             ['helperMethod' => 'getFormatList']
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Access',
-            'getAccessRestrictions',
-            'data-escapeHtml.phtml'
+            'getAccessRestrictions'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Related Items',
-            'getRelationshipNotes',
-            'data-escapeHtml.phtml'
+            'getRelationshipNotes'
         );
         return $spec->getArray();
     }
@@ -383,7 +377,10 @@ class RecordDataFormatterFactory
         $spec->setLine(
             'Dissertation Note',
             'getDissertationNote',
-            'data-escapeHtmlCommaSep.phtml'
+            null,
+            [
+                'separator' => ', '
+            ]
         );
         $spec->setLine(
             'Format',
@@ -429,20 +426,19 @@ class RecordDataFormatterFactory
             'getAdditionals',
             [$this,'additionals']
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Source',
-            'getMegaCollection',
-            'data-escapeHtml.phtml'
+            'getMegaCollection'
         );
         $spec->setMultiLine(
             "Other Relationship Entry",
             'getOtherRelationshipEntry',
             [$this,'otherRelationshipEntry']
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Notes',
             'getAdditionalNotes',
-            'data-escapeHtml.phtml',
+            null,
             [
                 'useCache' => true
             ]
@@ -459,60 +455,49 @@ class RecordDataFormatterFactory
     public function getDefaultDescriptionSpecs()
     {
         $spec = new RecordDataFormatter\SpecBuilder();
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Summary',
-            'getSummary',
-            'data-escapeHtml.phtml'
+            'getSummary'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Dates of publication',
-            'getDateSpan',
-            'data-escapeHtml.phtml'
+            'getDateSpan'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Item Description',
-            'getGeneralNotes',
-            'data-escapeHtml.phtml'
+            'getGeneralNotes'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Physical Description',
-            'getPhysicalDescriptions',
-            'data-escapeHtml.phtml'
+            'getPhysicalDescriptions'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Publication Frequency',
-            'getPublicationFrequency',
-            'data-escapeHtml.phtml'
+            'getPublicationFrequency'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Playing Time',
-            'getPlayingTimes',
-            'data-escapeHtml.phtml'
+            'getPlayingTimes'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Format',
-            'getSystemDetails',
-            'data-escapeHtml.phtml'
+            'getSystemDetails'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Audience',
-            'getTargetAudienceNotes',
-            'data-escapeHtml.phtml'
+            'getTargetAudienceNotes'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Awards',
-            'getAwards',
-            'data-escapeHtml.phtml'
+            'getAwards'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Production Credits',
-            'getProductionCredits',
-            'data-escapeHtml.phtml'
+            'getProductionCredits'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Bibliography',
-            'getBibliographyNotes',
-            'data-escapeHtml.phtml'
+            'getBibliographyNotes'
         );
         $spec->setTemplateLine(
             'ISBN',
@@ -524,35 +509,29 @@ class RecordDataFormatterFactory
             'getISSNs',
             'data-issn.phtml'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'DOI',
-            'getCleanDOI',
-            'data-escapeHtml.phtml'
+            'getCleanDOI'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'EISSN',
-            'getEISSNs',
-            'data-escapeHtml.phtml'
+            'getEISSNs'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Related Items',
-            'getRelationshipNotes',
-            'data-escapeHtml.phtml'
+            'getRelationshipNotes'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Access',
-            'getAccessRestrictions',
-            'data-escapeHtml.phtml'
+            'getAccessRestrictions'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Finding Aid',
-            'getFindingAids',
-            'data-escapeHtml.phtml'
+            'getFindingAids'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Publication_Place',
-            'getHierarchicalPlaceNames',
-            'data-escapeHtml.phtml'
+            'getHierarchicalPlaceNames'
         );
         $spec->setTemplateLine(
             'Author Notes',
@@ -564,10 +543,10 @@ class RecordDataFormatterFactory
             'getLocalSignature',
             'data-localSignature.phtml'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Notes',
             'getAdditionalNotes',
-            'data-escapeHtml.phtml',
+            null,
             [
                 'useCache' => true
             ]
@@ -636,86 +615,46 @@ class RecordDataFormatterFactory
                 ],
             ]
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Subject Detail',
-            'getSubjectDetails',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordSubjects']
-            ]
+            'getSubjectDetails'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Subject Place',
-            'getSubjectPlaces',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordSubjects']
-            ]
+            'getSubjectPlaces'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Subject Date',
-            'getSubjectDates',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordSubjects']
-            ]
+            'getSubjectDates'
         );
 
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Subject Actor',
-            'getSubjectActors',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordSubjects']
-            ]
+            'getSubjectActors'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Institution',
-            'getInstitutions',
-            'data-institutions.phtml',
-            [
-                'context' => ['class' => 'recordInstitution']
-            ]
+            'getInstitutions'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Inventory ID',
-            'getIdentifier',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordIdentifier']
-            ]
+            'getIdentifier'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Inventory ID',
-            'getIdentifier',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordIdentifier']
-            ]
+            'getIdentifier'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Measurements',
-            'getMeasurements',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordMeasurements']
-            ]
+            'getMeasurements'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Measurements',
-            'getMeasurementsDescription',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordMeasurements']
-            ]
+            'getMeasurementsDescription'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Collection',
-            'getCollections',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordCollection']
-            ]
+            'getCollections'
         );
         $spec->setLine(
             'Object type',
@@ -723,21 +662,13 @@ class RecordDataFormatterFactory
             'RecordHelper',
             ['helperMethod' => 'getFormatList']
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Other Classification',
-            'getFormatClassifications',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordClassifications']
-            ]
+            'getFormatClassifications'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Other ID',
-            'getLocalIdentifiers',
-            'data-escapeHtml.phtml',
-            [
-                'context' => ['class' => 'recordIdentifiers']
-            ]
+            'getLocalIdentifiers'
         );
         $spec->setMultiLine(
             'Events',
@@ -750,15 +681,18 @@ class RecordDataFormatterFactory
             'getLanguages',
             'data-transEscCommaSepLang.phtml'
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Time of origin',
             'getDateSpan',
-            'data-dateSpan.phtml'
+            'recordHelper',
+            [
+                'helperMethod' => 'mapDateListToRangeView'
+            ]
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Edition',
             'getEdition',
-            'data-escapeHtml.phtml',
+            null,
             [
                 'prefix' => '<span property="bookEdition">',
                 'suffix' => '</span>'
@@ -787,10 +721,13 @@ class RecordDataFormatterFactory
     public function getLidoDescriptionSpecs()
     {
         $spec = new RecordDataFormatter\SpecBuilder();
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Time of origin',
             'getDateSpan',
-            'data-dateSpan.phtml'
+            'recordHelper',
+            [
+                'helperMethod' => 'mapDateListToRangeView'
+            ]
         );
         $spec->setTemplateLine(
             'Access',
@@ -858,7 +795,10 @@ class RecordDataFormatterFactory
         $spec->setLine(
             'Dissertation Note',
             'getDissertationNote',
-            'data-escapeHtmlCommaSep.phtml'
+            null,
+            [
+                'separator' => ', '
+            ]
         );
         $spec->setLine(
             'Format',
@@ -919,20 +859,19 @@ class RecordDataFormatterFactory
                 }
             ]
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Source',
-            'getMegaCollection',
-            'data-escapeHtml.phtml'
+            'getMegaCollection'
         );
         $spec->setMultiLine(
             "Other Relationship Entry",
             'getOtherRelationshipEntry',
             [$this,'otherRelationshipEntry']
         );
-        $spec->setTemplateLine(
+        $spec->setLine(
             'Notes',
             'getAdditionalNotes',
-            'data-escapeHtml.phtml',
+            null,
             [
                 'useCache' => true
             ]
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-authors.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-authors.phtml
index 7330dda85d6..7fd72a9503a 100644
--- a/themes/finc/templates/RecordDriver/DefaultRecord/data-authors.phtml
+++ b/themes/finc/templates/RecordDriver/DefaultRecord/data-authors.phtml
@@ -53,5 +53,5 @@ $types = [
     <?php endforeach; ?>
   <?php endif; ?>
 <?php endforeach; ?>
-<?=implode(', ', $formattedAuthors)?>
+<?=implode($separator ?? ', ', $formattedAuthors)?>
 <!-- finc: RecordDriver - DefaultRecord - data-authors - END -->
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtml.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtml.phtml
deleted file mode 100644
index 2cf79df5dbd..00000000000
--- a/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtml.phtml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php // Don't add START and END comments ?>
-<?php if (!empty($data)): ?>
-  <?php if (is_array($data)): ?>
-    <?=implode('<br/>', array_map(array($this, 'escapeHtml'), $data))?>
-  <?php else: ?>
-    <?=$this->escapeHtml($data)?>
-  <?php endif; ?>
-<?php endif; ?>
\ No newline at end of file
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtmlCommaSep.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtmlCommaSep.phtml
deleted file mode 100644
index f1c711c47a8..00000000000
--- a/themes/finc/templates/RecordDriver/DefaultRecord/data-escapeHtmlCommaSep.phtml
+++ /dev/null
@@ -1,9 +0,0 @@
-<!-- finc: RecordDriver - DefaultRecord - data-escapeHtmlCommaSep -->
-<?php if (!empty($data)): ?>
-  <?php if (is_array($data)): ?>
-    <?=implode(', ', array_map(array($this, 'escapeHtml'), $data));?>
-  <?php else: ?>
-    <?=$this->escapeHtml($data)?>
-  <?php endif; ?>
-<?php endif; ?>
-<!-- finc: RecordDriver - DefaultRecord - data-escapeHtmlCommaSep - END -->
\ No newline at end of file
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-transEsc.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-transEsc.phtml
deleted file mode 100644
index efe6e050f56..00000000000
--- a/themes/finc/templates/RecordDriver/DefaultRecord/data-transEsc.phtml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php // Don't add START and END comments ?>
-<?php if (!empty($data)): ?>
-  <?php if (is_array($data)): ?>
-    <?=implode('<br/>', array_map(array($this, 'transEsc'), $data))?>
-  <?php else: ?>
-    <?=$this->transEsc($data)?>
-  <?php endif; ?>
-<?php endif; ?>
\ No newline at end of file
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-transEscCommaSep.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-transEscCommaSep.phtml
deleted file mode 100644
index 61fd836915c..00000000000
--- a/themes/finc/templates/RecordDriver/DefaultRecord/data-transEscCommaSep.phtml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php if (!empty($data)): ?>
-  <?php if (is_array($data)): ?>
-    <?=implode(', ', array_map(array($this, 'transEsc'), $data));?>
-  <?php else: ?>
-    <?=$this->transEsc($data)?>
-  <?php endif; ?>
-<?php endif; ?>
\ No newline at end of file
diff --git a/themes/finc/templates/RecordDriver/SolrLido/data-dateSpan.phtml b/themes/finc/templates/RecordDriver/SolrLido/data-dateSpan.phtml
deleted file mode 100644
index 59a1191eb97..00000000000
--- a/themes/finc/templates/RecordDriver/SolrLido/data-dateSpan.phtml
+++ /dev/null
@@ -1 +0,0 @@
-<?= $this->record($this->driver)->mapDateListToRangeView($data); ?>
\ No newline at end of file
-- 
GitLab