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 / Fields.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
Fields.php
290 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 use PodsForm;
6 use Pods\REST\Interfaces\Endpoints\CREATE_Interface;
7 use Pods\REST\Interfaces\Endpoints\READ_Interface;
8 use Pods\REST\Interfaces\Swagger\Provider_Interface;
9 use WP_REST_Request;
10
11 class Fields extends Base implements READ_Interface, CREATE_Interface, Provider_Interface {
12
13 /**
14 * {@inheritdoc}
15 *
16 * @since 2.8.0
17 */
18 public $route = '/fields';
19
20 /**
21 * {@inheritdoc}
22 *
23 * @since 2.8.0
24 */
25 public $object = 'field';
26
27 /**
28 * {@inheritdoc}
29 *
30 * @since 2.8.0
31 */
32 public function get_documentation() {
33 $GET_defaults = [
34 'in' => 'query',
35 'default' => '',
36 ];
37
38 $POST_defaults = [
39 'in' => 'body',
40 'default' => '',
41 'type' => 'string',
42 ];
43
44 return [
45 'get' => [
46 'summary' => 'Retrieve a collection of Fields',
47 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
48 'responses' => [
49 '200' => [
50 'description' => 'Returns a collection of Fields matching the request',
51 'content' => [
52 'application/json' => [
53 'schema' => [
54 'type' => 'object',
55 'properties' => [
56 'rest_url' => [
57 'type' => 'string',
58 'format' => 'uri',
59 'description' => __( 'This results page REST URL.', 'pods' ),
60 ],
61 'total' => [
62 'type' => 'integer',
63 'description' => __( 'The total number of results across all pages.', 'pods' ),
64 ],
65 'total_pages' => [
66 'type' => 'integer',
67 'description' => __( 'The total number of result pages matching the search criteria.', 'pods' ),
68 ],
69 'fields' => [
70 'type' => 'array',
71 'items' => [ '$ref' => '#/components/schemas/Field' ],
72 ],
73 ],
74 ],
75 ],
76 ],
77 ],
78 '400' => [
79 'description' => __( 'One or more of the specified query variables has a bad format.', 'pods' ),
80 'content' => [
81 'application/json' => [
82 'schema' => [
83 'type' => 'object',
84 ],
85 ],
86 ],
87 ],
88 '404' => [
89 'description' => __( 'The requested page was not found.', 'pods' ),
90 'content' => [
91 'application/json' => [
92 'schema' => [
93 'type' => 'object',
94 ],
95 ],
96 ],
97 ],
98 ],
99 ],
100 'post' => [
101 'summary' => 'Create a new Field',
102 'parameters' => $this->swaggerize_args( $this->CREATE_args(), $POST_defaults ),
103 'responses' => [
104 '201' => [
105 'description' => 'Returns the newly created Field',
106 'content' => [
107 'application/json' => [
108 'schema' => [
109 '$ref' => '#/components/schemas/Field',
110 ],
111 ],
112 ],
113 ],
114 '400' => [
115 'description' => 'The request was invalid or cannot be otherwise served',
116 'content' => [
117 'application/json' => [
118 'schema' => [
119 'type' => 'object',
120 ],
121 ],
122 ],
123 ],
124 '401' => [
125 'description' => 'Unauthorized access - user does not have permission to create Fields',
126 'content' => [
127 'application/json' => [
128 'schema' => [
129 'type' => 'object',
130 ],
131 ],
132 ],
133 ],
134 '403' => [
135 'description' => 'Forbidden - creation of this Field is not allowed',
136 'content' => [
137 'application/json' => [
138 'schema' => [
139 'type' => 'object',
140 ],
141 ],
142 ],
143 ],
144 ],
145 ],
146 ];
147 }
148
149 /**
150 * {@inheritdoc}
151 *
152 * @since 2.8.0
153 */
154 public function READ_args() {
155 return [
156 'return_type' => [
157 'description' => __( 'The type of data to return.', 'pods' ),
158 'type' => 'string',
159 'default' => 'full',
160 'required' => false,
161 'enum' => [
162 'full',
163 'names',
164 'names_ids',
165 'ids',
166 'key_names',
167 'count',
168 ],
169 ],
170 'types' => [
171 'required' => false,
172 'description' => __( 'A list of types to filter by.', 'pods' ),
173 'swagger_type' => 'array',
174 'items' => [
175 'type' => 'string',
176 ],
177 'collectionFormat' => 'csv',
178 ],
179 'ids' => [
180 'required' => false,
181 'description' => __( 'A list of IDs to filter by.', 'pods' ),
182 'swagger_type' => 'array',
183 'items' => [
184 'type' => 'integer',
185 ],
186 'collectionFormat' => 'csv',
187 ],
188 'args' => [
189 'required' => false,
190 'description' => __( 'A list of arguments to filter by.', 'pods' ),
191 'swagger_type' => 'array',
192 ],
193 'include_parent' => [
194 'type' => 'boolean',
195 'description' => __( 'Whether to include the parent Pod details (default: off).', 'pods' ),
196 'default' => false,
197 'cli_boolean' => true,
198 ],
199 ];
200 }
201
202 /**
203 * {@inheritdoc}
204 *
205 * @since 2.8.0
206 */
207 public function get( WP_REST_Request $request ) {
208 return $this->archive_by_args( $request );
209 }
210
211 /**
212 * Determine whether access to READ is available.
213 *
214 * @since 2.8.0
215 *
216 * @return bool Whether access to READ is available.
217 */
218 public function can_read() {
219 return pods_is_admin( 'pods' );
220 }
221
222 /**
223 * {@inheritdoc}
224 *
225 * @since 2.8.0
226 */
227 public function CREATE_args() {
228 return [
229 'pod_id' => [
230 'type' => 'string',
231 'description' => __( 'The Pod ID.', 'pods' ),
232 'validate_callback' => [ $this->validator, 'is_pod_id' ],
233 ],
234 'pod' => [
235 'type' => 'string',
236 'description' => __( 'The Pod name.', 'pods' ),
237 'validate_callback' => [ $this->validator, 'is_pod_slug' ],
238 ],
239 'group_id' => [
240 'type' => 'string',
241 'description' => __( 'The Group ID.', 'pods' ),
242 'validate_callback' => [ $this->validator, 'is_group_id' ],
243 ],
244 'group' => [
245 'type' => 'string',
246 'description' => __( 'The Group name.', 'pods' ),
247 'validate_callback' => [ $this->validator, 'is_group_slug' ],
248 ],
249 'name' => [
250 'type' => 'string',
251 'description' => __( 'The name of the Field.', 'pods' ),
252 ],
253 'label' => [
254 'type' => 'string',
255 'description' => __( 'The singular label of the Field.', 'pods' ),
256 'required' => true,
257 ],
258 'type' => [
259 'type' => 'string',
260 'description' => __( 'The type of the Field.', 'pods' ),
261 'enum' => PodsForm::field_types_list(),
262 'required' => true,
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 create( WP_REST_REQUEST $request, $return_id = false ) {
278 return $this->create_by_args( $request, $return_id );
279 }
280
281 /**
282 * {@inheritdoc}
283 *
284 * @since 2.8.0
285 */
286 public function can_create() {
287 return pods_is_admin( 'pods' );
288 }
289 }
290