protected static function getCommentAccessCondition(EntityTypeInterface
$comment_entity_type, AccountInterface
$current_user, CacheableMetadata
$cacheability,
$depth = 1
) { // If a comment is assigned to another entity or author the cache needs to
// be invalidated.
$cacheability->
addCacheTags($comment_entity_type->
getListCacheTags());
// Constructs a big EntityConditionGroup which will filter comments based on
// the current user's access to the entities on which each comment lives.
// This is especially complex because comments of different bundles can
// live on entities of different entity types.
$comment_entity_type_id =
$comment_entity_type->
id();
$field_map =
static::
$fieldManager->
getFieldMapByFieldType('entity_reference'
);
assert(isset($field_map[$comment_entity_type_id]['entity_id'
]['bundles'
]), 'Every comment has an `entity_id` field.'
);
$bundle_ids_by_target_entity_type_id =
[];
foreach ($field_map[$comment_entity_type_id]['entity_id'
]['bundles'
] as $bundle_id) { $field_definitions =
static::
$fieldManager->
getFieldDefinitions($comment_entity_type_id,
$bundle_id);
$commented_entity_field_definition =
$field_definitions['entity_id'
];
// Each commented entity field definition has a setting which indicates
// the entity type of the commented entity reference field. This differs
// per bundle.
$target_entity_type_id =
$commented_entity_field_definition->
getSetting('target_type'
);
$bundle_ids_by_target_entity_type_id[$target_entity_type_id][] =
$bundle_id;
}