Skip to content

Commit

Permalink
Merge pull request omeka#1882 from omeka/property-id-term
Browse files Browse the repository at this point in the history
Add way to use a value's term to get property
  • Loading branch information
zerocrates authored Aug 16, 2022
2 parents 1e93284 + 6406c70 commit a1c37b1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions application/src/Api/Adapter/ValueHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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']);
}
Expand Down

0 comments on commit a1c37b1

Please sign in to comment.