| 1 |
<?php |
| 2 |
namespace Elementor\Data\V2\Base\Endpoint\Index; |
| 3 |
|
| 4 |
use Elementor\Data\V2\Base\Endpoint\Index; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly. |
| 8 |
} |
| 9 |
/** |
| 10 |
* Class SubIndexEndpoint is default `Base\Endpoint\Index` of `SubController`, |
| 11 |
* it was created to handle base_route and format for child controller, index endpoint. |
| 12 |
* In case `SubController` were used and the default method of `Controller::register_index_endpoint` ain't overridden. |
| 13 |
* this class will give support to have such routes, eg: 'alpha/{id}/beta/{sub_id}' without using additional endpoints. |
| 14 |
*/ |
| 15 |
final class Sub_Index_Endpoint extends Index { |
| 16 |
/*** |
| 17 |
* @var \Elementor\Data\V2\Base\Controller |
| 18 |
*/ |
| 19 |
public $controller; |
| 20 |
|
| 21 |
public function get_format() { |
| 22 |
return $this->controller->get_parent()->get_name() . '/{id}/' . $this->controller->get_name() . '/{sub_id}'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_base_route() { |
| 26 |
$parent_controller = $this->controller->get_parent(); |
| 27 |
$parent_index_endpoint = $parent_controller->index_endpoint; |
| 28 |
$parent_controller_route = ''; |
| 29 |
|
| 30 |
// In case `$parent_index_endpoint` is AllChildren, it cannot support id_arg_name. |
| 31 |
if ( ! $parent_index_endpoint instanceof AllChildren ) { |
| 32 |
$parent_controller_route = "(?P<{$parent_index_endpoint->id_arg_name}>[\w]+)"; |
| 33 |
} |
| 34 |
|
| 35 |
return untrailingslashit('/' . implode( '/', array_filter( [ |
| 36 |
trim( $parent_index_endpoint->get_base_route(), '/' ), |
| 37 |
$parent_controller_route, |
| 38 |
$this->controller->get_name(), |
| 39 |
$this->get_public_name(), |
| 40 |
] ) ) ); |
| 41 |
} |
| 42 |
} |
| 43 |
|