EntityReferenceQueryDeriver::getDerivativeDefinitions() may return Undefined array key warning during config import

Created on 24 September 2024, 3 months ago

Problem/Motivation

We have error like Undefined array key "field_dummy_name" EntityReferenceQueryDeriver.php:100. when we try to import configuration containing:

  1. In our case new paragraph type having field field_dummy_name
  2. New external entity type

Error occurs, because EntityReferenceQueryDeriver::getDerivativeDefinitions() is called on new external entity type save (by ExternalEntityType::postSave()).

Steps to reproduce

Try to import configuration having:

  1. New paragraph type, e.g. paragraphs.paragraphs_type.dummy_paragraph_type
  2. Field inside paragraph, e.g. field_dummy_name
  3. New external entity type, e.g. external_entities.external_entity_type.dummy_external_entity_type

So... in our case, what happened during import:

  1. paragraphs.paragraphs_type.dummy_paragraph_type.yml imported
  2. field.storage.paragraph.field_dummy_field_name.yml imported
  3. During external_entities.external_entity_type.dummy_external_entity_type import error occured, because it was imported earlier than field.field.paragraph.dummy_paragraph_type.field_dummy_name.yml

Proposed resolution

What we can do, we can modify EntityReferenceQueryDeriver::getDerivativeDefinitions() from:

if ($fieldDefinition instanceof BaseFieldDefinition || !$entityType->hasKey('bundle')) {
          $parents = [StringHelper::camelCase($entityTypeId)];
        }
        else {
          $parents = [];
          foreach ($fieldMap[$entityTypeId][$fieldName]['bundles'] as $bundle) {
            $parents[] = StringHelper::camelCase($entityTypeId . '_' . $bundle);
          }
        }

to:

$parents = [];
        if ($fieldDefinition instanceof BaseFieldDefinition || !$entityType->hasKey('bundle')) {
          $parents = [StringHelper::camelCase($entityTypeId)];
        }
        elseif (isset($fieldMap[$entityTypeId][$fieldName])) {
          foreach ($fieldMap[$entityTypeId][$fieldName]['bundles'] as $bundle) {
            $parents[] = StringHelper::camelCase($entityTypeId . '_' . $bundle);
          }
        }
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇱Poland gugalamaciek

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

Comments & Activities

Production build 0.71.5 2024