| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Checklist\Data\Endpoints; |
| 3 |
|
| 4 |
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base; |
| 5 |
use Elementor\Modules\Checklist\Steps\Step_Base; |
| 6 |
use Elementor\Modules\Checklist\Steps_Manager; |
| 7 |
use Elementor\Modules\Checklist\Module as Checklist_Module; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Steps extends Endpoint_Base { |
| 14 |
|
| 15 |
public function get_name(): string { |
| 16 |
return 'steps'; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_format(): string { |
| 20 |
return 'checklist'; |
| 21 |
} |
| 22 |
|
| 23 |
public function get_items( $request ) { |
| 24 |
return $this->get_checklist_data(); |
| 25 |
} |
| 26 |
|
| 27 |
public function update_item( $id, $request ) { |
| 28 |
$checklist_module = Checklist_Module::instance(); |
| 29 |
$step = $checklist_module->get_steps_manager()->get_step_by_id( $id ); |
| 30 |
$step->update_step( $request->get_json_params() ); |
| 31 |
|
| 32 |
return [ |
| 33 |
'data' => 'success', |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
private function get_checklist_data(): array { |
| 38 |
$checklist_module = Checklist_Module::instance(); |
| 39 |
$steps_data = $checklist_module->get_steps_manager()->get_steps_for_frontend(); |
| 40 |
|
| 41 |
return [ |
| 42 |
'data' => $steps_data, |
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
protected function register() { |
| 47 |
parent::register(); |
| 48 |
|
| 49 |
$this->register_item_route(); |
| 50 |
$this->register_item_route( \WP_REST_Server::EDITABLE, [ |
| 51 |
'id_arg_name' => 'id', |
| 52 |
'id_arg_type_regex' => '[\w\-\_]+', |
| 53 |
'id' => [ |
| 54 |
'type' => 'string', |
| 55 |
'description' => 'The step id.', |
| 56 |
'required' => true, |
| 57 |
'validate_callback' => function ( $step_id ) { |
| 58 |
return in_array( $step_id, Steps_Manager::get_step_ids() ); |
| 59 |
}, |
| 60 |
], |
| 61 |
] ); |
| 62 |
} |
| 63 |
} |
| 64 |
|