comment.info.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * @file
  4. * Provides info about the comment entity.
  5. */
  6. /**
  7. * Implements hook_entity_property_info() on top of comment module.
  8. *
  9. * @see entity_entity_property_info()
  10. */
  11. function entity_metadata_comment_entity_property_info() {
  12. $info = array();
  13. // Add meta-data about the basic comment properties.
  14. $properties = &$info['comment']['properties'];
  15. $properties['cid'] = array(
  16. 'label' => t("Comment ID"),
  17. 'type' => 'integer',
  18. 'description' => t("The unique ID of the comment."),
  19. 'schema field' => 'cid',
  20. );
  21. $properties['hostname'] = array(
  22. 'label' => t("IP Address"),
  23. 'description' => t("The IP address of the computer the comment was posted from."),
  24. 'access callback' => 'entity_metadata_comment_properties_access',
  25. 'schema field' => 'hostname',
  26. );
  27. $properties['name'] = array(
  28. 'label' => t("Name"),
  29. 'description' => t("The name left by the comment author."),
  30. 'getter callback' => 'entity_metadata_comment_get_properties',
  31. 'setter callback' => 'entity_property_verbatim_set',
  32. 'setter permission' => 'administer comments',
  33. 'sanitize' => 'filter_xss',
  34. 'schema field' => 'name',
  35. );
  36. $properties['mail'] = array(
  37. 'label' => t("Email address"),
  38. 'description' => t("The email address left by the comment author."),
  39. 'getter callback' => 'entity_metadata_comment_get_properties',
  40. 'setter callback' => 'entity_property_verbatim_set',
  41. 'validation callback' => 'valid_email_address',
  42. 'access callback' => 'entity_metadata_comment_properties_access',
  43. 'schema field' => 'mail',
  44. );
  45. $properties['homepage'] = array(
  46. 'label' => t("Home page"),
  47. 'description' => t("The home page URL left by the comment author."),
  48. 'sanitize' => 'filter_xss_bad_protocol',
  49. 'setter callback' => 'entity_property_verbatim_set',
  50. 'setter permission' => 'administer comments',
  51. 'schema field' => 'homepage',
  52. );
  53. $properties['subject'] = array(
  54. 'label' => t("Subject"),
  55. 'description' => t("The subject of the comment."),
  56. 'setter callback' => 'entity_property_verbatim_set',
  57. 'sanitize' => 'filter_xss',
  58. 'required' => TRUE,
  59. 'schema field' => 'subject',
  60. );
  61. $properties['url'] = array(
  62. 'label' => t("URL"),
  63. 'description' => t("The URL of the comment."),
  64. 'getter callback' => 'entity_metadata_entity_get_properties',
  65. 'type' => 'uri',
  66. 'computed' => TRUE,
  67. );
  68. $properties['edit_url'] = array(
  69. 'label' => t("Edit URL"),
  70. 'description' => t("The URL of the comment's edit page."),
  71. 'getter callback' => 'entity_metadata_comment_get_properties',
  72. 'type' => 'uri',
  73. 'computed' => TRUE,
  74. );
  75. $properties['created'] = array(
  76. 'label' => t("Date created"),
  77. 'description' => t("The date the comment was posted."),
  78. 'type' => 'date',
  79. 'setter callback' => 'entity_property_verbatim_set',
  80. 'setter permission' => 'administer comments',
  81. 'schema field' => 'created',
  82. );
  83. $properties['parent'] = array(
  84. 'label' => t("Parent"),
  85. 'description' => t("The comment's parent, if comment threading is active."),
  86. 'type' => 'comment',
  87. 'getter callback' => 'entity_metadata_comment_get_properties',
  88. 'setter permission' => 'administer comments',
  89. 'schema field' => 'pid',
  90. );
  91. $properties['node'] = array(
  92. 'label' => t("Node"),
  93. 'description' => t("The node the comment was posted to."),
  94. 'type' => 'node',
  95. 'setter callback' => 'entity_metadata_comment_setter',
  96. 'setter permission' => 'administer comments',
  97. 'required' => TRUE,
  98. 'schema field' => 'nid',
  99. );
  100. $properties['author'] = array(
  101. 'label' => t("Author"),
  102. 'description' => t("The author of the comment."),
  103. 'type' => 'user',
  104. 'setter callback' => 'entity_property_verbatim_set',
  105. 'setter permission' => 'administer comments',
  106. 'required' => TRUE,
  107. 'schema field' => 'uid',
  108. );
  109. $properties['status'] = array(
  110. 'label' => t("Status"),
  111. 'description' => t("Whether the comment is published or unpublished."),
  112. 'setter callback' => 'entity_property_verbatim_set',
  113. // Although the status is expected to be boolean, its schema suggests
  114. // it is an integer, so we follow the schema definition.
  115. 'type' => 'integer',
  116. 'options list' => 'entity_metadata_status_options_list',
  117. 'access callback' => 'entity_metadata_comment_properties_access',
  118. 'schema field' => 'status',
  119. );
  120. return $info;
  121. }
  122. /**
  123. * Implements hook_entity_property_info_alter() on top of comment module.
  124. * @see entity_entity_property_info_alter()
  125. */
  126. function entity_metadata_comment_entity_property_info_alter(&$info) {
  127. // Add info about comment module related properties to the node entity.
  128. $properties = &$info['node']['properties'];
  129. $properties['comment'] = array(
  130. 'label' => t("Comments allowed"),
  131. 'description' => t("Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write)."),
  132. 'setter callback' => 'entity_property_verbatim_set',
  133. 'setter permission' => 'administer comments',
  134. 'type' => 'integer',
  135. );
  136. $properties['comments'] = array(
  137. 'label' => t("Comments"),
  138. 'type' => 'list<comment>',
  139. 'description' => t("The node comments."),
  140. 'getter callback' => 'entity_metadata_comment_get_node_properties',
  141. 'computed' => TRUE,
  142. );
  143. $properties['comment_count'] = array(
  144. 'label' => t("Comment count"),
  145. 'description' => t("The number of comments posted on a node."),
  146. 'getter callback' => 'entity_metadata_comment_get_node_properties',
  147. 'type' => 'integer',
  148. );
  149. $properties['comment_count_new'] = array(
  150. 'label' => t("New comment count"),
  151. 'description' => t("The number of comments posted on a node since the reader last viewed it."),
  152. 'getter callback' => 'entity_metadata_comment_get_node_properties',
  153. 'type' => 'integer',
  154. );
  155. // The comment body field is usually available for all bundles, so add it
  156. // directly to the comment entity.
  157. $info['comment']['properties']['comment_body'] = array(
  158. 'type' => 'text_formatted',
  159. 'label' => t('The main body text'),
  160. 'getter callback' => 'entity_metadata_field_verbatim_get',
  161. 'setter callback' => 'entity_metadata_field_verbatim_set',
  162. 'property info' => entity_property_text_formatted_info(),
  163. 'field' => TRUE,
  164. 'required' => TRUE,
  165. );
  166. unset($info['comment']['properties']['comment_body']['property info']['summary']);
  167. }