// Historically, comments were always linked to 'node' entities, but that is
// no longer the case, as the 'node' module might not even be enabled.
// Comments can now be linked to any entity and they can also be referenced
// by other entities, so we won't have a single table to join to. That
// actually means that we can no longer optimize the query on those cases.
// However, the most common case remains to be comment replies, and in this
// case, we can get the host entity type if the 'entity' value is present
// and perform the extra joins and alterations needed.
$comment =
$this->
getConfiguration()['entity'
];
if ($comment instanceof CommentInterface
) { $host_entity_type_id =
$comment->
getCommentedEntityTypeId();
/** @var \Drupal\Core\Entity\EntityTypeInterface $host_entity_type */
$host_entity_type =
$this->entityTypeManager->
getDefinition($host_entity_type_id);
$host_entity_field_data_table =
$host_entity_type->
getDataTable();
// Not all entities have a data table, so check first.
if ($host_entity_field_data_table) { $id_key =
$host_entity_type->
getKey('id'
);
// The Comment module doesn't implement per-comment access, so it
// checks instead that the user has access to the host entity.