Skip to content

Error in EntityReferenceHandler when $label_key is FALSE #291

@khiminrm

Description

@khiminrm

There is error '' not found when trying to create entity with reference on entity which doesn't have defined label key in it's entity type e.g. commerce_license.

To fix this we can try to add condition and modify query:
foreach ((array) $values as $value) {
$query = \Drupal::entityQuery($entity_type_id);
if ($label_key) {
$or = $query->orConditionGroup();
$or->condition($id_key, $value)
->condition($label_key, $value);
$query->condition($or);
}
else {
$query->condition($id_key, $value);
}
$query->accessCheck(FALSE);
if ($target_bundles && $target_bundle_key) {
$query->condition($target_bundle_key, $target_bundles, 'IN');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions