← All changes
|
lib/experimental/dashboard-widgets/class-wp-rest-widget-modules-controller.php
+173
-1
23.2.2
→
trunk
View file →
| @@ -110,9 +110,9 @@ | ||
| 110 | 110 | * Verifies the user has the basic read capability. |
| 111 | 111 | * |
| 112 | 112 | * Widget modules are not sensitive data; they describe what is |
| 113 | 113 | * available to render. Gating at the same level as the dashboard |
| 114 | - * page menu (which requires `read`) keeps the surface consistent. | |
| 114 | + * page menu (which requires `read`) keeps access consistent. | |
| 115 | 115 | * |
| 116 | 116 | * @return true|WP_Error True if the request is allowed, WP_Error |
| 117 | 117 | * otherwise. |
| 118 | 118 | */ |
| @@ -181,15 +181,53 @@ | ||
| 181 | 181 | |
| 182 | 182 | if ( rest_is_field_included( 'name', $fields ) ) { |
| 183 | 183 | $data['name'] = $widget_type->name; |
| 184 | 184 | } |
| 185 | + | |
| 185 | 186 | if ( rest_is_field_included( 'render_module', $fields ) ) { |
| 186 | 187 | $data['render_module'] = $widget_type->render_module; |
| 187 | 188 | } |
| 189 | + | |
| 188 | 190 | if ( rest_is_field_included( 'widget_module', $fields ) ) { |
| 189 | 191 | $data['widget_module'] = $widget_type->widget_module; |
| 190 | 192 | } |
| 191 | 193 | |
| 194 | + if ( rest_is_field_included( 'presentation', $fields ) ) { | |
| 195 | + $data['presentation'] = $widget_type->presentation; | |
| 196 | + } | |
| 197 | + | |
| 198 | + if ( rest_is_field_included( 'category', $fields ) ) { | |
| 199 | + $data['category'] = $widget_type->category; | |
| 200 | + } | |
| 201 | + | |
| 202 | + if ( rest_is_field_included( 'title', $fields ) ) { | |
| 203 | + $data['title'] = $widget_type->title; | |
| 204 | + } | |
| 205 | + | |
| 206 | + if ( rest_is_field_included( 'description', $fields ) ) { | |
| 207 | + $data['description'] = $widget_type->description; | |
| 208 | + } | |
| 209 | + | |
| 210 | + if ( rest_is_field_included( 'help', $fields ) ) { | |
| 211 | + $data['help'] = $widget_type->help; | |
| 212 | + } | |
| 213 | + | |
| 214 | + if ( rest_is_field_included( 'icon', $fields ) ) { | |
| 215 | + $data['icon'] = $widget_type->icon; | |
| 216 | + } | |
| 217 | + | |
| 218 | + if ( rest_is_field_included( 'actions', $fields ) ) { | |
| 219 | + $data['actions'] = $widget_type->actions; | |
| 220 | + } | |
| 221 | + | |
| 222 | + if ( rest_is_field_included( 'attributes', $fields ) ) { | |
| 223 | + $data['attributes'] = $widget_type->attributes; | |
| 224 | + } | |
| 225 | + | |
| 226 | + if ( rest_is_field_included( 'keywords', $fields ) ) { | |
| 227 | + $data['keywords'] = $widget_type->keywords; | |
| 228 | + } | |
| 229 | + | |
| 192 | 230 | $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
| 193 | 231 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 194 | 232 | $data = $this->filter_response_by_context( $data, $context ); |
| 195 | 233 | |
| @@ -216,8 +254,9 @@ | ||
| 216 | 254 | 'type' => 'string', |
| 217 | 255 | 'context' => array( 'view', 'edit', 'embed' ), |
| 218 | 256 | 'readonly' => true, |
| 219 | 257 | ), |
| 258 | + | |
| 220 | 259 | 'render_module' => array( |
| 221 | 260 | 'description' => __( 'Script-module handle for the widget render entry point.', 'gutenberg' ), |
| 222 | 261 | 'type' => array( 'string', 'null' ), |
| 223 | 262 | 'context' => array( 'view', 'edit', 'embed' ), |
| @@ -222,11 +261,144 @@ | ||
| 222 | 261 | 'type' => array( 'string', 'null' ), |
| 223 | 262 | 'context' => array( 'view', 'edit', 'embed' ), |
| 224 | 263 | 'readonly' => true, |
| 225 | 264 | ), |
| 265 | + | |
| 226 | 266 | 'widget_module' => array( |
| 227 | 267 | 'description' => __( 'Script-module handle for the widget metadata entry point.', 'gutenberg' ), |
| 228 | 268 | 'type' => array( 'string', 'null' ), |
| 269 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 270 | + 'readonly' => true, | |
| 271 | + ), | |
| 272 | + | |
| 273 | + 'presentation' => array( | |
| 274 | + 'description' => __( 'Authoring intent about how the widget wants to render.', 'gutenberg' ), | |
| 275 | + 'type' => array( 'string', 'null' ), | |
| 276 | + 'enum' => array_merge( WP_Widget_Type::PRESENTATION_VALUES, array( null ) ), | |
| 277 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 278 | + 'readonly' => true, | |
| 279 | + ), | |
| 280 | + | |
| 281 | + 'category' => array( | |
| 282 | + 'description' => __( 'Widget types are grouped into categories to help users browse and discover them.', 'gutenberg' ), | |
| 283 | + 'type' => array( 'string', 'null' ), | |
| 284 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 285 | + 'readonly' => true, | |
| 286 | + ), | |
| 287 | + | |
| 288 | + 'title' => array( | |
| 289 | + 'description' => __( 'Human-readable title that names the widget type. Translatable.', 'gutenberg' ), | |
| 290 | + 'type' => array( 'string', 'null' ), | |
| 291 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 292 | + 'readonly' => true, | |
| 293 | + ), | |
| 294 | + | |
| 295 | + 'description' => array( | |
| 296 | + 'description' => __( 'Human-readable description of what the widget type does. Translatable.', 'gutenberg' ), | |
| 297 | + 'type' => array( 'string', 'null' ), | |
| 298 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 299 | + 'readonly' => true, | |
| 300 | + ), | |
| 301 | + | |
| 302 | + 'help' => array( | |
| 303 | + 'description' => __( 'Contextual help note for the widget type: content plus optional links. Translatable.', 'gutenberg' ), | |
| 304 | + 'type' => array( 'object', 'null' ), | |
| 305 | + 'properties' => array( | |
| 306 | + 'content' => array( | |
| 307 | + 'description' => __( 'Help content; may carry minimal inline emphasis.', 'gutenberg' ), | |
| 308 | + 'type' => 'string', | |
| 309 | + ), | |
| 310 | + 'links' => array( | |
| 311 | + 'description' => __( 'Optional links contextual to the help content.', 'gutenberg' ), | |
| 312 | + 'type' => 'array', | |
| 313 | + 'items' => array( | |
| 314 | + 'type' => 'object', | |
| 315 | + 'properties' => array( | |
| 316 | + 'label' => array( 'type' => 'string' ), | |
| 317 | + 'href' => array( 'type' => 'string' ), | |
| 318 | + ), | |
| 319 | + ), | |
| 320 | + ), | |
| 321 | + ), | |
| 322 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 323 | + 'readonly' => true, | |
| 324 | + ), | |
| 325 | + | |
| 326 | + 'icon' => array( | |
| 327 | + 'description' => __( 'Registered icon name identifying the widget type visually.', 'gutenberg' ), | |
| 328 | + 'type' => array( 'string', 'null' ), | |
| 329 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 330 | + 'readonly' => true, | |
| 331 | + ), | |
| 332 | + | |
| 333 | + 'actions' => array( | |
| 334 | + 'description' => __( 'Declarative actions the widget type exposes. Labels are translatable.', 'gutenberg' ), | |
| 335 | + 'type' => array( 'array', 'null' ), | |
| 336 | + 'items' => array( | |
| 337 | + 'type' => 'object', | |
| 338 | + 'properties' => array( | |
| 339 | + 'id' => array( 'type' => 'string' ), | |
| 340 | + 'label' => array( 'type' => 'string' ), | |
| 341 | + 'icon' => array( 'type' => 'string' ), | |
| 342 | + 'relevance' => array( | |
| 343 | + 'type' => 'string', | |
| 344 | + 'enum' => array( 'high', 'medium', 'low' ), | |
| 345 | + ), | |
| 346 | + 'href' => array( 'type' => 'string' ), | |
| 347 | + 'download' => array( 'type' => array( 'string', 'boolean' ) ), | |
| 348 | + 'openInNewTab' => array( 'type' => 'boolean' ), | |
| 349 | + ), | |
| 350 | + ), | |
| 351 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 352 | + 'readonly' => true, | |
| 353 | + ), | |
| 354 | + | |
| 355 | + 'attributes' => array( | |
| 356 | + 'description' => __( 'Attribute schema hosts render settings from: the JSON-expressible subset of a DataViews field per entry. User-facing strings are translatable.', 'gutenberg' ), | |
| 357 | + 'type' => array( 'array', 'null' ), | |
| 358 | + 'items' => array( | |
| 359 | + 'type' => 'object', | |
| 360 | + 'properties' => array( | |
| 361 | + 'id' => array( 'type' => 'string' ), | |
| 362 | + 'type' => array( 'type' => 'string' ), | |
| 363 | + 'label' => array( 'type' => 'string' ), | |
| 364 | + 'header' => array( 'type' => 'string' ), | |
| 365 | + 'description' => array( 'type' => 'string' ), | |
| 366 | + 'placeholder' => array( 'type' => 'string' ), | |
| 367 | + 'readOnly' => array( 'type' => 'boolean' ), | |
| 368 | + 'isDisabled' => array( 'type' => 'boolean' ), | |
| 369 | + 'enableSorting' => array( 'type' => 'boolean' ), | |
| 370 | + 'enableHiding' => array( 'type' => 'boolean' ), | |
| 371 | + 'enableGlobalSearch' => array( 'type' => 'boolean' ), | |
| 372 | + 'elements' => array( | |
| 373 | + 'type' => 'array', | |
| 374 | + 'items' => array( | |
| 375 | + 'type' => 'object', | |
| 376 | + 'properties' => array( | |
| 377 | + 'value' => array( 'type' => array( 'string', 'integer', 'number', 'boolean', 'null' ) ), | |
| 378 | + 'label' => array( 'type' => 'string' ), | |
| 379 | + 'description' => array( 'type' => 'string' ), | |
| 380 | + ), | |
| 381 | + ), | |
| 382 | + ), | |
| 383 | + 'filterBy' => array( 'type' => array( 'object', 'boolean' ) ), | |
| 384 | + 'format' => array( 'type' => 'object' ), | |
| 385 | + 'isValid' => array( 'type' => 'object' ), | |
| 386 | + 'Edit' => array( 'type' => array( 'string', 'object' ) ), | |
| 387 | + 'relevance' => array( | |
| 388 | + 'type' => 'string', | |
| 389 | + 'enum' => array( 'high', 'medium', 'low' ), | |
| 390 | + ), | |
| 391 | + ), | |
| 392 | + ), | |
| 393 | + 'context' => array( 'view', 'edit', 'embed' ), | |
| 394 | + 'readonly' => true, | |
| 395 | + ), | |
| 396 | + | |
| 397 | + 'keywords' => array( | |
| 398 | + 'description' => __( 'Alternative terms used to match the widget type when searching, e.g. "calendar" for an events widget. Translatable.', 'gutenberg' ), | |
| 399 | + 'type' => array( 'array', 'null' ), | |
| 400 | + 'items' => array( 'type' => 'string' ), | |
| 229 | 401 | 'context' => array( 'view', 'edit', 'embed' ), |
| 230 | 402 | 'readonly' => true, |
| 231 | 403 | ), |
| 232 | 404 | ), |