Plugin EntityReference Default Selection does not take into account the language on buildEntityQuery

Created on 23 May 2022, over 2 years ago
Updated 12 September 2024, 4 months ago

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 πŸ› NodeAccessControlHandler::acquireGrants() does not consider translations with different published states Needs work
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 πŸ› NodeAccessControlHandler::acquireGrants() does not consider translations with different published states Needs work
  • 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.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 16 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024