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.
Issue fork ui_patterns-3513546
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
Comment #2
just_like_good_vibesComment #4
just_like_good_vibesHello, thank you for reporting.
When i read for example FieldDefinitionInterface in drupal core, in the comments :
"Returns the ID of the entity type the field is attached to.", "@return string".
But it is not in the signature, only in the comments.
That sounds like a very odd and strange case, where a field formatter would not have an entity_type_id to which it is attached.
i tried to patch the function and treat the case of entity_type_id being null, but my guess is that something else won't work at another place.
please review
Comment #5
liam morlandThis patch fixed the problem for us. Thanks!
Comment #6
just_like_good_vibesthanks, i will merge
Comment #8
just_like_good_vibes