Taxonomy.php
3.68 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
declare(strict_types=1);
namespace ACP\ListScreen;
use AC;
use AC\ColumnRepository;
use AC\MetaType;
use AC\Type\Uri;
use AC\WpListTableFactory;
use ACP\Column;
use ACP\Editing;
use ACP\Editing\BulkDelete\Deletable;
use ACP\Export;
use ACP\Filtering;
use ACP\Sorting;
use ACP\Sorting\AbstractModel;
use ACP\Sorting\Strategy;
class Taxonomy extends AC\ListScreen
implements Editing\ListScreen, Export\ListScreen, Filtering\ListScreen, Sorting\ListScreen,
Editing\BulkDelete\ListScreen, AC\ListScreen\ManageValue, AC\ListScreen\ListTable
{
public const KEY_PREFIX = 'wp-taxonomy_';
private $taxonomy;
public function __construct(string $taxonomy)
{
parent::__construct(self::KEY_PREFIX . $taxonomy, 'edit-' . $taxonomy);
$this->taxonomy = $taxonomy;
$this->group = 'taxonomy';
$this->set_meta_type(MetaType::TERM);
}
public function get_taxonomy(): string
{
return $this->taxonomy;
}
public function list_table(): AC\ListTable
{
return new AC\ListTable\Taxonomy(
(new WpListTableFactory())->create_taxonomy_table($this->get_screen_id()),
$this->taxonomy
);
}
public function manage_value(): AC\Table\ManageValue
{
return new AC\Table\ManageValue\Taxonomy($this->taxonomy, new ColumnRepository($this));
}
public function get_label(): ?string
{
return $this->get_taxonomy_label_var('name');
}
public function get_singular_label(): ?string
{
return $this->get_taxonomy_label_var('singular_name');
}
private function get_post_type_tax(): ?string
{
$post_type = null;
$object_type = $this->get_taxonomy_var('object_type');
if ($object_type && post_type_exists(reset($object_type))) {
$post_type = (string)$object_type[0];
}
return $post_type;
}
public function get_table_url(): Uri
{
return new AC\Type\Url\ListTable\Taxonomy(
$this->taxonomy,
$this->has_id() ? $this->get_id() : null,
$this->get_post_type_tax()
);
}
private function get_taxonomy_label_var($var)
{
$taxonomy = get_taxonomy($this->taxonomy);
return $taxonomy->labels->{$var} ?? null;
}
private function get_taxonomy_var(string $var)
{
$taxonomy = get_taxonomy($this->taxonomy);
return $taxonomy->{$var} ?? null;
}
protected function register_column_types(): void
{
$this->register_column_types_from_list([
Column\CustomField::class,
Column\Actions::class,
Column\Taxonomy\Count::class,
Column\Taxonomy\CountForPostType::class,
Column\Taxonomy\CustomDescription::class,
Column\Taxonomy\Description::class,
Column\Taxonomy\Excerpt::class,
Column\Taxonomy\ID::class,
Column\Taxonomy\Links::class,
Column\Taxonomy\Menu::class,
Column\Taxonomy\Name::class,
Column\Taxonomy\Posts::class,
Column\Taxonomy\Slug::class,
Column\Taxonomy\TaxonomyParent::class,
]);
}
public function editing()
{
return new Editing\Strategy\Taxonomy();
}
public function deletable()
{
return new Deletable\Taxonomy($this->taxonomy);
}
public function filtering($model)
{
return new Filtering\Strategy\Taxonomy($model);
}
public function sorting(AbstractModel $model): Strategy
{
return new Sorting\Strategy\Taxonomy($model, $this->taxonomy);
}
public function export()
{
return new Export\Strategy\Taxonomy($this);
}
}