CommentManagerInterface.php 3.56 KB
Newer Older
1
2
3
4
5
6
7
8
<?php

/**
 * @file
 * Contains \Drupal\comment\CommentManagerInterface.
 */

namespace Drupal\comment;
9
use Drupal\Core\Entity\EntityInterface;
10

11
12
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * Comment manager contains common functions to manage comment fields.
 */
interface CommentManagerInterface {

  /**
   * Utility function to return URI of the comment's parent entity.
   *
   * @param \Drupal\comment\CommentInterface $comment
   *   The comment entity.
   *
   * @return array
   *   An array returned by \Drupal\Core\Entity\EntityInterface::uri().
   */
  public function getParentEntityUri(CommentInterface $comment);

  /**
   * Utility function to return an array of comment fields.
   *
32
   * @param string $entity_type_id
33
   *   The content entity type to which the comment fields are attached.
34
35
36
37
38
39
40
41
42
43
   *
   * @return 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.
   *
   * @see field_info_field_map()
   */
44
  public function getFields($entity_type_id);
45
46
47
48
49
50
51
52
53
54

  /**
   * Utility function to return all comment fields.
   */
  public function getAllFields();

  /**
   * Utility method to add the default comment field to an entity.
   *
   * Attaches a comment field named 'comment' to the given entity type and
55
   * bundle. Largely replicates the default behavior in Drupal 7 and earlier.
56
57
58
59
60
61
62
63
   *
   * @param string $entity_type
   *   The entity type to attach the default comment field to.
   * @param string $bundle
   *   The bundle to attach the default comment field instance to.
   * @param string $field_name
   *   (optional) Field name to use for the comment field. Defaults to 'comment'.
   * @param int $default_value
64
65
66
   *   (optional) Default value, one of CommentItemInterface::HIDDEN,
   *   CommentItemInterface::OPEN, CommentItemInterface::CLOSED. Defaults to
   *   CommentItemInterface::OPEN.
67
   */
68
  public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN);
69
70
71
72
73
74
75
76
77
78
79
80
81
82

  /**
   * Creates a comment_body field instance.
   *
   * @param string $entity_type
   *   The type of the entity to which the comment field attached.
   * @param string $field_name
   *   Name of the comment field to add comment_body field.
   */
  public function addBodyField($entity_type, $field_name);

  /**
   * Builds human readable page title for field_ui management screens.
   *
83
84
   * @param string $commented_entity_type
   *   The entity type to which the comment field is attached.
85
86
87
88
89
90
   * @param string $field_name
   *   The comment field for which the overview is to be displayed.
   *
   * @return string
   *   The human readable field name.
   */
91
  public function getFieldUIPageTitle($commented_entity_type, $field_name);
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  /**
   * 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.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to which comments are attached to.
   * @param string $field_name
   *   The field name on the entity to which comments are attached to.
   *
   * @return string
   *   HTML for a "you can't post comments" notice.
   */
  public function forbiddenMessage(EntityInterface $entity, $field_name);

110
}