CommentManagerInterface.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldMap()
  30. */
  31. public function getFields($entity_type_id);
  32. /**
  33. * Creates a comment_body field.
  34. *
  35. * @param string $comment_type
  36. * The comment bundle.
  37. */
  38. public function addBodyField($comment_type);
  39. /**
  40. * Provides a message if posting comments is forbidden.
  41. *
  42. * If authenticated users can post comments, a message is returned that
  43. * prompts the anonymous user to log in (or register, if applicable) that
  44. * redirects to entity comment form. Otherwise, no message is returned.
  45. *
  46. * @param \Drupal\Core\Entity\EntityInterface $entity
  47. * The entity to which comments are attached to.
  48. * @param string $field_name
  49. * The field name on the entity to which comments are attached to.
  50. *
  51. * @return string
  52. * HTML for a "you can't post comments" notice.
  53. */
  54. public function forbiddenMessage(EntityInterface $entity, $field_name);
  55. /**
  56. * Returns the number of new comments available on a given entity for a user.
  57. *
  58. * @param \Drupal\Core\Entity\EntityInterface $entity
  59. * The entity to which the comments are attached to.
  60. * @param string $field_name
  61. * (optional) The field_name to count comments for. Defaults to any field.
  62. * @param int $timestamp
  63. * (optional) Time to count from. Defaults to time of last user access the
  64. * entity.
  65. *
  66. * @return int|false
  67. * The number of new comments or FALSE if the user is not authenticated.
  68. */
  69. public function getCountNewComments(EntityInterface $entity, $field_name = NULL, $timestamp = 0);
  70. }