From e59396753e8a5ddb42372b4604b789db075ad98e Mon Sep 17 00:00:00 2001 From: Simon Hohl <mail@dersmon.net> Date: Thu, 16 Aug 2018 13:49:22 +0200 Subject: [PATCH] Keep author fields even if no role is given (#1216) --- .../src/VuFindApi/Formatter/BaseFormatter.php | 5 ++++- .../src/VuFindTest/Formatter/RecordFormatterTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/module/VuFindApi/src/VuFindApi/Formatter/BaseFormatter.php b/module/VuFindApi/src/VuFindApi/Formatter/BaseFormatter.php index 96588b0bfa4..9c7d843d49e 100644 --- a/module/VuFindApi/src/VuFindApi/Formatter/BaseFormatter.php +++ b/module/VuFindApi/src/VuFindApi/Formatter/BaseFormatter.php @@ -56,7 +56,10 @@ class BaseFormatter $this->resetArrayIndices($value); } - if ((is_array($value) && empty($value)) + // We don't want to return empty values -- unless it's an empty array + // with a non-numeric key, since the key could be significant (e.g. in + // the case of an author name => roles array with no assigned roles). + if ((is_numeric($key) && is_array($value) && empty($value)) || (is_bool($value) && !$value) || $value === null || $value === '' ) { diff --git a/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/RecordFormatterTest.php b/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/RecordFormatterTest.php index 686cfb894d9..169642533af 100644 --- a/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/RecordFormatterTest.php +++ b/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/RecordFormatterTest.php @@ -68,6 +68,7 @@ class RecordFormatterTest extends \VuFindTest\Unit\TestCase 'subjectsExtended' => [ 'vufind.method' => 'Formatter::getExtendedSubjectHeadings' ], + 'authors' => ['vufind.method' => 'getDeduplicatedAuthors'], ]; } @@ -121,6 +122,10 @@ class RecordFormatterTest extends \VuFindTest\Unit\TestCase 'spelling' => 's', 'Building' => ['foo', new TranslatableString('bar', 'xyzzy')], 'AllSubjectHeadings' => [['heading' => 'subject']], + 'DeduplicatedAuthors' => [ + 'primary' => ['Ms. A' => ['role' => ['Editor']]], + 'secondary' => ['Mr. B' => [], 'Mr. C' => []], + ], ] ); return $driver; @@ -158,6 +163,10 @@ class RecordFormatterTest extends \VuFindTest\Unit\TestCase 'buildings' => ['foo', ['value' => 'bar', 'translated' => 'xyzzy']], 'recordPage' => 'http://record', 'subjectsExtended' => [['heading' => 'subject']], + 'authors' => [ + 'primary' => ['Ms. A' => ['role' => ['Editor']]], + 'secondary' => ['Mr. B' => [], 'Mr. C' => []], + ], ], ]; $this->assertEquals($expected, $results); @@ -197,6 +206,7 @@ class RecordFormatterTest extends \VuFindTest\Unit\TestCase 'buildings' => [], 'recordPage' => [], 'subjectsExtended' => [], + 'authors' => [], ]; $this->assertEquals($expected, $results); } -- GitLab