Problem/Motivation
After going through the following issues
- https://www.drupal.org/project/paragraphs_table/issues/3441247
- https://www.drupal.org/project/field_formatter/issues/3426834
and then debugging, led to the discovery that EntityReferenceFormatterBase class does not load the proper revision based on the revision of the entity where it the reference field lies.
It loads the default revision of the entity which is referenced, rather than loading the revision based on the revision of the entity it is attached to.
Steps to reproduce
Follow the steps mentioned in the description of https://www.drupal.org/project/paragraphs_table/issues/3441247.
Proposed resolution
In EntityReferenceFormatterBase::prepareView() load the proper revision of the entity which is referenced.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3442267-ent-ref-rev.patch | 1.59 KB | dale42 |
Issue fork drupal-3442267
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
vivek panicker commentedComment #4
vivek panicker commentedComment #5
smustgrave commentedThank you for reporting. Appears to have test failures and will need test coverage
Comment #6
vivek panicker commented@smustgrave can you please explain a bit more on what all is necessary now?
I can then give it a try.
Comment #7
dale42This issue causes the display of invalid information on the Content Moderation "Latest version" tab. Specifically, it does not actually display the data from the latest version, it displays information from the default/published version. Adding the "content moderation" issue tag.
After reading the description of priorities I believe it qualifies a Major, as it is displaying incorrect data.
Comment #8
dale42target_revision_id does not appear on every item. I expect this is why the tests are failing.
I have an alternative solution, also attached as a file, that is solving the issue on my system. I don't believe this is the best solution, but I think it will advance discussion on the issue.
$item sometimes has a target_revision_id and sometimes not. This code uses the target_revision_id if available, and falls back to target_id when it isn't. According to the comments "multiple entity load" should be used, so this was used to load the revised version.
Perhaps all items should have a target_revision_id so that all the entities could be loaded by revision id? This would work even if revisions were not enabled, since every entity has a revision id. This would require an upstream change to what ever is producing $item.
There is also EntityReferenceRevisionsFormatterBase. I'm not sure where it fits in the picture.
Comment #9
dale42Sorry, did not mean to remove the "Needs tests" tag. Re-adding.