Closed (fixed)
Project:
JSON:API
Version:
8.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Mar 2017 at 16:56 UTC
Updated:
2 May 2017 at 07:45 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
e0ipsoI'm not sure I understand the question. Please be more specific. You should be able to see all the fields in the image entity via the image resource or using the includes.
Comment #3
grimreaperHello @eOipso,
Thanks for the quick reply.
Yes, I see the fields in the image entity but the problem is that the alt text is not stored in the image entity but in the field value on the article.
I will attached screenshots of what I obtain.
The node:
The value of the field image in the database:
jsonapi/node/article:
jsonapi/node/article with include:
jsonapi/node/article/uuid/field_image:
jsonapi/node/article/uuid/relationships/field_image:
I don't see the alt text anywhere. Am I missing something?
Do you need more details?
Thanks fot you reply.
Comment #4
e0ipsoThanks for the details!
Comment #5
dawehnerI also ran into the problem. As of now there seems to be now way to fetch it.
Comment #6
grimreaperHello,
Also for comment field type, there are some conf values in the "attributes" but nothing in the "relationships" to be able to get the comment.
Also I wonder if the "cid" and the "last_comment_uid" should be converted into the UUID of the entities.
Comment #7
edaa commentedBesides the alt text, the image width and height values are also useful.
Comment #8
grimreaperHello,
I discussed about this issue with @Wim Leers.
In a first time for image fields only, a strategy would be to look at the classes:
- jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php
- jsonapi/src/Normalizer/Relationship.php
- jsonapi/src/Normalizer/RelationshipItem.php
And to see how and if we need, to create sub-classes to add the extra information in the relationship.
@eOipso: Are you ok with this strategy?
Comment #9
e0ipsoThat seems reasonable. There can be dedicated normalizers for this.
Comment #10
grimreaperHello,
Here is a first attempt.
It adds the additionnal properties into a meta in the relationship value, as you can see on the attached screenshot.
It breaks the tests and I want some feedback before to continue working on this issue.
I worked with beram (https://www.drupal.org/u/beram).
Also, we put some TODO where we had interrogations?
Thanks for the review.
Comment #11
dawehnerI think its fine to skip computed fields for now. Computed fields adds its own complexity.
Conceptually I think that is its own complexity, maybe a submodule of ERR would be good on tp.
I guess you should check for
\Drupal\Core\Access\AccessibleInterfacefor each property here, but core doesn't do it, nor there are properties which have that.Comment #12
dawehnerI started with some additional test coverage.
Comment #14
grimreaperThanks @dawehner
Here is a quick review.
Should be removed? :)
$normalized['data']['relationships']['field_image']['data']['meta'] instead?
Comment #15
dawehner@Grimreaper
Oh yeah good point. I just wanted to put out some test ...
Comment #16
grimreaper@Dawehner no problem :)
I am currently using your test to test my previous patch. Trying to have as much green as possible.
Comment #17
grimreaperHere is the patch that fix @dawehner test and put it into green.
But I still get the failures from patch in comment 10.
It will need to investigate.
Comment #18
grimreaperI forgot to change to needs review to trigger the test bot...
Comment #20
grimreaperI think I found a way to fix the tests.
I will upload a patch soon.
Comment #21
grimreaperHere is the patch.
Comment #22
grimreaperTests are green \o/
Is it possible to have feedbacks to know if this approach will be merged?
After an image field, should we also test a file field?
Comment #23
e0ipsoI like what I am seeing from a code perspective. A couple of comments:
Can we use
getReferencedEntities()instead?Nit. Use
[]instead ofarray(). (applies to other places as well)What is the reasoning behind adding this? Would it make more sense to pass the UUID around under a static
'target_uuid'key that we can expect during "rasterization"?Comment #24
e0ipsoHowever I am not convinced that companion properties to a relationship are metadata at all. They are first class content, and they should be treated as such.
I did a bunch of research as part of this issue and found some relevant threads.
I believe that ultimately it all boils down to an architectural problem derived from the 1-to-1 mapping of resource and bundles. If that was not a limitation we could consider doing:
As of now, that is not possible so I believe that meta on the relationship is the best we can do for now.
Comment #25
e0ipsoI don't think that is the case. If a module (even if it is core) wants to store some normalized data for performance reasons, we should not transform it in any way. We should only turn references into their UUID when they are declared as entity relationships explicitly.
Comment #26
dawehnerWell, not really, because the entities don't contain the metadata we want here.
This is indeed a much nicer solution ...
Comment #28
dawehnerOne underscore too much.
Comment #29
e0ipsoAdded some minor modifications. Merging if green.
Comment #31
e0ipsoComment #32
grimreaperHello,
Thanks @dawehner for completing the patch.
Thanks @e0ipso for the merge and the search in JSONAPI.