Entity lookup doesn't work with multiligual content

Created on 8 August 2021, over 3 years ago
Updated 21 November 2024, 4 months ago

Problem/Motivation

When looking for entities, entity lookup only loads the default translation content.
Therefore if you're looking to target a content by one of its translated field, the plugin won't find anything.

Steps to reproduce

Setup a Drupal site with French and English languages.
Create an article node with title "ChΓ’teau" then translate it in "Castle".
Create a migration using this template:

source:
  ...
  constants:
    search_title: 'Castle'
process:
  find_node:
    plugin: entity_lookup
    entity_type: node
    bundle_key: type
    bundle: article
    value_key: title
    source: constants/search_title

When you run it find_node will be false.

Proposed resolution

It seems that in EntityLookup:query() we only retrieve the original content through this code :

  $entity = $this->entityTypeManager->getStorage($this->lookupEntityType)->load($identifier);

So this should be updated using a langcode parameter.

πŸ› Bug report
Status

Needs work

Version

5.0

Component

Plugins

Created by

πŸ‡«πŸ‡·France tostinni

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    jsutta β†’ changed the visibility of the branch 3227245-entity-lookup-doesnt to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    jsutta β†’ changed the visibility of the branch 3227245-entity-lookup-doesnt to active.

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    We've been maintaining a local copy of this patch, updating it periodically when updates are released.

    I tried to update the issue's MR to target the 6.0.x branch and rebase it, but couldn't change the target branch. Probably for the best in case others are using it. That being the case, I tried to create a new feature branch based on 6.0.x, but only the branches available in the fork are available to base the branch on. If anyone knows how to bring 6.0.x into the fork, or create a new fork in this same issue, please let me know and I'm happy to do the work. I've attached a patch that installs with the latest release (6.0.5).

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Changing to latest version 6.x, to create a fresh MR.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I get the message below, after trying to create a new version 6 branch. Someone probably needs to do a local Git update, to allow creating an MR against version 6:

    Failed to create branch '3227245-3227245-entity-lookup-doesnt-v6': invalid reference name '6.0.x'

    See also https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr... β†’

Production build 0.71.5 2024