comment.info.inc 6.26 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Provides info about the comment entity.
 */

/**
 * Implements hook_entity_property_info() on top of comment module.
10
 *
11
 * @see entity_entity_property_info()
12 13 14 15 16 17 18 19 20 21
 */
function entity_metadata_comment_entity_property_info() {
  $info = array();
  // Add meta-data about the basic comment properties.
  $properties = &$info['comment']['properties'];

  $properties['cid'] = array(
    'label' => t("Comment ID"),
    'type' => 'integer',
    'description' => t("The unique ID of the comment."),
22
    'schema field' => 'cid',
23 24 25 26
  );
  $properties['hostname'] = array(
    'label' => t("IP Address"),
    'description' => t("The IP address of the computer the comment was posted from."),
27
    'access callback' => 'entity_metadata_comment_properties_access',
28
    'schema field' => 'hostname',
29 30 31 32 33
  );
  $properties['name'] = array(
    'label' => t("Name"),
    'description' => t("The name left by the comment author."),
    'getter callback' => 'entity_metadata_comment_get_properties',
34
    'setter callback' => 'entity_property_verbatim_set',
35
    'setter permission' => 'administer comments',
36
    'sanitize' => 'filter_xss',
37
    'schema field' => 'name',
38 39 40 41 42
  );
  $properties['mail'] = array(
    'label' => t("Email address"),
    'description' => t("The email address left by the comment author."),
    'getter callback' => 'entity_metadata_comment_get_properties',
43
    'setter callback' => 'entity_property_verbatim_set',
44
    'validation callback' => 'valid_email_address',
45
    'access callback' => 'entity_metadata_comment_properties_access',
46
    'schema field' => 'mail',
47 48 49 50 51
  );
  $properties['homepage'] = array(
    'label' => t("Home page"),
    'description' => t("The home page URL left by the comment author."),
    'sanitize' => 'filter_xss_bad_protocol',
52
    'setter callback' => 'entity_property_verbatim_set',
53
    'setter permission' => 'administer comments',
54
    'schema field' => 'homepage',
55
  );
56 57 58
  $properties['subject'] = array(
    'label' => t("Subject"),
    'description' => t("The subject of the comment."),
59
    'setter callback' => 'entity_property_verbatim_set',
60
    'sanitize' => 'filter_xss',
61
    'required' => TRUE,
62
    'schema field' => 'subject',
63 64 65 66
  );
  $properties['url'] = array(
    'label' => t("URL"),
    'description' => t("The URL of the comment."),
67
    'getter callback' => 'entity_metadata_entity_get_properties',
68
    'type' => 'uri',
69
    'computed' => TRUE,
70
  );
71
  $properties['edit_url'] = array(
72 73 74 75
    'label' => t("Edit URL"),
    'description' => t("The URL of the comment's edit page."),
    'getter callback' => 'entity_metadata_comment_get_properties',
    'type' => 'uri',
76
    'computed' => TRUE,
77 78 79 80 81
  );
  $properties['created'] = array(
    'label' => t("Date created"),
    'description' => t("The date the comment was posted."),
    'type' => 'date',
82
    'setter callback' => 'entity_property_verbatim_set',
83
    'setter permission' => 'administer comments',
84
    'schema field' => 'created',
85 86 87 88 89 90
  );
  $properties['parent'] = array(
    'label' => t("Parent"),
    'description' => t("The comment's parent, if comment threading is active."),
    'type' => 'comment',
    'getter callback' => 'entity_metadata_comment_get_properties',
91
    'setter permission' => 'administer comments',
92
    'schema field' => 'pid',
93 94 95 96 97
  );
  $properties['node'] = array(
    'label' => t("Node"),
    'description' => t("The node the comment was posted to."),
    'type' => 'node',
98 99 100
    'setter callback' => 'entity_metadata_comment_setter',
    'setter permission' => 'administer comments',
    'required' => TRUE,
101
    'schema field' => 'nid',
102 103 104
  );
  $properties['author'] = array(
    'label' => t("Author"),
105
    'description' => t("The author of the comment."),
106
    'type' => 'user',
107
    'setter callback' => 'entity_property_verbatim_set',
108 109
    'setter permission' => 'administer comments',
    'required' => TRUE,
110
    'schema field' => 'uid',
111
  );
112 113 114 115 116 117 118 119
  $properties['status'] = array(
    'label' => t("Status"),
    'description' => t("Whether the comment is published or unpublished."),
    'setter callback' => 'entity_property_verbatim_set',
    // Although the status is expected to be boolean, its schema suggests
    // it is an integer, so we follow the schema definition.
    'type' => 'integer',
    'options list' => 'entity_metadata_status_options_list',
120
    'access callback' => 'entity_metadata_comment_properties_access',
121 122
    'schema field' => 'status',
  );
123 124 125 126 127
  return $info;
}

/**
 * Implements hook_entity_property_info_alter() on top of comment module.
128
 * @see entity_entity_property_info_alter()
129 130 131 132
 */
function entity_metadata_comment_entity_property_info_alter(&$info) {
  // Add info about comment module related properties to the node entity.
  $properties = &$info['node']['properties'];
133 134 135
  $properties['comment'] = array(
    'label' => t("Comments allowed"),
    'description' => t("Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write)."),
136
    'setter callback' => 'entity_property_verbatim_set',
137 138 139
    'setter permission' => 'administer comments',
    'type' => 'integer',
  );
140 141 142 143 144 145 146
  $properties['comments'] = array(
    'label' => t("Comments"),
    'type' => 'list<comment>',
    'description' => t("The node comments."),
    'getter callback' => 'entity_metadata_comment_get_node_properties',
    'computed' => TRUE,
  );
147
  $properties['comment_count'] = array(
148 149 150
    'label' => t("Comment count"),
    'description' => t("The number of comments posted on a node."),
    'getter callback' => 'entity_metadata_comment_get_node_properties',
151
    'type' => 'integer',
152
  );
153
  $properties['comment_count_new'] = array(
154 155 156
    'label' => t("New comment count"),
    'description' => t("The number of comments posted on a node since the reader last viewed it."),
    'getter callback' => 'entity_metadata_comment_get_node_properties',
157
    'type' => 'integer',
158
  );
159

160 161 162 163 164 165 166 167 168 169 170 171
  // The comment body field is usually available for all bundles, so add it
  // directly to the comment entity.
  $info['comment']['properties']['comment_body'] = array(
    'type' => 'text_formatted',
    'label' => t('The main body text'),
    'getter callback' => 'entity_metadata_field_verbatim_get',
    'setter callback' => 'entity_metadata_field_verbatim_set',
    'property info' => entity_property_text_formatted_info(),
    'field' => TRUE,
    'required' => TRUE,
  );
  unset($info['comment']['properties']['comment_body']['property info']['summary']);
172
}