Problem/Motivation
The first problem that we found with node grants was that when it insert the records on the database, it does not take into account the translations. It is solved on NodeAccessControlHandler::acquireGrants() does not consider translations with different published states
After apply the pach of the issue, now the "node_access" records have sense.
However, if we have a node with an entity reference field that is translatable, and we need to reference a node that matches the current translation but has the original/default language unpublished, the ValidReferenceConstraintValidator.php validate method does not check the translation. Instead, it is evaluating the original language, so the constraint is not met and an exception is thrown.

After some testing and debugging we found that the method buildEntityQuery from DefaultSelection.php does not take into account the language. To work properly, it should add the language metadata as it's said on Language support added to node access grants and records
Steps to reproduce
It was tested on a Drupal 9.2.13 after a site install following the next steps:
- The module content_translation should be enabled
- Also the hook_node_grants should be implemented (could be empty) to use the node_access logic
- Add some languages to the site
- Make a content translatable
- Apply the patch of the issue NodeAccessControlHandler::acquireGrants() does not consider translations with different published states
- Add to a translatable content a field reference
- Create a content and a translation, for example, default language en, translation es and unplish the defaul language en
- Reference the content created to another content with the translation en
- The error "This entity (node: [NID]) cannot be referenced." will be triggered
Proposed resolution
Patch buildEntityQuery from DefaultSelection.php to get the language from the entity and add the langcode metadata.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | core-default_selection_access_validation-issue_3281934-7.patch | 1.41 KB | albeorte |
| validation_reference.png | 31.7 KB | eduardo morales alberti |
Issue fork drupal-3281934
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
eduardo morales albertiCreated MR to use the language as query metadata on access check
Comment #4
eduardo morales albertiComment #5
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
This will need a test case showing the issue.
Comment #7
albeorte commentedReroll to core 10.3.x