-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use metadata map when rendering collections of "related" resources #102
Comments
I am not totally sure if i understand it correctly, but can you not pass the correct route/url to the collection in the hydrator (where you embed it in your resource). |
My case is very similar to the one explained in the docs - Advanced routing. The
The difference from the example in the docs is that the In such case the the route for the items in the collection is taken from the controller config (in `$config['phlyrestfully']['resources']) and the metadata are ignored, which seems to me a bit incosistent. Of course, there are several possible workarounds and also - it's possible that I'm doing something wrong. |
Maybe you just have to attach a listener to the |
Yes, this might be a solution, but I thought it could be done in a more elegant way :). The page you are referencing itself says: "In general, you shouldn’t need to tie into the events listed on this page very often. The recommended way to customize URL generation for resources is to instead use a metadata map." Thanks for your help anyway. |
What goes wrong when you use metadata mapping...? |
Ok, I'll try to be more specific.
And these resource controllers:
Now, the https://github.com/phly/PhlyRestfully/blob/master/src/PhlyRestfully/ResourceController.php#L490 This route is used for "self" link generation, which in this case is:
The problem is that the items of the collection use the same route for generating "self" links, although there exists a valid mapping in the metadata map. Here it is obvious, that the route name assigned to the HalCollection earlier is used in the "self" link generation of the items: https://github.com/phly/PhlyRestfully/blob/master/src/PhlyRestfully/Plugin/HalLinks.php#L784 The metadata map is used only, if an item of the collection contains an embedded resource: https://github.com/phly/PhlyRestfully/blob/master/src/PhlyRestfully/Plugin/HalLinks.php#L811 It is not used for the "first-level" item itself. And the metadata mapping is OK, because the right hydrator is used and the item is converted to an array properly: https://github.com/phly/PhlyRestfully/blob/master/src/PhlyRestfully/Plugin/HalLinks.php#L807 The only thing needed is to get the route name from the metadata map along with the right hydrator. |
That's helpful, but please also show me your resource mapping from your config.php :-) |
Sure, actually it's here on github :). |
Suppose we have
users
andgroups
resources with the corresponding routes -/users[/:id]
and/groups[/:id]
.If I need to list users which are members of a group I have to use a "child" resource with a route
/groups/:id/users
, which returns a collection of users.I followed the documentation and everything worked fine. Except one thing - the self links of the users under
/groups/:id/users
were (as expected) using the route from the corresponding resource, for example:Instead, I'd like to have the "standard" location:
I tried to define a
route
option for theUsers
collection in the metadata map, but it was ignored. I examined theextractCollection()
method inPlugin\HalLinks.php
and it seems that metadata are taken into consideration only if the resource is embedded, but not if it is in the "first level" of the collection.I may provide a solution, but I just wanted to ask, if I'm getting this right.
The text was updated successfully, but these errors were encountered: