3 namespace Drupal\comment;
5 use Drupal\Core\Entity\EntityInterface;
8 * Comment manager contains common functions to manage comment fields.
10 interface CommentManagerInterface {
13 * Comments are displayed in a flat list - expanded.
15 const COMMENT_MODE_FLAT = 0;
18 * Comments are displayed as a threaded list - expanded.
20 const COMMENT_MODE_THREADED = 1;
23 * Utility function to return an array of comment fields.
25 * @param string $entity_type_id
26 * The content entity type to which the comment fields are attached.
29 * An array of comment field map definitions, keyed by field name. Each
30 * value is an array with two entries:
31 * - type: The field type.
32 * - bundles: The bundles in which the field appears, as an array with entity
33 * types as keys and the array of bundle names as values.
35 * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldMap()
37 public function getFields($entity_type_id);
40 * Creates a comment_body field.
42 * @param string $comment_type
45 public function addBodyField($comment_type);
48 * Provides a message if posting comments is forbidden.
50 * If authenticated users can post comments, a message is returned that
51 * prompts the anonymous user to log in (or register, if applicable) that
52 * redirects to entity comment form. Otherwise, no message is returned.
54 * @param \Drupal\Core\Entity\EntityInterface $entity
55 * The entity to which comments are attached to.
56 * @param string $field_name
57 * The field name on the entity to which comments are attached to.
60 * HTML for a "you can't post comments" notice.
62 public function forbiddenMessage(EntityInterface $entity, $field_name);
65 * Returns the number of new comments available on a given entity for a user.
67 * @param \Drupal\Core\Entity\EntityInterface $entity
68 * The entity to which the comments are attached to.
69 * @param string $field_name
70 * (optional) The field_name to count comments for. Defaults to any field.
71 * @param int $timestamp
72 * (optional) Time to count from. Defaults to time of last user access the
76 * The number of new comments or FALSE if the user is not authenticated.
78 public function getCountNewComments(EntityInterface $entity, $field_name = NULL, $timestamp = 0);