Problem/Motivation
A client reported that some field values weren't showing up on the preview link of a node.
The node is published, and the content being referenced is also published. The field is rendered using core's EntityReferenceLabelFormatter.
Debugging into it, preview_link_entity_access is returning forbidden for the referenced node because the tokens do not match.
This would only happen when the referenced entity also has a preview link entity, since PreviewLinkAccessCheck::access returns early when there isn't one.
This should be pretty easy to write a failing test for, the solution might be a bit more involved though.
Proposed resolution
Check the entity id from the route match against the entity passed into preview_link_entity_access and return neutral if they don't match?
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3117258-19.patch | 4.24 KB | acbramley |
Issue fork preview_link-3117258
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
acbramley commentedHere's a potential fix and a test which should be failing for the test-only version but for some reason it's not. Running an identical workflow in a test environment does correctly fail so I'm not too sure what's going on there, maybe some weird caching or something?
Comment #3
jibranI wish core should provide an API for this. Here is another issue #3047936: Generic support for any entity type where we wanted to do the same
Comment #4
acbramley commented@jibran agreed, there's a few modules that would benefit from this.
Comment #5
jibranAlso, see the discussion after #18 in #2847224: Add views argument_default for getting Entity ID from URL.
Comment #6
acbramley commented#2 was throwing 500s for some users on revision routes. It's interesting that this module's access hook even runs on non-preview link routes but that's a separate issue.
FYI: The test still needs work.
Comment #7
dpiThis should probably get the route optionpreview_link.entity_type_id, similar toPreviewLinkController::resolveEntity, instead of iterating parameters.edit: See below
Comment #8
dpi301 #3138465: Add a generic entity route context
--
Uploaded reroll + 7 feedback
Comment #9
dpiActually I think I may have gotten the intent of the change wrong :/ In which case a new test is necessary.
Comment #10
dpiJust the reroll
Comment #11
dpiMaking a list of issues which would find service outlined in #3138465: Add a generic entity route context useful.
Comment #12
acbramley commentedComment #13
sam152 commentedCould simplify with the following?
What if two different entity types have the same ID?
neutralon preview link route A andallowedon preview link route B is fine because they are two different routes?Still not completely sure, it's a bit mind bending...
Comment #14
sam152 commentedAlso failing to apply.
Comment #16
suresh prabhu parkala commentedJust a re-roll.
Comment #18
acbramley commentedComment #19
acbramley commentedComment #20
dpiThe calls out to routematch in an access always scare me so much, considering history in this project. So long as we have coverage should be alright.
CI reports a minor CS error.
For caution sake, can we make sure we tag this as a non stable release (alpha/beta/RC) and have it get a little bit of usage before we release it widely.
Comment #22
acbramley commentedThanks! Fixed CS on commit.