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