Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

entityLinks from Collection are not set in the embeded entity. #175

Open
vlx73 opened this issue Nov 18, 2019 · 2 comments
Open

entityLinks from Collection are not set in the embeded entity. #175

vlx73 opened this issue Nov 18, 2019 · 2 comments

Comments

@vlx73
Copy link

vlx73 commented Nov 18, 2019

If I set entity links within collection using $collection->setEntityLinks($LinkColection) these are not rendered.
Within Hal plugin exctractCollection() method if the $entity has metadataMap then its created from metadataMap inclusive links.

if (is_object($entity) && $metadataMap->has($entity)) { $entity = $this->getResourceFactory()->createEntityFromMetadata($entity, $metadataMap->get($entity)); }

After that there is only the call for rendering the $entity.
if ($entity instanceof Entity) { // Depth does not increment at this level $collection[] = $this->renderEntity($entity, $this->getRenderCollections(), $depth, $maxDepth); continue; }

Probably there shall be a call to $entity->setLink($halCollection->getEntityLinks()) before the rendering.

@vlx73
Copy link
Author

vlx73 commented Nov 19, 2019

I would propose following change . in the protected method of class Hal

`protected function extractCollection(Collection $halCollection, $depth = 0, $maxDepth = null)
{
...
if ($entity instanceof Entity) {

            // inject entity links from the parrent Collection
            if (!is_null($halCollection->getEntityLinks())) {
                $entityLinks = $entity->getLinks();
                foreach ($halCollection->getEntityLinks() as $collectionsEntityLink)
                    $entityLinks->idempotentAdd($collectionsEntityLink);
            }

            // Depth does not increment at this level
            $collection[] = $this->renderEntity($entity, $this->getRenderCollections(), $depth, $maxDepth);
            continue;
        }`

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-hal; a new issue has been opened at laminas-api-tools/api-tools-hal#1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants