Problem / Motivation
The path attribute of results is always null. I'm guessing that this should be the url alias of the node. It's also not possible to filter on path, resulting in a 500 error: "Path" Not found.
I was thinking that this issue #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise had something to do with it, but after downloading the latest version with the pathes of that issue, running update.php it still has the same result.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | jsonapi_2799909.patch | 2.08 KB | janlaureys |
Comments
Comment #2
janlaureys commentedI created a patch that adds a plugin compared to the file url. It returns an alias at least. Feels a bit dirty though :xYeah, that was no good really.
Comment #3
janlaureys commentedComment #4
e0ipsoComment #5
janlaureys commentedComment #6
e0ipsoSettings this to needs work.
Comment #7
dremy commentedI added a patch here: https://www.drupal.org/node/2649646#comment-11843756 from Related Issue: #2649646: [pp-1] Normalize path fields as part of the entity: allow REST clients to know the path alias, that has this working.
Comment #8
badrange commentedThere is a patch at https://www.drupal.org/node/2846554#comment-11924532 which seems to solve this. It also applies to 8.2.6 even though it is made for 8.4.x.
Comment #9
e0ipsoIt's worth noting that even if the path may be correctly exposed, you won't be able to filter by it:
Returns:
Comment #10
badrange commentedThanks for that heads up!
In our case we can live with this situation (at least it seems so, for now), because the core patch allows the decoupled front end to fetch the data directly from the backend based on the path without us writing any crazy magic. Time will tell.
Comment #11
badrange commentedOh, it looks like fetching the related via
&include=doesn't work either in this way. Or is it just me?Comment #12
gabesullice@badrange are you including
pathorpath.alias?Comment #13
dawehnerGiven that the path alias will never be stored in fieldapi I doubt we will ever have a chance to filter by it.
Comment #14
e0ipsoThis is a big bummer:
I suppose that client applications will have to do routing on some alternative custom field that contains the alias information. There is no way that a React app will have UUIDs in their URLs.
Does someone know a contrib that will maintain a textfield with the same contents of the alias?
Comment #15
e0ipsoClosing since it seems this won't be doable:
Comment #16
dubcanada commentedThis is a pretty big issue, not being able to filter content for a specific page doesn't allow you to do react based routing.
Your suggestion about maintaining a textfield with the path alias seems like it might work. But is there a way to fix this or make an exception (do filtering for paths differently) for path aliases?
In regards to the textfield, is the thought we would have a hidden textfield that maintains a copy of the path that gets updated upon entity save? Not sure how we would set it up to work for every entity...
Comment #17
gabesullice@dubcanada
My approach has been to create a "slug" property. I auto-generate it sort of like an html class, e.g., "My Node Title" becomes "my-node-title". The field should be unique (at least per entity type).
Instead of filtering on a full path, my front-end app's routes can be structured like so:
/article/{slug}Then, I can just filter by that slug property like so:
/jsonapi/node/article?filter[slug][value]=my-node-titleComment #18
e0ipsohttps://www.drupal.org/project/machine_name and https://www.drupal.org/project/safeword are relevant projects for that. However, they don't have a D8 release. Maybe that would be a good place to start.
Comment #19
spleshkaThis is interesting! The solution I considered as "internal workaround" turns out to be the only viable way to go :) Having this conversation read, I've published our internal module which maps "path" property to the field. Check out Fieldable Path. It still needs tests coverage and minor improvements for wider use cases, though "done is better than perfect".
Critics and feedback are welcome.
Comment #20
e0ipsoThanks again for the module @Spleshka!
Comment #21
bmx269 commentedAwesome module @Spleshka! Thanks
Comment #22
e0ipsoI think it can be really interesting to add `https://github.com/contentacms/snail` to the mix as well.
Comment #23
segovia94 commentedEven if we can't filter by it, it would still be helpful to return the path rather than just "null". For example, if I have a directory of people that another website is consuming, it would be good to have the node path so that when a person is clicked on in the list it will take them back to the correct page on the original site.
Comment #24
gabesullice@segovia94,
This should land "automatically" when #2392845: Add a trait to standardize handling of computed item lists lands in core. We support computed fields on entities already, it's just that the path field is not a "real" computed field yet.
Comment #25
rozh commented#2392845: Add a trait to standardize handling of computed item lists has landed, but I can't find a way to filter node by path.
Could you help me to construct request to get a node by path, if possible. Or Fieldable Path is still required for that kind of functionality?
Comment #26
e0ipsoWhy do you need to filter by path? 90% of the cases where you think you need to find content by alias what you want instead is http://dgo.to/decoupled_router
Comment #27
rozh commentedThank you e0ipso! This is perfect solution indeed.