Taxonomy.php
1.3 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
57
58
59
60
61
62
63
<?php
namespace ACP\Editing\Service\Post;
use ACP\Editing\PaginatedOptions;
use ACP\Editing\Service;
use ACP\Editing\Storage;
use ACP\Editing\View;
use ACP\Helper\Select\Paginated\Terms;
class Taxonomy implements Service, PaginatedOptions {
/**
* @var string
*/
protected $taxonomy;
/**
* @var bool
*/
private $enable_term_creation;
/**
* @var Storage\Post\Taxonomy
*/
private $storage;
public function __construct( string $taxonomy, bool $enable_term_creation ) {
$this->taxonomy = $taxonomy;
$this->enable_term_creation = $enable_term_creation;
$this->storage = new Storage\Post\Taxonomy( $taxonomy, $enable_term_creation );
}
public function get_value( int $id ) {
return $this->storage->get( $id );
}
public function update( int $id, $data ): void {
$this->storage->update( $id, $data );
}
public function get_view( string $context ): ?View {
$view = new View\AjaxSelect();
$view->set_multiple( 'post_format' !== $this->taxonomy )
->set_clear_button( true );
if ( $this->enable_term_creation ) {
$view->set_tags( true );
}
if ( $context === self::CONTEXT_BULK ) {
$view->has_methods( true );
}
return $view;
}
public function get_paginated_options( $search, $page, $id = null ) {
return new Terms( $search, $page, [ $this->taxonomy ] );
}
}