CommentManagerInterface.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Drupal\comment;
  3. use Drupal\Core\Entity\EntityInterface;
  4. /**
  5. * Comment manager contains common functions to manage comment fields.
  6. */
  7. interface CommentManagerInterface {
  8. /**
  9. * Comments are displayed in a flat list - expanded.
  10. */
  11. const COMMENT_MODE_FLAT = 0;
  12. /**
  13. * Comments are displayed as a threaded list - expanded.
  14. */
  15. const COMMENT_MODE_THREADED = 1;
  16. /**
  17. * Utility function to return an array of comment fields.
  18. *
  19. * @param string $entity_type_id
  20. * The content entity type to which the comment fields are attached.
  21. *
  22. * @return array
  23. * An array of comment field map definitions, keyed by field name. Each
  24. * value is an array with two entries:
  25. * - type: The field type.
  26. * - bundles: The bundles in which the field appears, as an array with entity
  27. * types as keys and the array of bundle names as values.
  28. */
  29. public function getFields($entity_type_id);
  30. /**
  31. * Creates a comment_body field.
  32. *
  33. * @param string $comment_type
  34. * The comment bundle.
  35. */
  36. public function addBodyField($comment_type);
  37. /**
  38. * Provides a message if posting comments is forbidden.
  39. *
  40. * If authenticated users can post comments, a message is returned that
  41. * prompts the anonymous user to log in (or register, if applicable) that
  42. * redirects to entity comment form. Otherwise, no message is returned.
  43. *
  44. * @param \Drupal\Core\Entity\EntityInterface $entity
  45. * The entity to which comments are attached to.
  46. * @param string $field_name
  47. * The field name on the entity to which comments are attached to.
  48. *
  49. * @return string
  50. * HTML for a "you can't post comments" notice.
  51. */
  52. public function forbiddenMessage(EntityInterface $entity, $field_name);
  53. /**
  54. * Returns the number of new comments available on a given entity for a user.
  55. *
  56. * @param \Drupal\Core\Entity\EntityInterface $entity
  57. * The entity to which the comments are attached to.
  58. * @param string $field_name
  59. * (optional) The field_name to count comments for. Defaults to any field.
  60. * @param int $timestamp
  61. * (optional) Time to count from. Defaults to time of last user access the
  62. * entity.
  63. *
  64. * @return int|false
  65. * The number of new comments or FALSE if the user is not authenticated.
  66. */
  67. public function getCountNewComments(EntityInterface $entity, $field_name = NULL, $timestamp = 0);
  68. }