forked from justafish/drupal_createapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createapi.api.php
239 lines (230 loc) · 6.33 KB
/
createapi.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* @file
* Hooks provided by the CreateAPI module.
*/
/**
* Expose content types as endpoints.
*
* @return array
* Describes the properties of the endpoint, each element keyed by the machine
* name of each content type being exposed.
*/
function hook_createapi_content_types() {
return array(
// The content type machine name.
'topic' => array(
// This will create a path of the form "/api/<version>/<path>".
'version' => '1.0',
'path' => 'topics.json',
// Wrapper fields for JSON data.
'wrapper' => 'topics',
'row' => 'topic',
// Which fields and properties to be output, as well as the path.
// The key represents the output alias and the value is the field or
// property machine name.
'data' => array(
'fields' => array(
'short_title' => 'field_short_title',
'primary_image' => 'field_primary_image',
'teaser_image' => array('field_teaser_image' => array(
'fields' > array(
'alt' => 'field_file_image_alt_text',
'title' => 'field_file_image_title_text',
'caption' => 'field_caption',
),
'styles' => array(
'thumbnail' => 'thumbnail',
'medium' => 'medium',
'large' => 'large',
'square_thumbnail' => 'square_thumbnail',
),
),
'assets' => array('field_asset_reference' => array(
'fields' => array(
'type' => 'field_type'
),
'properties' => array(
'title' => 'title',
),
'path' => 'path',
)),
),
'properties' => array(
'id' => 'nid',
'title' => 'title',
'created' => 'created',
),
// The value is used as the output alias.
'path' => 'path',
),
// URL filters that can be used with this endpoint.
'filters' => array(
// The key represents the parameter to be used in the URL and the value
// is the property to filter by. Multiple parameters can be provided,
// separated by ",".
'properties' => array(
'id' => 'nid',
),
// The key represents the parameter to be used in the URL.
'fields' => array(
'person' => array(
'field' => 'field_person',
'column' => 'target_id',
),
'type' => array(
'field' => 'field_type',
'column' => 'value',
),
),
// The value is used as the URL parameter.
'path' => 'path',
'start_end' => array(
// The property to restrict results by. This could also be
// 'field' => 'field_name', however the property will override the
// field if both are present.
'property' => 'created',
// The values are used in the URL parameters.
'start' => 'start',
'end' => 'end',
),
// The values are used in the URL parameters. There is an enforced limit
// of 200 items for the range.
'range' => 'count',
'offset' => 'offset',
),
),
);
}
/**
* Expose nodequeues as endpoints.
*
* @return array
* Describes the properties of the endpoint, each element keyed by the machine
* name of each nodequeue being exposed.
*
* @see hook_createapi_content_types()
*/
function hook_createapi_nodequeues() {
return array(
// The nodequeue machine name.
'trending_topics' => array(
'version' => '1.0',
'path' => 'trending-topics.json',
'wrapper' => 'topics',
'row' => 'topic',
'data' => array(
'fields' => array(
'short_title' => 'field_short_title',
),
'properties' => array(
'id' => 'nid',
'title' => 'title',
),
'path' => 'path',
),
// Only the following filters are supported in nodequeue endpoints.
'filters' => array(
'properties' => array(
'id' => 'nid',
),
'path' => 'path',
'range' => 'count',
'offset' => 'offset',
),
),
);
}
/**
* Expose menus as an endpoint.
*/
function hook_createapi_menus() {
return array(
'main-menu' => array(
'version' => '1.0',
'path' => 'main-menu.json',
'wrapper' => 'links',
'row' => 'link',
),
);
}
/**
* Expose any entities as an endpoint.
*
* @return array
* Describes the properties of the endpoint.
*
* @see hook_createapi_content_types()
*/
function hook_createapi_custom_entities_info() {
return array(
'topics' => array(
'version' => '1.0',
'path' => 'topics.json',
'wrapper' => 'topics',
'row' => 'topic',
'data' => array(
'fields' => array(
'short_title' => 'field_short_title',
),
'properties' => array(
'id' => 'nid',
'title' => 'title',
'created' => 'created',
),
'path' => 'path',
),
'filters' => array(
'properties' => array(
'id' => 'nid',
),
'path' => 'path',
'start_end' => array(
'property' => 'created',
'start' => 'start',
'end' => 'end',
),
'range' => 'count',
'offset' => 'offset',
),
'custom_query' => array(
'entity_type' => 'node',
// This item is only required if path filtering is used. It is the alias
// of the node ID as used in the EntityFieldQuery.
'nid_alias' => 'nid',
),
),
);
}
/**
* The query that is used for fetching the set of entities to use for custom
* endpoints.
*
* @return EntityFieldQuery
*/
function hook_createapi_custom_entities_query_ENDPOINT_ID() {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'topic')
->propertyCondition('status', 1)
->propertyOrderBy('nid', 'DESC');
return $query;
}
/**
* Expose items from the variable table in a json feed.
*
* @return array
* Describes the properties of the endpoint.
*/
function hook_createapi_variables() {
return array(
'site-information' => array(
'version' => '1.0',
'path' => 'site-information.json',
'wrapper' => 'variables',
'data' => array(
'site_name' => 'site_name',
),
),
);
}