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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibran created an issue. See original summary.

jibran’s picture

Fixed minor copy paste error.

jibran’s picture

The last submitted patch, testCommentEntityIdEntityReferenceProperties.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: testCommentEntityIdEntityReferenceProperties-2.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
3.41 KB

:/

Status: Needs review » Needs work

The last submitted patch, 6: comment_entity_id_field-2558337-6.patch, failed testing.

jibran’s picture

Version: 8.1.x-dev » 8.0.x-dev

damn it.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: comment_entity_id_field-2558337-6.patch, failed testing.

jibran’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.24 KB
3.28 KB

Removed bogus asserts.

Status: Needs review » Needs work

The last submitted patch, 11: comment_entity_id_field-2558337-11.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
2.26 KB
3.11 KB

hmmm I realized I was checking the setting on a wrong thing. Fixed the test and it came back green so false alarm.

jibran’s picture

Status: Needs review » Closed (works as designed)

Sorry for the noise.