class CommentStatistics implements CommentStatisticsInterface (View source)

Properties

protected Connection $database

The current database connection.

protected Connection $databaseReplica

The replica database connection.

protected AccountInterface $currentUser

The current logged in user.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected StateInterface $state

The state service.

Methods

__construct(Connection $database, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, StateInterface $state, Connection $database_replica = NULL)

Constructs the CommentStatistics service.

object[]
read(EntityInterface[] $entities, string $entity_type, bool $accurate = TRUE)

Read comment statistics records for an array of entities.

delete(EntityInterface $entity)

Delete comment statistics records for an entity.

create(FieldableEntityInterface $entity, array $fields)

Insert an empty record for the given entity.

int
getMaximumCount(string $entity_type)

Find the maximum number of comments for the given entity type.

array
getRankingInfo()

Returns an array of ranking information for hook_ranking().

update(CommentInterface $comment)

Update or insert comment statistics records after a comment is added.

Details

__construct(Connection $database, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, StateInterface $state, Connection $database_replica = NULL)

Constructs the CommentStatistics service.

Parameters

Connection $database

The active database connection.

AccountInterface $current_user

The current logged in user.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

StateInterface $state

The state service.

Connection $database_replica

(Optional) the replica database connection.

object[] read(EntityInterface[] $entities, string $entity_type, bool $accurate = TRUE)

Read comment statistics records for an array of entities.

Parameters

EntityInterface[] $entities

Array of entities on which commenting is enabled, keyed by id

string $entity_type

The entity type of the passed entities.

bool $accurate

(optional) Indicates if results must be completely up to date. If set to FALSE, a replica database will used if available. Defaults to TRUE.

Return Value

object[]

Array of statistics records.

delete(EntityInterface $entity)

Delete comment statistics records for an entity.

Parameters

EntityInterface $entity

The entity for which comment statistics should be deleted.

create(FieldableEntityInterface $entity, array $fields)

Insert an empty record for the given entity.

Parameters

FieldableEntityInterface $entity

The created entity for which a statistics record is to be initialized.

array $fields

Array of comment field definitions for the given entity.

int getMaximumCount(string $entity_type)

Find the maximum number of comments for the given entity type.

Used to influence search rankings.

Parameters

string $entity_type

The entity type to consider when fetching the maximum comment count for.

Return Value

int

The maximum number of comments for and entity of the given type.

array getRankingInfo()

Returns an array of ranking information for hook_ranking().

Return Value

array

Array of ranking information as expected by hook_ranking().

update(CommentInterface $comment)

Update or insert comment statistics records after a comment is added.

Parameters

CommentInterface $comment

The comment added or updated.