Prepares an element type for response.
Description
See also
Parameters
- $element_type
-
(awsmug\Torro_Forms\DB_Objects\Elements\Element_Types\Element_Type) (Required) Element type object.
- $request
-
(WP_REST_Request) (Required) Request object.
Return
(awsmug\Torro_Forms\DB_Objects\Elements\Element_Types\WP_REST_Response) Response object.
Source
File: src/db-objects/elements/element-types/rest-element-types-controller.php
public function prepare_item_for_response( $element_type, $request ) { $schema = $this->get_item_schema(); $data = array(); foreach ( $schema['properties'] as $property => $params ) { switch ( $property ) { case 'slug': case 'title': case 'description': case 'icon_css_class': case 'icon_svg_id': case 'icon_url': $data[ $property ] = call_user_func( array( $element_type, 'get_' . $property ) ); break; case 'non_input': $data[ $property ] = is_a( $element_type, Non_Input_Element_Type_Interface::class ); break; case 'evaluable': $data[ $property ] = is_a( $element_type, Choice_Element_Type_Interface::class ); break; case 'multifield': $data[ $property ] = is_a( $element_type, Multi_Field_Element_Type_Interface::class ); break; case 'sections': $sections = $element_type->get_settings_sections(); $data[ $property ] = array(); foreach ( $sections as $slug => $section ) { $data[ $property ][] = array_merge( array( 'slug' => $slug, ), $section ); } break; case 'fields': $fields = $element_type->get_settings_fields(); $data[ $property ] = array(); foreach ( $fields as $slug => $field ) { $data[ $property ][] = array_merge( array( 'slug' => $slug, ), $field ); } break; default: $data[ $property ] = null; } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $response->add_links( $this->prepare_links( $element_type ) ); return $response; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |