PostParent.php
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace ACP\Editing\Service\Post;
use AC;
use ACP\Editing\PaginatedOptions;
use ACP\Editing\Service\BasicStorage;
use ACP\Editing\Storage;
use ACP\Editing\View;
use ACP\Helper\Select;
class PostParent extends BasicStorage implements PaginatedOptions {
/**
* @var string
*/
private $post_type;
public function __construct( $post_type ) {
parent::__construct( new Storage\Post\Field( 'post_parent' ) );
$this->post_type = (string) $post_type;
}
public function get_view( string $context ): ?View {
$view = new View\AjaxSelect();
return $view->set_clear_button( true );
}
public function get_paginated_options( $s, $paged, $id = null ) {
$entities = new Select\Entities\Post( [
's' => $s,
'paged' => $paged,
'post_type' => $this->post_type,
] );
return new AC\Helper\Select\Options\Paginated(
$entities,
new Select\Formatter\PostTitle( $entities )
);
}
public function get_value( int $id ) {
$parent = get_post( parent::get_value( $id ) );
if ( ! $parent ) {
return false;
}
return [
$parent->ID => $parent->post_title,
];
}
}