From 6406c70aa7adbfc942fc62eb70c0291d17b4373e Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 11 Aug 2022 15:39:19 -0400 Subject: [PATCH] Add way to use value term to get property (#1171) --- application/src/Api/Adapter/ValueHydrator.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/application/src/Api/Adapter/ValueHydrator.php b/application/src/Api/Adapter/ValueHydrator.php index c6431fd37b..f77c33ea48 100644 --- a/application/src/Api/Adapter/ValueHydrator.php +++ b/application/src/Api/Adapter/ValueHydrator.php @@ -73,7 +73,7 @@ public function hydrate(Request $request, Resource $entity, $entityManager = $adapter->getEntityManager(); $dataTypes = $adapter->getServiceLocator()->get('Omeka\DataTypeManager'); - // Iterate the representation data. Note that we ignore terms. + // Iterate the representation data. $valuePassed = false; foreach ($representation as $term => $valuesData) { if (!is_array($valuesData)) { @@ -113,10 +113,12 @@ public function hydrate(Request $request, Resource $entity, // Hydrate a single value. $value->setResource($entity); $value->setType($dataType->getName()); - $value->setProperty($entityManager->getReference( - 'Omeka\Entity\Property', - $valueData['property_id'] - )); + // If the property_id is "auto", look out to the value's key for + // a property term. + $property = 'auto' === $valueData['property_id'] + ? $adapter->getPropertyByTerm($term) + : $entityManager->getReference('Omeka\Entity\Property', $valueData['property_id']); + $value->setProperty($property); if (isset($valueData['is_public'])) { $value->setIsPublic($valueData['is_public']); }