TableListScreenSetter.php
1.53 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
<?php
namespace AC\Controller;
use AC\Asset\Location\Absolute;
use AC\ColumnSize;
use AC\ListScreen;
use AC\ListScreenFactory;
use AC\ListScreenRepository\Storage;
use AC\Registerable;
use AC\Request;
use AC\Table;
use WP_Screen;
class TableListScreenSetter implements Registerable {
private $storage;
private $location;
private $list_screen_factory;
private $preference;
public function __construct(
Storage $storage,
Absolute $location,
ListScreenFactory $list_screen_factory,
Table\LayoutPreference $preference
) {
$this->storage = $storage;
$this->list_screen_factory = $list_screen_factory;
$this->location = $location;
$this->preference = $preference;
}
public function register() {
add_action( 'current_screen', [ $this, 'handle' ] );
}
public function handle( WP_Screen $wp_screen ): void {
$request = new Request();
$request->add_middleware(
new Middleware\ListScreenTable(
$this->storage,
$this->list_screen_factory,
$wp_screen,
$this->preference
)
);
$list_screen = $request->get( 'list_screen' );
if ( ! $list_screen instanceof ListScreen ) {
return;
}
if ( $list_screen->has_id() ) {
$this->preference->set( $list_screen->get_key(), (string) $list_screen->get_id() );
}
$table_screen = new Table\Screen(
$this->location,
$list_screen,
new ColumnSize\ListStorage( $this->storage ),
new ColumnSize\UserStorage( new ColumnSize\UserPreference( get_current_user_id() ) )
);
$table_screen->register();
do_action( 'ac/table', $table_screen );
}
}