There's no point in having this in entity_lookup AFAICT.

If you're detecting the entity type and bundle from the field, then you ask the entity type manager service for the bundle key:

            $this->lookupBundleKey = $this->lookupBundleKey ?: $this->entityManager->getDefinition($this->lookupEntityType)->getKey('bundle');

But if the developer specifies the entity type and bundle in the configuration, the bundle key can ALSO be obtained from the entity type manager! There is no other value the bundle key can be, it's entirely determined by the entity type.

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

joachim created an issue. See original summary.

joachim’s picture

(Don't remove lookupValueKey though -- that's really useful for looking up entities by another field than their title!)

marvil07’s picture

joachim’s picture

Status: Active » Needs review
matroskeen’s picture

Title: bundle_key configuration for entity_lookup process plugin isn't necessary » [PP-1] bundle_key configuration for entity_lookup process plugin isn't necessary
Status: Needs review » Postponed

It looks good to me, and I would be happy to commit this change after we land #2787219: Entity lookup plugin not able to guess config for entity types without bundle, which introduces more test coverage for the plugin. I'll mark it as Postponed for now.

mpp’s picture

Atm the bundle_key is marked optional but when not passing it, under certain circumstances, the lookup isn't filtered for the proper bundle.

The following will result in a lookup on all bundles (not just the article):

  field_reference/target_id:
    plugin: default_entity_value
    entity_type: node
    bundle: article
    value_key: title
    access_check: false
    ignore_case: true
    default_value: mytitle

I had to explicitly add bundle_key: type to fix it.

thtas’s picture

Yes this can create some nasty bugs.

We ended up associating terms from the wrong vocabulary because the documentation isn't clear that you both bundle AND bundle_key are required, it just says:

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

This implies that both are optional and makes no mention that `bundle` is useless without `bundle_key`.

ressa’s picture

Version: 8.x-4.x-dev » 6.0.x-dev

I also saw this, where I was using a most basic set up of only entity_generate (same configuration as entity_lookup) based on the doc page Contrib process plugin: entity_generate (since updated), but had to supply a lot more configuration to make it work, as in comment #7. See #2787219-30: Entity lookup plugin not able to guess config for entity types without bundle.