Problem/Motivation
EntityReferenceLabelFormatter properly checks if a user has "view label" entity access (only and not "view" access) but then it still renders a link to the entity's canonical page even if the user only has "view label" access (but not "view" access). When a user clicks on the link it gets a 403 page as they should.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3293287
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 #3
mxr576Comment #4
mxr576Probably
\Drupal\Tests\field\Kernel\EntityReference\EntityReferenceFormatterTest::testLabelFormatter()should be extended.Comment #7
chi commentedAuthorFormatter might have same bug.
Comment #8
mxr576It should not ... it is indirectly protected by
\template_preprocess_username()-->$variables['profile_access'] = $account->access('view');Comment #10
lukasss commentedComment #13
lukasss commentedComment #14
lukasss commentedComment #15
chi commentedI wonder if
$entity->toUrl()->access()is more appropriate here than$entity->access('view').Comment #18
lukasss commentedIf an entity type doesn't have any link templates.
We get: Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the 'entity_test_label' entity type
There is a test that checks this.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/field...
Comment #19
smustgrave commentedHave not yet review but issue summary appears to be incomplete. Bugs should contain steps to reproduce and proposed solution. If other sections don't apply N/A is fine.
Comment #20
chi commentedRe #18. It happens without this MR as well. Right?
Comment #21
lukasss commented@chi yes, that's right
Comment #22
kumudbThere is conflict on MR so I have implement code here, please update this on MR , below error is displaying on MR
Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.
To resolve the issue where the
EntityReferenceLabelFormatterimproperly renders links to entities when the user has "view label" access but not "view" access, we need to add an additional access check within theviewElements()function. Specifically, we should ensure that the link is rendered only if the user has both "view label" and "view" access to the entity.Key Changes Made
1. Added view label Access Check:
2. Added view Access Check for Links:
Testing the Changes
Scenario 1: User with Both "view label" and "view" Access
Scenario 2: User with Only "view label" Access
Scenario 3: User with No Access
Comment #25
lukasss commentedI think this issue can be closed.
Latest changes:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/media...