Better support for subfields

Created on 14 April 2023, about 1 year ago
Updated 15 November 2023, 7 months ago

Problem/Motivation

It should be possible to do an entity lookup on sub-fields using value_key: field_name.subfield.

In my particular example, but it might be valid for others too, I have the media field field_bridtv (from module bridtv β†’ ) and want to do an entity lookup on video_id, to get the target_id of the media entity (as all related media already exist, imported by the module and not by a migration).

The process part looks like:

field_bridtv_reference:
  - plugin: skip_on_empty
    method: process
    source: field_bridtv_reference
  - plugin: sub_process
    process:
      target_id:
        - plugin: entity_lookup
          source: field_bridtv_video_id
          entity_type: media
          bundle: bridtv
          value_key: field_bridtv.video_id

Looking at the result in \Drupal\migrate_plus\Plugin\migrate\process\EntityLookup::query() looks good, but then it fails on $entity->get($this->lookupValueKey), due to ContentEntityBase.php line 587, saying:

Field field_bridtv.video_id is unknown.

Steps to reproduce

I guess it could be reproduced with any field that has subfields.

Proposed resolution

The problem is with $entity->get($this->lookupValueKey), which in above example would be the same as $entity->get('field_bridtv.video_id'). That does not work, instead it might look like $entity->get('field_bridtv')->video_id.

Workaround

It might already work for many cases, setting ignore_case: true. That way the code block resulting in the error won't be executed.

✨ Feature request
Status

Active

Version

6.0

Component

Plugins

Created by

πŸ‡©πŸ‡ͺGermany osopolar πŸ‡©πŸ‡ͺ GER 🌐

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

Comments & Activities

  • Issue created by @osopolar
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I just ran into this trying to do an entity_lookup against part of an address field. The ignore_case workaround worked for me. It would be nice to come up with a robust solution, but I'm very pleased that @osopolar posted that workaround. Thanks!

Production build 0.69.0 2024