← All changes
|
modules/components/components-rest-api.php
+21
-33
4.1.0-dev1
→
4.0.0-dev3
View file →
| @@ -147,15 +147,12 @@ | ||
| 147 | 147 | 'methods' => 'GET', |
| 148 | 148 | 'callback' => fn( $request ) => $this->route_wrapper( fn() => $this->get_overridable_props( $request ) ), |
| 149 | 149 | 'permission_callback' => fn() => current_user_can( 'edit_posts' ), |
| 150 | 150 | 'args' => [ |
| 151 | - 'componentIds' => [ | |
| 152 | - 'type' => 'array', | |
| 153 | - 'items' => [ | |
| 154 | - 'type' => 'integer', | |
| 155 | - ], | |
| 151 | + 'componentId' => [ | |
| 152 | + 'type' => 'integer', | |
| 156 | 153 | 'required' => true, |
| 157 | - 'description' => 'The component IDs to get overridable props for', | |
| 154 | + 'description' => 'The component ID to get overridable props for', | |
| 158 | 155 | ], |
| 159 | 156 | ], |
| 160 | 157 | ], |
| 161 | 158 | ] ); |
| @@ -313,42 +310,33 @@ | ||
| 313 | 310 | return Response_Builder::make( $styles )->build(); |
| 314 | 311 | } |
| 315 | 312 | |
| 316 | 313 | private function get_overridable_props( \WP_REST_Request $request ) { |
| 317 | - $component_ids = $request->get_param( 'componentIds' ); | |
| 314 | + $component_id = (int) $request->get_param( 'componentId' ); | |
| 318 | 315 | |
| 319 | - $data = []; | |
| 320 | - $errors = []; | |
| 316 | + if ( ! $component_id ) { | |
| 317 | + return Error_Builder::make( 'invalid_component_id' ) | |
| 318 | + ->set_status( 400 ) | |
| 319 | + ->set_message( __( 'Invalid component ID', 'elementor' ) ) | |
| 320 | + ->build(); | |
| 321 | + } | |
| 321 | 322 | |
| 322 | - foreach ( $component_ids as $component_id ) { | |
| 323 | - $component_id = (int) $component_id; | |
| 323 | + $document = $this->get_repository()->get( $component_id ); | |
| 324 | 324 | |
| 325 | - /** @var Component $document */ | |
| 326 | - $document = $this->get_repository()->get( $component_id ); | |
| 325 | + if ( ! $document ) { | |
| 326 | + return Error_Builder::make( 'component_not_found' ) | |
| 327 | + ->set_status( 404 ) | |
| 328 | + ->set_message( __( 'Component not found', 'elementor' ) ) | |
| 329 | + ->build(); | |
| 330 | + } | |
| 327 | 331 | |
| 328 | - if ( ! $document ) { | |
| 329 | - $errors[ $component_id ] = 'component_not_found'; | |
| 330 | - continue; | |
| 331 | - } | |
| 332 | + $overridable = $document->get_json_meta( Component::OVERRIDABLE_PROPS_META_KEY ) ?? null; | |
| 332 | 333 | |
| 333 | - // This is a fix for the case where overridable props in element settings where migrated | |
| 334 | - // but the overridable props metadata were not aligned with the new origin values. | |
| 335 | - // In version 4.0.1, we fixed this by running the align_overridable_props_with_elements method after the migration. | |
| 336 | - $document_version = $document->get_elementor_version(); | |
| 337 | - $overridable_props_migration_fix_version = '4.0.1'; | |
| 338 | - $should_align_overridable_props = version_compare( $document_version, $overridable_props_migration_fix_version, '<=' ); | |
| 339 | - if ( $should_align_overridable_props ) { | |
| 340 | - $document->align_overridable_props_with_elements(); | |
| 341 | - } | |
| 342 | - | |
| 343 | - $overridable = $document->get_json_meta( Component::OVERRIDABLE_PROPS_META_KEY ); | |
| 344 | - | |
| 345 | - $data[ $component_id ] = empty( $overridable ) ? null : $overridable; | |
| 334 | + if ( empty( $overridable ) ) { | |
| 335 | + $overridable = null; | |
| 346 | 336 | } |
| 347 | 337 | |
| 348 | - return Response_Builder::make( $data ) | |
| 349 | - ->set_meta( [ 'errors' => $errors ] ) | |
| 350 | - ->build(); | |
| 338 | + return Response_Builder::make( $overridable )->build(); | |
| 351 | 339 | } |
| 352 | 340 | |
| 353 | 341 | private function create_components( \WP_REST_Request $request ) { |
| 354 | 342 | if ( ! Components_Access_Controller::can_create() ) { |