Closed (won't fix)
Project:
Drupal core
Version:
8.5.x-dev
Component:
taxonomy.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Nov 2017 at 22:37 UTC
Updated:
29 Jan 2018 at 09:11 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
amateescu commentedHere's a patch which makes the field computed and includes the logic for getting the term's parent. The patch depends on #2392845: Add a trait to standardize handling of computed item lists so I'm posting a combined patch as well.
The interdiff contains only the changes that were made to the tests from #2543726-200: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration.
Comment #3
amateescu commentedOn second thought, the field doesn't necessarily have to be computed if it wants to implement the trait.
Comment #8
amateescu commentedThis should do it.
Comment #10
amateescu commentedSigh.. this should be green.
Comment #11
amateescu commentedCleaned up a couple of things from my review in #2543726-201: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration.
Comment #12
wim leersThis looks nice! 👏
Except for one thing:
This is wrong, this is only adding
_linksand_embedded(hal_jsonformat) or a non-emptyparentfield (jsonformat) for$term->parentif and only if the parent is not<root>(or term zero).We need those to be always present, otherwise API clients would have to hardcode that logic themselves. We want to be explicit about the fact that a term doesn't have a parent.
#2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration gets this right.
Comment #13
amateescu commentedActually, I think that this patch does the right thing, IMO. Adding
_linksand_embeddedor aparentreference to an entity with the ID 0 means (logically) that there is a resource with the ID 0 that can be requested via a REST call. Otherwise, we're just putting the burden on API clients to *know* that 0 is a special resource ID which means<root>.The approach of this patch is to not send any details about a parent resource for root terms, with the logic being explained by "there is no parent therefore this term is at the root level".
However, after writing the two paragraphs above, I just realized that there is a flaw in my explanation, which is the multi-parent architecture of taxonomy terms. Since the root level is not explicitly determined by a "magic" ID, there is no way for a REST POST request to say: make this term a root-level one as well as a child of term X. Or for a REST GET request to know whether a term with a parent of Y is also a root term.
Do you happen to know of any examples of REST API's dealing with a multi-parent hierarchy resource like we have here?
The answer might very well be that we need to keep the magic
<root> = 0assumption that we have in #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration, but I just want to be sure there's no other better way for it.Comment #14
wim leersI strongly disagree. This patch causes the normalizations/API responses to communicate information implicitly rather than explicitly, which can lead to misinterpretations, and requires all API clients to build in this understanding.
In #2543726-205: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration the
_linksand_embeddedentries look like this when the parent term is the root term (term zero):The absence of a URL explicitly communicates that there is no parent resource to request.
This is a very good point, and something we're missing test coverage for. Working to add that… stay tuned.
Comment #15
wim leersAdded that multi-parent test coverage at #2543726-216: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration — now you can inherit it here.
Not immediately, no.
I think so, yes.
Comment #16
amateescu commentedIt would be nice if you could read the entire comment before disagreeing so strongly..
Comment #17
wim leers(Typing on my phone from 🏓 competition.)
Huh? :( I really did not intend to upset you! I did read everything you wrote, and I tried to constructively explain why I disagree. The explicit versus implicit.
EDIT: oh, I see, I think you mean that you ended up kind of agreeing with me, yet my comment still answers part of your comment before you agreed. You’re right. I should’ve edited that away. It’s just how I gradually answer a comment, and if I switched tasks in between I sometimes forget to go back and re-read and revise the entire comment. My apologies!
Comment #18
amateescu commentedIt seems that we don't want to fix this bug in 8.4.x and we're only doing #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration for 8.5.x.
Comment #19
jibranNOw that we are not going to backport #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration to 8.5x. Can we consider this patch for 8.5.x?
Comment #20
wim leers@jibran: yes, indeed, and @amateescu asked the same question at #2543726-341: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration. We'll have to be VERY careful to ensure it behaves exactly the same though. We'd need this to work exactly the same as 8.6.
Marking NW because #11 does not include the same test coverage that #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration committed to 8.6.
Comment #21
wim leersJust chatted with @damainkloip about this.
We agreed that it's probably better to not try to land this issue in Drupal 8.5, because:
$term->parentto work!Comment #22
amateescu commented#21 seems to imply that this issue will introduce a custom normalizer, but that's not what this patch does. It simply provides an item list class for the
parentfield which makes its value available to the "outside world", including every other component from the API-first ecosystem (JSON API, GraphQL, whatever..)Since all the arguments "against" from #21 are about a non-existing thing.. sounds like you need to chat about it again :)
Comment #23
damiankloip commentedIndeed - this patch does not add a normalizer of any kind.. yet. I think we were thinking that if we add this, we would need to also add a normalizer (or change how the new list class handles the computed items for no parent) to return values for the parent = 0 case. The patch would currently just return an empty array instead of a value of 0. Which is different to the new behaviour in #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration.
Otherwise, we shoot ourselves in the foot a little bit and make an additional API BC break for ourselves, if we're not careful.
Thoughts? :)