Entity lookup plugin not able to guess config for entity types without bundle

Created on 19 August 2016, over 8 years ago
Updated 7 August 2024, 7 months ago

I was trying the minimal configuration for an entity_lookup process plugin on a user entity but the migration failed wit ha message "The entity_lookup plugin requires a value_key, none located."

I debugged a bit and I found that the bundle is empty for user entitie when you try to get it with $this->entityManager->getDefinition($this->destinationEntityType)->getKey('bundle');

So is not available on when you do $this->destinationBundleKey
http://cgit.drupalcode.org/migrate_plus/tree/src/Plugin/migrate/process/...

πŸ› Bug report
Status

Needs work

Version

5.0

Component

Plugins

Created by

πŸ‡ͺπŸ‡ΈSpain rodrigoaguilera Barcelona

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    I had similar problem where I wanted to reference a regular field. I was able to do with the following patch and config:

      _check_migrated:
        - 
          plugin: entity_lookup
          source: '@_processed_link'
          access_check: false
          value_key: field_web_link.uri #required
          bundle: feed_item #required
          bundle_key: field_web_link.uri #required
          entity_type: node #required
          ignore_case: true
          # destination_field: field_web_link
        - 
          plugin: skip_on_value
          value: null
          not_equals: true
          method: row
          message: Do I really want to flood my logs?
    

    The important field is value_key. I think bundle, bundle_key and entity_type are irrelevant but necessary for entity_lookup to function

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Actually please ignore my previous comment. Turns out I had not configured the value key correctly.

    Here is a working example that checks if an source or processed uri has already been imported, and if so we can choose to skip the row if the value returned !== null. NULL is returned if there is no matching field_web_link_url on a node entity_type bundle aka 'feed_item" content type.

    source
      _check_migrated:
        - 
          plugin: entity_lookup
          source: '@_processed_link'
          access_check: false
          value_key: field_web_link.uri #required -  note use of  dot notation as mentioned <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/function/QueryInterface%3A%3Acondition/11.x">here</a>. This will actually map to field_web_link_uri column on the node__field_web_link table
          bundle: feed_item #required - for node this is the content type
          bundle_key: type #required - e.g. <code>Drupal::entityTypeManager()->getStorage('node')->getEntityType()->getKey('bundle')

    entity_type: node #required - entity type id
    ignore_case: true
    -
    plugin: skip_on_value
    value: null
    not_equals: true
    method: row
    message: Row skipped because uri already exists

  • heddn Nicaragua

    Failing tests after a rebase.

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

    I recently tried a very minimal migration, using only entity_generate (Note, not entity_lookup plugin) and source, which didn't work, even though all properties are labelled "optional" ...

    I am sharing it here, since at it says in the entity_generate code, that it shares properties with entity_lookup:

    * All the configuration from the lookup plugin applies here. In its most
    * simple form, this plugin needs no configuration. If there are fields on the
    * generated entity that are required or need some value, their values can be
    * provided via values and/or default_values configuration options.

    From https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...

    From the entity_lookup configuration documentation:

    * Available configuration keys:
    * - entity_type: (optional) The ID of the entity type to query for.
    * - value_key: (optional) The name of the entity field on which the source
    * value will be queried. If omitted, defaults to one of the following
    * depending on the destination field type:
    * - entity_reference: The entity label key.
    * - file: The uri field.
    * - image: The uri field.
    * - operator: (optional) The comparison operator supported by entity query:
    * See \Drupal\Core\Entity\Query\QueryInterface::condition() for available
    * values. Defaults to '=' for scalar values and 'IN' for arrays.
    * - bundle_key: (optional) The name of the bundle field on the entity type
    * being queried.
    * - bundle: (optional) The value to query for the bundle - can be a string or
    * an array.
    * - access_check: (optional) Indicates if access to the entity for this user
    * will be checked. Default is true.
    * - ignore_case: (optional) Whether to ignore case in the query. Defaults to
    * false, meaning the query is case-sensitive by default. Works only with
    * strict operators: '=' and 'IN'.
    * - destination_field: (optional) If specified, and if the plugin's source
    * value is an array, the result array's items will be themselves arrays of
    * the form [destination_field => ENTITY_ID].

    https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...

    Only after setting the values below as well, did my import not return "Failed" (and without saying why):

    process:
      field_library:
        plugin: entity_lookup
        source: library
        value_key: title
        bundle: article
        entity_type: node

    I updated the existing entity_generate doc page (it had a very basic, failing example I mentioned in the beginning) and created a new doc page for entity_lookup, where I also included the great answers and question in comments #7 to #12, thanks @james.williams amd @tnfno!

Production build 0.71.5 2024