From 2f73f48bff729a11a6806cd3e4b3d2d05319ca44 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 14 Sep 2020 00:00:00 +0000 Subject: [PATCH] Get values of different types in one time. --- .../AbstractResourceEntityRepresentation.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/application/src/Api/Representation/AbstractResourceEntityRepresentation.php b/application/src/Api/Representation/AbstractResourceEntityRepresentation.php index 638ccccfb7..166c993e7b 100644 --- a/application/src/Api/Representation/AbstractResourceEntityRepresentation.php +++ b/application/src/Api/Representation/AbstractResourceEntityRepresentation.php @@ -309,8 +309,9 @@ public function values() * * @param string $term The prefix:local_part * @param array $options - * - type: (null) Get values of this type only. Valid types are "literal", - * "uri", and "resource". Returns all types by default. + * - type (array|string): Get values of these types only. Default types are + * "literal", "uri", "resource", "resource:item", "resource:media" and + * "resource:itemset". Returns all types by default. * - all: (false) If true, returns all values that match criteria. If false, * returns the first matching value. * - default: (null) Default value if no values match criteria. Returns null @@ -322,9 +323,6 @@ public function values() public function value($term, array $options = []) { // Set defaults. - if (!isset($options['type'])) { - $options['type'] = null; - } if (!isset($options['all'])) { $options['all'] = false; } @@ -343,12 +341,18 @@ public function value($term, array $options = []) return $options['default']; } + if (empty($options['type'])) { + $types = false; + } elseif (is_array($options['type'])) { + $types = $options['type']; + } else { + $types = [$options['type']]; + } + // Match only the representations that fit all the criteria. $matchingValues = []; foreach ($this->values()[$term]['values'] as $value) { - if (!is_null($options['type']) - && $value->type() !== $options['type'] - ) { + if ($types && !in_array($value->type(), $types)) { continue; } if (!is_null($options['lang'])