Using Apigility v. 1.4 I strugle to add additional links to entity of a collection. I have apigility attached to my own services so I do not use the generated entity and collection object. I use the resource listener fetchall directly. I have nested resource /api/sellers/:seller_id/tickets[:/ticket_id] and use following code to generate the hall response. As the link ‘owner’ needs to have dynamically set :seller_id the metadatamap way of injecting links is not usable as these are static. I could not find a way how add any id to the “links” section of metadata. So I tried to use the setEntityLinks() of Collection. I seems that rendering Hal when the embeded object type is Entity, then only links defined in metadata_map are rendered and links set by setEntityLinks() are ignored. Is that correct? Is there any workaround, so that I can inject other links for entities within a collection? Below is code what I have tried, but does not render. Thank you in advance for hints.
indent preformatted text by 4 spaces
public function fetchAll($params = [])
{
$sellerid = $this->event->getRouteParam('seller_id');
$seller = $this->entityManager->getRepository(Seller::class)->findOneBysellerid($sellerid);
$tickets = $this->ticketsManager->getForSeller($seller);
$ticketsCollection = new Collection($tickets);
$ownerLink = new Link('owner');
$ownerLink->setRoute('api.rest.sellers', ['seller_id' => $sellerid]);
$entityLinkCollection = $ticketsCollection->getEntityLinks();
if (is_null($entityLinkCollection))
$entityLinkCollection = new LinkCollection();
$entityLinkCollection->add($ownerLink);
$ticketsCollection->setEntityLinks($entityLinkCollection);
return $ticketsCollection;
}