| 1 |
<?php |
| 2 |
namespace Elementor\App\Modules\KitLibrary\Data\Kits\Endpoints; |
| 3 |
|
| 4 |
use Elementor\App\Modules\KitLibrary\Data\Kits\Controller; |
| 5 |
use Elementor\Data\V2\Base\Endpoint; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* @property Controller $controller |
| 13 |
*/ |
| 14 |
class Favorites extends Endpoint { |
| 15 |
public function get_name() { |
| 16 |
return 'favorites'; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_format() { |
| 20 |
return 'kits/favorites/{id}'; |
| 21 |
} |
| 22 |
|
| 23 |
protected function register() { |
| 24 |
$args = [ |
| 25 |
'id_arg_type_regex' => '[\w]+', |
| 26 |
]; |
| 27 |
|
| 28 |
$this->register_item_route( \WP_REST_Server::CREATABLE, $args ); |
| 29 |
$this->register_item_route( \WP_REST_Server::DELETABLE, $args ); |
| 30 |
} |
| 31 |
|
| 32 |
public function create_item( $id, $request ) { |
| 33 |
$repository = $this->controller->get_repository(); |
| 34 |
$kit = $repository->add_to_favorites( $id ); |
| 35 |
|
| 36 |
return [ |
| 37 |
'data' => $kit, |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
public function delete_item( $id, $request ) { |
| 42 |
$repository = $this->controller->get_repository(); |
| 43 |
|
| 44 |
$kit = $repository->remove_from_favorites( $id ); |
| 45 |
|
| 46 |
return [ |
| 47 |
'data' => $kit, |
| 48 |
]; |
| 49 |
} |
| 50 |
} |
| 51 |
|