diff --git a/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php b/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php index b186f4f2eb44676a028fd02bfbced610470d7899..cf5e262c106ea2d6a1ca1a2b8da2da17b42d65d1 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php @@ -73,7 +73,7 @@ class RecordDataFormatter extends AbstractHelper * @param RecordDriver $driver Record driver object. * @param array $spec Formatting specification * - * @return Record + * @return array */ public function getData(RecordDriver $driver, array $spec) { @@ -105,7 +105,11 @@ class RecordDataFormatter extends AbstractHelper ) { $field = call_user_func($current['labelFunction'], $data); } - $result[$field] = $text; + $context = isset($current['context']) ? $current['context'] : []; + $result[$field] = [ + 'value' => $text, + 'context' => $context + ]; } } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordDataFormatterTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordDataFormatterTest.php index fe2e74915622d8d95da8f5385e016ff08ba3d531..4f5ee4842769cdde03e25444c98912f20b1d57da 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordDataFormatterTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordDataFormatterTest.php @@ -157,7 +157,9 @@ class RecordDataFormatterTest extends \VuFindTest\Unit\ViewHelperTestCase { $formatter = $this->getFormatter(); $spec = $formatter->getDefaults('core'); - $spec['Building'] = ['dataMethod' => 'getBuilding', 'pos' => 0]; + $spec['Building'] = [ + 'dataMethod' => 'getBuilding', 'pos' => 0, 'context' => ['foo' => 1] + ]; $expected = [ 'Building' => '0', @@ -182,11 +184,15 @@ class RecordDataFormatterTest extends \VuFindTest\Unit\ViewHelperTestCase // Check for expected text (with markup stripped) foreach ($expected as $key => $value) { $this->assertEquals( - $value, trim(preg_replace('/\s+/', ' ', strip_tags($results[$key]))) + $value, + trim(preg_replace('/\s+/', ' ', strip_tags($results[$key]['value']))) ); } // Check for exact markup in representative example: - $this->assertEquals('Italian<br />Latin', $results['Language']); + $this->assertEquals('Italian<br />Latin', $results['Language']['value']); + + // Check for context in Building: + $this->assertEquals(['foo' => 1], $results['Building']['context']); } } diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml index 670ca115ead2c768784f922b1ea4c6aee4166c1f..dc91ed04a70c6ae637ee10361c1ed6564ca587d3 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-info.phtml @@ -47,8 +47,8 @@ ?> <? if (!empty($fields)): ?> <table id="collectionInfo" class="table table-striped" summary="<?=$this->transEsc('Bibliographic Details')?>"> - <? foreach ($fields as $key => $value): ?> - <tr><th><?=$this->transEsc($key)?>:</th><td><?=$value?></td></tr> + <? foreach ($fields as $key => $current): ?> + <tr><th><?=$this->transEsc($key)?>:</th><td><?=$current['value']?></td></tr> <? endforeach; ?> </table> <? endif; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-record.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-record.phtml index 93d236d6438cf78afc45ec9a58dc7e7cd40fb020..64ce05a7b5dcbde529a8202366bbc2d785f7ad27 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-record.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/collection-record.phtml @@ -7,8 +7,8 @@ ?> <? if (!empty($fields)): ?> <table class="table table-striped" summary="<?=$this->transEsc('Bibliographic Details')?>"> - <? foreach ($fields as $key => $value): ?> - <tr><th><?=$this->transEsc($key)?>:</th><td><?=$value?></td></tr> + <? foreach ($fields as $key => $current): ?> + <tr><th><?=$this->transEsc($key)?>:</th><td><?=$current['value']?></td></tr> <? endforeach; ?> </table> <? endif; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml index 4504c41094423efd2d2e729a3892db9a245be99e..464e5a00b12b21b2924a705a4d708582409fc9d9 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/core.phtml @@ -55,8 +55,8 @@ ?> <? if (!empty($coreFields)): ?> <table class="table table-striped" summary="<?=$this->transEsc('Bibliographic Details')?>"> - <? foreach ($coreFields as $key => $value): ?> - <tr><th><?=$this->transEsc($key)?>:</th><td><?=$value?></td></tr> + <? foreach ($coreFields as $key => $current): ?> + <tr><th><?=$this->transEsc($key)?>:</th><td><?=$current['value']?></td></tr> <? endforeach; ?> </table> <? endif; ?> diff --git a/themes/bootstrap3/templates/RecordDriver/SolrDefault/data-authors.phtml b/themes/bootstrap3/templates/RecordDriver/SolrDefault/data-authors.phtml index d5e934703ba744896233ecbbc109f010d4081fdf..bbc3a63584b902dacbc53ce54f71de7923e3f243 100644 --- a/themes/bootstrap3/templates/RecordDriver/SolrDefault/data-authors.phtml +++ b/themes/bootstrap3/templates/RecordDriver/SolrDefault/data-authors.phtml @@ -21,12 +21,14 @@ $formattedAuthors = []; <? // Display additional data using the appropriate translation prefix // (for example, to render author roles correctly): - foreach ($requiredDataFields as $field) { - $name = $field['name']; - $prefix = isset($field['prefix']) ? $field['prefix'] : ''; - if (isset($dataFields[$name])) { - echo $formatProperty($dataFields[$name], $name, $prefix); - } + if (!empty($requiredDataFields)) { + foreach ($requiredDataFields as $field) { + $name = $field['name']; + $prefix = isset($field['prefix']) ? $field['prefix'] : ''; + if (isset($dataFields[$name])) { + echo $formatProperty($dataFields[$name], $name, $prefix); + } + } } ?> </span> diff --git a/themes/bootstrap3/templates/RecordTab/description.phtml b/themes/bootstrap3/templates/RecordTab/description.phtml index e989574ff21e0736e5237e55b3ee8e3072f9bf86..3d73373ffc50f983c38e8046f959e60cd5c6e6fc 100644 --- a/themes/bootstrap3/templates/RecordTab/description.phtml +++ b/themes/bootstrap3/templates/RecordTab/description.phtml @@ -7,8 +7,8 @@ ?> <table class="table table-striped" summary="<?=$this->transEsc('Description')?>"> <? if (!empty($mainFields)): ?> - <? foreach ($mainFields as $key => $value): ?> - <tr><th><?=$this->transEsc($key)?>:</th><td><?=$value?></td></tr> + <? foreach ($mainFields as $key => $current): ?> + <tr><th><?=$this->transEsc($key)?>:</th><td><?=$current['value']?></td></tr> <? endforeach; ?> <? else: ?> <tr><td><?=$this->transEsc('no_description')?></td></tr>