TypeError: ::findEntityBundleWithField(): $entity_type_id must be of type string, null given

Created on 17 March 2025, 16 days ago

Problem/Motivation

We are getting an error when adding blocks. There is an error in the browser console, "An AJAX HTTP error occurred". Drupal logs have:

TypeError: Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase::findEntityBundleWithField(): Argument #1 ($entity_type_id) must be of type string, null given, called in …/ui_patterns/modules/ui_patterns_field_formatters/src/Plugin/Field/FieldFormatter/ComponentFormatterBase.php on line 223 in Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase->findEntityBundleWithField() (line 174 of …/ui_patterns/modules/ui_patterns_field_formatters/src/Plugin/Field/FieldFormatter/ComponentFormatterBase.php)

Steps to reproduce

In CKEditor, click on the Block button. When "Select content block to embed" appears, choose a block and click "Select blocks". Check the browser console and logs for error messages.

There may be things that are specific to our setup that cause this to happen. However, looking at the code, ComponentFormatterBase::findEntityBundleWithField() requires that its first param is a string. It is called in ::getComponentSourceContexts(). The first param comes from the return value of BaseFieldDefinition::getTargetEntityTypeId(). That function does not promise to always return a string. It may also return NULL, which is what is happening here.

Proposed resolution

Check for a NULL return from BaseFieldDefinition::getTargetEntityTypeId() and handle the case where the value is NULL.

Remaining tasks

Implement.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024