From eb548669fc96490068f743bbeddd0bada013b22e Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 12 Sep 2024 16:37:55 -0400 Subject: [PATCH] Filter properties for displayValues(); pass options to event (#2228) (fix #2225, fix #2226) --- .../AbstractResourceEntityRepresentation.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/application/src/Api/Representation/AbstractResourceEntityRepresentation.php b/application/src/Api/Representation/AbstractResourceEntityRepresentation.php index ed6367c29..7a1c78dc9 100644 --- a/application/src/Api/Representation/AbstractResourceEntityRepresentation.php +++ b/application/src/Api/Representation/AbstractResourceEntityRepresentation.php @@ -470,6 +470,8 @@ public function objectValues() * * - viewName: Name of view script, or a view model. Default "common/resource-values" * - siteId: A site ID + * - properties: an array of property terms to include in the markup (excludes all others) + * - excludeProperties: an array of property terms to exclude from the markup (includes all others) * * @param array $options * @return string @@ -478,10 +480,20 @@ public function displayValues(array $options = []) { $options['viewName'] ??= 'common/resource-values'; $options['siteId'] ??= null; + $options['properties'] ??= []; + $options['excludeProperties'] ??= []; $services = $this->getServiceLocator(); $values = $this->values(); + // Filter values by the "properties" and "excludeProperties" options. + if ($options['properties']) { + $values = array_intersect_key($values, array_flip($options['properties'])); + } + if ($options['excludeProperties']) { + $values = array_diff_key($values, array_flip($options['excludeProperties'])); + } + if ($options['siteId']) { // Exclude resources that are not assigned to the site if the // "exclude_resources_not_in_site" site setting is true. @@ -504,7 +516,7 @@ public function displayValues(array $options = []) } $eventManager = $this->getEventManager(); - $args = $eventManager->prepareArgs(['values' => $values]); + $args = $eventManager->prepareArgs(['values' => $values, 'options' => $options]); $eventManager->trigger('rep.resource.display_values', $this, $args); $template = $this->resourceTemplate();