Skip to content

Commit

Permalink
Filter properties for displayValues(); pass options to event (#2228)
Browse files Browse the repository at this point in the history
(fix #2225, fix #2226)
  • Loading branch information
jimsafley authored Sep 12, 2024
1 parent 3f1ca36 commit eb54866
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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();
Expand Down

0 comments on commit eb54866

Please sign in to comment.