PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.5
Pods – Custom Content Types and Fields v3.2.5
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 3 years ago Field.php 3 years ago Field_Slug.php 4 years ago Fields.php 3 years ago Group.php 3 years ago Group_Slug.php 4 years ago Groups.php 3 years ago Pod.php 3 years ago Pod_Slug.php 4 years ago Pods.php 3 years ago Swagger_Documentation.php 3 years ago
Field.php
229 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 // @todo Handle get/post/delete
54
55 return [
56 'get' => [
57 'summary' => '', // @todo Fill this out
58 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
59 'responses' => [
60 '200' => [
61 'description' => '', // @todo Fill this out
62 'content' => [
63 'application/json' => [
64 'schema' => [
65 '$ref' => '#/components/schemas/Field',
66 ],
67 ],
68 ],
69 ],
70 '400' => [
71 'description' => '', // @todo Fill this out
72 'content' => [
73 'application/json' => [
74 'schema' => [
75 'type' => 'object',
76 ],
77 ],
78 ],
79 ],
80 '401' => [
81 'description' => '', // @todo Fill this out
82 'content' => [
83 'application/json' => [
84 'schema' => [
85 'type' => 'object',
86 ],
87 ],
88 ],
89 ],
90 '404' => [
91 'description' => '', // @todo Fill this out
92 'content' => [
93 'application/json' => [
94 'schema' => [
95 'type' => 'object',
96 ],
97 ],
98 ],
99 ],
100 ],
101 ],
102 ];
103 }
104
105 /**
106 * {@inheritdoc}
107 *
108 * @since 2.8.0
109 */
110 public function READ_args() {
111 return [
112 'id' => [
113 'type' => 'integer',
114 'in' => 'path',
115 'description' => __( 'The Field ID.', 'pods' ),
116 'required' => true,
117 'validate_callback' => [ $this->validator, 'is_field_id' ],
118 ],
119 ];
120 }
121
122 /**
123 * {@inheritdoc}
124 *
125 * @since 2.8.0
126 */
127 public function get( WP_REST_Request $request ) {
128 return $this->get_by_args( 'id', 'id', $request );
129 }
130
131 /**
132 * Determine whether access to READ is available.
133 *
134 * @since 2.8.0
135 *
136 * @return bool Whether access to READ is available.
137 */
138 public function can_read() {
139 return pods_is_admin( 'pods' );
140 }
141
142 /**
143 * {@inheritdoc}
144 *
145 * @since 2.8.0
146 */
147 public function EDIT_args() {
148 return [
149 'id' => [
150 'type' => 'integer',
151 'in' => 'path',
152 'description' => __( 'The Field ID.', 'pods' ),
153 'required' => true,
154 'validate_callback' => [ $this->validator, 'is_field_id' ],
155 ],
156 'name' => [
157 'type' => 'string',
158 'description' => __( 'The new name of the Field.', 'pods' ),
159 ],
160 'label' => [
161 'type' => 'string',
162 'description' => __( 'The singular label of the Field.', 'pods' ),
163 ],
164 'type' => [
165 'type' => 'string',
166 'description' => __( 'The type of the Field.', 'pods' ),
167 ],
168 'args' => [
169 'required' => false,
170 'description' => __( 'A list of additional options to save to the Field.', 'pods' ),
171 'swagger_type' => 'array',
172 ],
173 ];
174 }
175
176 /**
177 * {@inheritdoc}
178 *
179 * @since 2.8.0
180 */
181 public function update( WP_REST_Request $request ) {
182 return $this->update_by_args( 'id', 'id', $request );
183 }
184
185 /**
186 * {@inheritdoc}
187 *
188 * @since 2.8.0
189 */
190 public function can_edit() {
191 return pods_is_admin( 'pods' );
192 }
193
194 /**
195 * {@inheritdoc}
196 *
197 * @since 2.8.0
198 */
199 public function DELETE_args() {
200 return [
201 'id' => [
202 'type' => 'integer',
203 'in' => 'path',
204 'description' => __( 'The Field ID.', 'pods' ),
205 'required' => true,
206 'validate_callback' => [ $this->validator, 'is_field_id' ],
207 ],
208 ];
209 }
210
211 /**
212 * {@inheritdoc}
213 *
214 * @since 2.8.0
215 */
216 public function delete( WP_REST_Request $request ) {
217 return $this->delete_by_args( 'id', 'id', $request );
218 }
219
220 /**
221 * {@inheritdoc}
222 *
223 * @since 2.8.0
224 */
225 public function can_delete() {
226 return pods_is_admin( 'pods' );
227 }
228 }
229