From bb4cbf595522be504ecee052ab0c3d4875c36860 Mon Sep 17 00:00:00 2001
From: Dorian Merz <merz@ub.uni-leipzig.de>
Date: Thu, 26 Aug 2021 10:36:22 +0200
Subject: [PATCH] refs #19336 [finc] introduce RecordDataFormatter config for
 TOC tab contents

* use getTOC and specific data template for TOC tab
---
 .../Root/RecordDataFormatterFactory.php       | 20 +++++++++++
 .../templates/RecordTab/toc.phtml             | 35 -------------------
 .../RecordDriver/DefaultRecord/data-toc.phtml |  7 ++++
 themes/finc/templates/RecordTab/toc.phtml     | 16 +++++++++
 4 files changed, 43 insertions(+), 35 deletions(-)
 delete mode 100644 themes/finc-accessibility/templates/RecordTab/toc.phtml
 create mode 100644 themes/finc/templates/RecordDriver/DefaultRecord/data-toc.phtml
 create mode 100644 themes/finc/templates/RecordTab/toc.phtml

diff --git a/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php b/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
index 372032924f2..4b8ae4866d2 100644
--- a/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
+++ b/module/finc/src/finc/View/Helper/Root/RecordDataFormatterFactory.php
@@ -71,6 +71,10 @@ class RecordDataFormatterFactory
             'description',
             [$this, 'getDefaultDescriptionSpecs']
         );
+        $helper->setDefaults(
+            'toc',
+            [$this, 'getTOCSpecs']
+        );
         $helper->setDefaults(
             'core-ai',
             [$this, 'getAiCoreSpecs']
@@ -893,4 +897,20 @@ class RecordDataFormatterFactory
             ? 'rda_original_title'
             : 'non_rda_original_title';
     }
+
+    /**
+     * Get marc specifications for displaying table of contents.
+     *
+     * @return array
+     */
+    public function getTOCSpecs()
+    {
+        $spec = new RecordDataFormatter\SpecBuilder();
+        $spec->setTemplateLine(
+            'Table of Contents',
+            'getTOC',
+            'data-toc.phtml'
+        );
+        return $spec->getArray();
+    }
 }
diff --git a/themes/finc-accessibility/templates/RecordTab/toc.phtml b/themes/finc-accessibility/templates/RecordTab/toc.phtml
deleted file mode 100644
index 6e71822f850..00000000000
--- a/themes/finc-accessibility/templates/RecordTab/toc.phtml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!-- finc-accessibility: RecordTab - toc -->
-<?php /**
- *  copy of VuFind-version, adds empty lang-attribute to <li>s
- */
-?>
-?>
-<?php
-    // Set page title.
-    $this->headTitle($this->translate('Table of Contents') . ': ' . $this->driver->getBreadcrumb());
-
-    $toc = $this->tab->getContent();
-    if (empty($toc)) {
-        $driverToc = $this->driver->getTOC();
-        if (!empty($driverToc)) {
-            $toc['RecordDriver'] = $driverToc;
-        }
-    }
-?>
-<?php if (!empty($toc)): ?>
-  <strong><?=$this->transEsc('Table of Contents')?>: </strong>
-  <?php foreach ($toc as $provider => $content): ?>
-    <?php if (!is_array($content)): // treat non-array content as raw HTML ?>
-      <?=$content?>
-    <?php else: ?>
-      <ul class="toc">
-      <?php foreach ($content as $line): ?>
-        <li lang=""><?=$this->escapeHtml($line)?></li>
-      <?php endforeach; ?>
-      </ul>
-    <?php endif; ?>
-  <?php endforeach; ?>
-<?php else: ?>
-  <?=$this->transEsc('Table of Contents unavailable')?>.
-<?php endif; ?>
-<!-- finc-accessibility: RecordTab - toc - END -->
\ No newline at end of file
diff --git a/themes/finc/templates/RecordDriver/DefaultRecord/data-toc.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/data-toc.phtml
new file mode 100644
index 00000000000..e2c53a3d900
--- /dev/null
+++ b/themes/finc/templates/RecordDriver/DefaultRecord/data-toc.phtml
@@ -0,0 +1,7 @@
+<!-- finc: RecordDriver - DefaultRecord - data-toc -->
+<ul class="toc">
+<?php foreach ($data as $item): ?>
+    <li lang=""><?=$this->escapeHtml($item)?></li>
+<?php endforeach; ?>
+</ul>
+<!-- finc: RecordDriver - DefaultRecord - data-toc - END -->
\ No newline at end of file
diff --git a/themes/finc/templates/RecordTab/toc.phtml b/themes/finc/templates/RecordTab/toc.phtml
new file mode 100644
index 00000000000..eb89dc704ee
--- /dev/null
+++ b/themes/finc/templates/RecordTab/toc.phtml
@@ -0,0 +1,16 @@
+<!-- finc: RecordTab - toc -->
+<?php
+    // Set page title.
+    $this->headTitle($this->translate('Table of Contents') . ': ' . $this->driver->getBreadcrumb());
+    $formatter = $this->recordDataFormatter();
+    $mainFields = $formatter->getData($this->driver, $formatter->getDefaults('toc'));
+?>
+<?php if (!empty($mainFields)): ?>
+  <?php foreach ($mainFields as $current): ?>
+    <strong><?=$this->transEsc($current['label'])?>: </strong>
+    <?=$current['value']?>
+  <?php endforeach; ?>
+<?php else: ?>
+  <?=$this->transEsc('Table of Contents unavailable')?>.
+<?php endif; ?>
+<!-- finc: RecordTab - toc - END -->
\ No newline at end of file
-- 
GitLab