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.

Error validation

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.

Issue fork drupal-3281934

Command icon 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

eduardo morales alberti’s picture

Status: Active » Needs review

Created MR to use the language as query metadata on access check

eduardo morales alberti’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This 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.

Version: 9.2.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

albeorte’s picture

Reroll to core 10.3.x

oily made their first commit to this issue’s fork.

oily changed the visibility of the branch 3281934-validation-reference-access-language to hidden.

oily changed the visibility of the branch 3281934-plugin-entityreference-default to hidden.

oily changed the visibility of the branch 3281934-plugin-entityreference-default-11.x to hidden.

oily changed the visibility of the branch 3281934-validation-reference-access-language to active.

oily changed the visibility of the branch 3281934-validation-reference-access-language to hidden.

oily changed the visibility of the branch 3281934-plugin-entityreference-default to active.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.