Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In Comment::baseFieldDefinitions()
$fields['entity_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Entity ID'))
->setDescription(t('The ID of the entity of which this comment is a reply.'))
->setRequired(TRUE);
See there is no ->setSetting('target_type', '??')
because it is set when the comment bundle(CommentType) is defined in Comment::bundleFieldDefinitions()
if ($comment_type = CommentType::load($bundle)) {
$fields['entity_id'] = clone $base_field_definitions['entity_id'];
$fields['entity_id']->setSetting('target_type', $comment_type->getTargetEntityTypeId());
return $fields;
}
Because of this when comment is created $comment = Comment::create([]);
the target_type
setting for entity_id
field is not set.
This makes rendering of $comment->entity_id
impossible using ER formatter.
Proposed resolution
Don't know yet
Remaining tasks
Don't know yet
User interface changes
None
API changes
None
Data model changes
Don't know yet
Comment | File | Size | Author |
---|---|---|---|
#13 | comment_entity_id_field-2558337-13.patch | 3.11 KB | jibran |
Comments
Comment #2
jibranFixed minor copy paste error.
Comment #3
jibran#2346347: Finalize API for creating, overriding, and altering code-defined bundle fields seems related.
Comment #6
jibran:/
Comment #8
jibrandamn it.
Comment #11
jibranRemoved bogus asserts.
Comment #13
jibranhmmm I realized I was checking the setting on a wrong thing. Fixed the test and it came back green so false alarm.
Comment #14
jibranSorry for the noise.