Closed (duplicate)
Project:
JSON:API
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
1 Mar 2018 at 11:06 UTC
Updated:
30 May 2018 at 14:13 UTC
Jump to comment: Most recent
\Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer::normalize() constructs a Relationship object and then normalizes that\Drupal\jsonapi\Normalizer\RelationshipNormalizer::normalize() then does the actual normalizationRelationship object is only ever created by EntityReferenceFieldNormalizer::normalize()and…
\Drupal\jsonapi\Normalizer\RelationshipNormalizer::denormalize() throws an exception: it doesn't support denormalization\Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer::denormalize() does the actual denormalizationThis makes for a very hard to understand architecture. Even though I think the intent was laudable: AFAICT the intent was to model the Relationship value object after the "relationship" described by the JSON API spec. So having a value object for that of course would make things simpler to understand.
This just doesn't seem to have worked out in practice.
It seems that at this point, it'd be simpler to merge RelationshipNormalizer into EntityReferenceFieldNormalizer. We can still keep the Relationship(Item)NormalizerValue value objects though!
Comments
Comment #2
wim leersSee #2940342-45: Cacheability metadata on an entity fields' properties is lost.
Comment #3
e0ipso@Wim Leers the relationship objects where introduced in order to accomodate for non EntityReference relationships.
AFAIK there is still value in that. Even though we are not taking advantage of it yet, we may want to have autocomputed relationships (for instance reverse relationships, relationships to the entity type config entity, …).
Is this a feature we want to stop supporting? (or rather ban that from our future, since we don't support them now).
Comment #4
gabesulliceAFAICT, there's no "feature" there right now. Just an architectural "opening" for the future. Is that right?
I would be vehemently opposed to "banning" it from our future though. I absolutely think this will only become more necessary in the medium to long term of future Drupal development.
If we want to remove it for now, I would be indifferent, but I'm fairly certain we will be adding it back in sometime in the future (though I can't say if it will be in 2 months or 24).
Comment #5
wim leersI wrote:
Emphasis added just now.
I agree it's a good idea in principle. But right now, it's causing more confusion than anything. Even more so because:
i.e. right now the very fact that this level of indirection/point of abstraction is incomplete is dangerous in that we could easily mislead ourselves.
Also, just like , I'd like to say .
I've learned the hard way in core that one should only ever add layers of abstraction when there's >=2 consumers. Fortunately, this is marked
@internal, so at least we're doing better than core in that respect :)Summarized:
Comment #6
e0ipsoYes. Sorry for the weird wording.
That's the reason why I don't want to remove it.
Comment #7
wim leersI don't understand why you wouldn't want to remove an abstraction that is clearly incomplete and has only a single consumer. Why are you opposed to reintroducing it in the future, when there is a better understanding of how this should work, because there would be >=2 consumers?
Comment #8
wim leersTurns out the confusion described in the issue summary of this issue actually ended up causing problems: see #2955615-11: Field properties are not being denormalized. Don't worry, no seismic shifts in functionality. Only moving logic from one normalizer to another! And in doing so, this actually is untangled. At least, untangled enough.
That patch is currently RTBC. Once that lands, there will be nothing left to untangle. The discussion in this issue was trending towards bigger architecture/elegance questions. Which are nice questions to dig into, and ambitions to aspire to, but they're not essential. So, closing this issue.