interface CommentManagerInterface (View source)

Comment manager contains common functions to manage comment fields.

Constants

COMMENT_MODE_FLAT

Comments are displayed in a flat list - expanded.

COMMENT_MODE_THREADED

Comments are displayed as a threaded list - expanded.

Methods

array
getFields(string $entity_type_id)

Utility function to return an array of comment fields.

addBodyField(string $comment_type)

Creates a comment_body field.

string
forbiddenMessage(EntityInterface $entity, string $field_name)

Provides a message if posting comments is forbidden.

int|false
getCountNewComments(EntityInterface $entity, string $field_name = NULL, int $timestamp = 0)

Returns the number of new comments available on a given entity for a user.

Details

array getFields(string $entity_type_id)

Utility function to return an array of comment fields.

Parameters

string $entity_type_id

The content entity type to which the comment fields are attached.

Return Value

array

An array of comment field map definitions, keyed by field name. Each value is an array with two entries:

  • type: The field type.
  • bundles: The bundles in which the field appears, as an array with entity types as keys and the array of bundle names as values.

addBodyField(string $comment_type)

Creates a comment_body field.

Parameters

string $comment_type

The comment bundle.

string forbiddenMessage(EntityInterface $entity, string $field_name)

Provides a message if posting comments is forbidden.

If authenticated users can post comments, a message is returned that prompts the anonymous user to log in (or register, if applicable) that redirects to entity comment form. Otherwise, no message is returned.

Parameters

EntityInterface $entity

The entity to which comments are attached to.

string $field_name

The field name on the entity to which comments are attached to.

Return Value

string

HTML for a "you can't post comments" notice.

int|false getCountNewComments(EntityInterface $entity, string $field_name = NULL, int $timestamp = 0)

Returns the number of new comments available on a given entity for a user.

Parameters

EntityInterface $entity

The entity to which the comments are attached to.

string $field_name

(optional) The field_name to count comments for. Defaults to any field.

int $timestamp

(optional) Time to count from. Defaults to time of last user access the entity.

Return Value

int|false

The number of new comments or FALSE if the user is not authenticated.