Currently, entity's referred to be entityreference fields are stubs of an entry including only the referred entity's:

For graphs of entities connected by entityreference, multiple rounds of GET requests are needed to fully traverse this graph/network/bunch-of-entities. I'd like to be able to recursively load the tree of connected entities in a single request.

The related issue I've quoted here does this using what appears to an obsolete hook_restws_response_alter() and it's not trivial to port it to the current hook as it stands.

The former code snippet assumes the $response is an array expression that includes the entity's fields as keyed elements. The current hook_restws_response_alter() receives $response as a PHP DOMDocument class -- totally different kind of thing.

Edge cases include monkey wrenchs like cyclic networks. I'm going to assume, for now, that those don't exist / kittens will die if the first draft code snippet encounters a loop. I don't think the related issue I've referenced dealt with cyclic networks either.

I'll be working to close this gap, but any help would be appreciated. I'm also documenting it here for posterity.

Comments

JamesAn’s picture

Issue summary: View changes
btopro’s picture

errr why is hook_restws_response_alter deprecated? Funtion has been updated in the last year and now supports deep querying via the deep-load-refs meta controller (also altered in via available hooks). permissions respected and supports multiple entity targets.

https://github.com/btopro/elmsln/blob/master/core/dslmcode/shared/drupal...

JamesAn’s picture

Status: Active » Closed (works as designed)

Waahhh.. brain fart, You're right. I was attempting this with XML output (e.g. node/10.xml) and didn't realise until now that this isn't possible / is more involved than your implementation. I leaned towards XML output only because Aegir had a bug (that I've not resolved) that threw 404 errors rather than feeding URLs ending in .json to Drupal.

Closing issue. Thanks for responding. Your pointing in a direction saved me valuable time -- much appreciated.

I've refactored your code into a sandbox module (will probably polish it up for release). I'm going to invert the logic with your deep-load-refs meta controller for this module to blacklist entity types to not deep load, rather than whitelist the ones to load, as enabling the modules implies wanting to deep load.

I'd also like to recursively load entity references, handle cyclically linked reference networks, and parameterise all that with meta controllers.

btopro’s picture

V cool. Re your XML thing because I ran into that too and needed a way around it. I added a metacontroller for use with json called xml-out which will dump to XML instead of dealing w/ the normal XML processor. It's a hack but wow is it easier then dealing w/ the BS in XML class controllers:

https://github.com/btopro/elmsln/blob/df3ee8b401d255ed70b0862de32f8828e2...

Good luck on the sandbox, very interested in seeing that rolled in here as I did a lot of work in stepping around that issue so that I could reduce the calls involved :)

JamesAn’s picture

Yes! I saw your xml-out. MUCH better than dealing with DOMDocument and XML things in PHP. Just glad le client only needs JSON. O=)