diff --git a/application/src/Api/Adapter/ResourceAdapter.php b/application/src/Api/Adapter/ResourceAdapter.php index f717702a5..66821ff4d 100644 --- a/application/src/Api/Adapter/ResourceAdapter.php +++ b/application/src/Api/Adapter/ResourceAdapter.php @@ -33,7 +33,6 @@ public function hydrate(Request $request, EntityInterface $entity, ErrorStore $e * * This version simply proxies to the "real" getRepresentation for each resource's adapter. * - * @param string|int $id The unique identifier of the resource * @param mixed $data Whatever data is needed to compose the representation. * @return ResourceInterface|null */ diff --git a/application/src/Api/Adapter/ValueAnnotationAdapter.php b/application/src/Api/Adapter/ValueAnnotationAdapter.php index 1b8b4d04e..9f04c4f4b 100644 --- a/application/src/Api/Adapter/ValueAnnotationAdapter.php +++ b/application/src/Api/Adapter/ValueAnnotationAdapter.php @@ -2,7 +2,9 @@ namespace Omeka\Api\Adapter; use Omeka\Api\Representation\ValueAnnotationRepresentation; +use Omeka\Api\Representation\ValueRepresentation; use Omeka\Api\Request; +use Omeka\Api\ResourceInterface; use Omeka\Entity\ValueAnnotation; class ValueAnnotationAdapter extends AbstractResourceEntityAdapter @@ -46,4 +48,23 @@ public function delete(Request $request) { return AbstractAdapter::delete($request); } + + /** + * Compose a resource representation object. + * + * The value is not directly available in ValueAnnotation data, because + * their one-to-one relation is unidirectional, so append it here. + * + * @param mixed $data Whatever data is needed to compose the representation. + * @param ValueRepresentation|null + * @return ResourceInterface|null + */ + public function getRepresentation(ResourceInterface $data = null, ?ValueRepresentation $value = null) + { + if (!$data instanceof ValueAnnotation || !$value) { + // Do not attempt to compose a null representation. + return null; + } + return new ValueAnnotationRepresentation($data, $this, $value); + } } diff --git a/application/src/Api/Representation/ValueAnnotationRepresentation.php b/application/src/Api/Representation/ValueAnnotationRepresentation.php index 2c2eaa52b..3be796fff 100644 --- a/application/src/Api/Representation/ValueAnnotationRepresentation.php +++ b/application/src/Api/Representation/ValueAnnotationRepresentation.php @@ -1,8 +1,28 @@ value = $value; + } + public function getResourceJsonLdType() { return 'o:ValueAnnotation'; @@ -13,12 +33,31 @@ public function getResourceJsonLd() return []; } + /** + * Get the resource representation. + */ + public function resource(): AbstractResourceEntityRepresentation + { + return $this->value->resource(); + } + + /** + * Get the value representation. + */ + public function resourceValue(): ValueRepresentation + { + return $this->value; + } + public function displayValues(array $options = []) { $eventManager = $this->getEventManager(); $args = $eventManager->prepareArgs(['values' => $this->values()]); $eventManager->trigger('rep.resource.value_annotation_display_values', $this, $args); + $options['resource'] = $this->resource(); + $options['valueAnnotation'] = $this; $options['values'] = $args['values']; + $options['templateProperties'] = []; $partial = $this->getViewHelper('partial'); return $partial('common/value-annotation-resource-values', $options); diff --git a/application/src/Api/Representation/ValueRepresentation.php b/application/src/Api/Representation/ValueRepresentation.php index f6d7ef686..6eb747f6a 100644 --- a/application/src/Api/Representation/ValueRepresentation.php +++ b/application/src/Api/Representation/ValueRepresentation.php @@ -202,7 +202,7 @@ public function isPublic() public function valueAnnotation() { $valueAnnotation = $this->value->getValueAnnotation(); - return $valueAnnotation ? $this->getAdapter('value_annotations')->getRepresentation($valueAnnotation) : null; + return $valueAnnotation ? $this->getAdapter('value_annotations')->getRepresentation($valueAnnotation, $this) : null; } /**