PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / REST / V1 / Endpoints / Field.php
pods / src / Pods / REST / V1 / Endpoints Last commit date
Base.php 1 year ago Field.php 1 year ago Field_Slug.php 4 years ago Fields.php 1 year ago Group.php 1 year ago Group_Slug.php 4 years ago Groups.php 1 year ago Pod.php 1 year ago Pod_Slug.php 4 years ago Pods.php 1 year ago Swagger_Documentation.php 1 year ago
Field.php
325 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 use Pods\REST\Interfaces\Endpoints\DELETE_Interface;
6 use Pods\REST\Interfaces\Endpoints\READ_Interface;
7 use Pods\REST\Interfaces\Endpoints\UPDATE_Interface;
8 use Pods\REST\Interfaces\Swagger\Provider_Interface;
9 use WP_REST_Request;
10
11 class Field extends Base implements READ_Interface, UPDATE_Interface, DELETE_Interface, Provider_Interface {
12
13 /**
14 * {@inheritdoc}
15 *
16 * @since 2.8.0
17 */
18 public $route = '/fields/%1$d';
19
20 /**
21 * {@inheritdoc}
22 *
23 * @since 2.8.11
24 */
25 public $rest_route = '/fields/(?P<id>\\d+)';
26
27 /**
28 * {@inheritdoc}
29 *
30 * @since 2.8.11
31 */
32 public $rest_doc_route = '/fields/{id}';
33
34 /**
35 * {@inheritdoc}
36 *
37 * @since 2.8.0
38 */
39 public $object = 'field';
40
41 /**
42 * {@inheritdoc}
43 *
44 * @since 2.8.0
45 */
46 public function get_documentation() {
47 $GET_defaults = [
48 'in' => 'query',
49 'default' => '',
50 'type' => 'string',
51 ];
52
53 $POST_defaults = [
54 'in' => 'body',
55 'default' => '',
56 'type' => 'string',
57 ];
58
59 return [
60 'get' => [
61 'summary' => 'Retrieve a specific Field',
62 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
63 'responses' => [
64 '200' => [
65 'description' => 'Returns the requested Field with its details',
66 'content' => [
67 'application/json' => [
68 'schema' => [
69 '$ref' => '#/components/schemas/Field',
70 ],
71 ],
72 ],
73 ],
74 '400' => [
75 'description' => 'The request was invalid or cannot be otherwise served',
76 'content' => [
77 'application/json' => [
78 'schema' => [
79 'type' => 'object',
80 ],
81 ],
82 ],
83 ],
84 '401' => [
85 'description' => 'Unauthorized access - user does not have permission to access this Field',
86 'content' => [
87 'application/json' => [
88 'schema' => [
89 'type' => 'object',
90 ],
91 ],
92 ],
93 ],
94 '404' => [
95 'description' => 'The requested Field was not found',
96 'content' => [
97 'application/json' => [
98 'schema' => [
99 'type' => 'object',
100 ],
101 ],
102 ],
103 ],
104 ],
105 ],
106 'put' => [
107 'summary' => 'Update a specific Field',
108 'parameters' => $this->swaggerize_args( $this->EDIT_args(), $POST_defaults ),
109 'responses' => [
110 '200' => [
111 'description' => 'Returns the updated Field',
112 'content' => [
113 'application/json' => [
114 'schema' => [
115 '$ref' => '#/components/schemas/Field',
116 ],
117 ],
118 ],
119 ],
120 '400' => [
121 'description' => 'The request was invalid or cannot be otherwise served',
122 'content' => [
123 'application/json' => [
124 'schema' => [
125 'type' => 'object',
126 ],
127 ],
128 ],
129 ],
130 '401' => [
131 'description' => 'Unauthorized access - user does not have permission to update this Field',
132 'content' => [
133 'application/json' => [
134 'schema' => [
135 'type' => 'object',
136 ],
137 ],
138 ],
139 ],
140 '404' => [
141 'description' => 'The Field to update was not found',
142 'content' => [
143 'application/json' => [
144 'schema' => [
145 'type' => 'object',
146 ],
147 ],
148 ],
149 ],
150 ],
151 ],
152 'delete' => [
153 'summary' => 'Delete a specific Field',
154 'parameters' => $this->swaggerize_args( $this->DELETE_args(), $POST_defaults ),
155 'responses' => [
156 '200' => [
157 'description' => 'Returns the deleted Field details',
158 'content' => [
159 'application/json' => [
160 'schema' => [
161 '$ref' => '#/components/schemas/Field',
162 ],
163 ],
164 ],
165 ],
166 '400' => [
167 'description' => 'The request was invalid or cannot be otherwise served',
168 'content' => [
169 'application/json' => [
170 'schema' => [
171 'type' => 'object',
172 ],
173 ],
174 ],
175 ],
176 '401' => [
177 'description' => 'Unauthorized access - user does not have permission to delete this Field',
178 'content' => [
179 'application/json' => [
180 'schema' => [
181 'type' => 'object',
182 ],
183 ],
184 ],
185 ],
186 '404' => [
187 'description' => 'The Field to delete was not found',
188 'content' => [
189 'application/json' => [
190 'schema' => [
191 'type' => 'object',
192 ],
193 ],
194 ],
195 ],
196 ],
197 ],
198 ];
199 }
200
201 /**
202 * {@inheritdoc}
203 *
204 * @since 2.8.0
205 */
206 public function READ_args() {
207 return [
208 'id' => [
209 'type' => 'integer',
210 'in' => 'path',
211 'description' => __( 'The Field ID.', 'pods' ),
212 'required' => true,
213 'validate_callback' => [ $this->validator, 'is_field_id' ],
214 ],
215 ];
216 }
217
218 /**
219 * {@inheritdoc}
220 *
221 * @since 2.8.0
222 */
223 public function get( WP_REST_Request $request ) {
224 return $this->get_by_args( 'id', 'id', $request );
225 }
226
227 /**
228 * Determine whether access to READ is available.
229 *
230 * @since 2.8.0
231 *
232 * @return bool Whether access to READ is available.
233 */
234 public function can_read() {
235 return pods_is_admin( 'pods' );
236 }
237
238 /**
239 * {@inheritdoc}
240 *
241 * @since 2.8.0
242 */
243 public function EDIT_args() {
244 return [
245 'id' => [
246 'type' => 'integer',
247 'in' => 'path',
248 'description' => __( 'The Field ID.', 'pods' ),
249 'required' => true,
250 'validate_callback' => [ $this->validator, 'is_field_id' ],
251 ],
252 'name' => [
253 'type' => 'string',
254 'description' => __( 'The new name of the Field.', 'pods' ),
255 ],
256 'label' => [
257 'type' => 'string',
258 'description' => __( 'The singular label of the Field.', 'pods' ),
259 ],
260 'type' => [
261 'type' => 'string',
262 'description' => __( 'The type of the Field.', 'pods' ),
263 ],
264 'args' => [
265 'required' => false,
266 'description' => __( 'A list of additional options to save to the Field.', 'pods' ),
267 'swagger_type' => 'array',
268 ],
269 ];
270 }
271
272 /**
273 * {@inheritdoc}
274 *
275 * @since 2.8.0
276 */
277 public function update( WP_REST_Request $request ) {
278 return $this->update_by_args( 'id', 'id', $request );
279 }
280
281 /**
282 * {@inheritdoc}
283 *
284 * @since 2.8.0
285 */
286 public function can_edit() {
287 return pods_is_admin( 'pods' );
288 }
289
290 /**
291 * {@inheritdoc}
292 *
293 * @since 2.8.0
294 */
295 public function DELETE_args() {
296 return [
297 'id' => [
298 'type' => 'integer',
299 'in' => 'path',
300 'description' => __( 'The Field ID.', 'pods' ),
301 'required' => true,
302 'validate_callback' => [ $this->validator, 'is_field_id' ],
303 ],
304 ];
305 }
306
307 /**
308 * {@inheritdoc}
309 *
310 * @since 2.8.0
311 */
312 public function delete( WP_REST_Request $request ) {
313 return $this->delete_by_args( 'id', 'id', $request );
314 }
315
316 /**
317 * {@inheritdoc}
318 *
319 * @since 2.8.0
320 */
321 public function can_delete() {
322 return pods_is_admin( 'pods' );
323 }
324 }
325