TableListScreenSetter.php
1.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
<?php
namespace AC\Controller;
use AC\Asset\Location\Absolute;
use AC\ColumnSize;
use AC\ListScreenRepository\Storage;
use AC\ListScreenTypes;
use AC\Registerable;
use AC\Request;
use AC\Table;
use AC\Type\ListScreenId;
use WP_Screen;
class TableListScreenSetter implements Registerable {
private $storage;
private $location;
private $preference;
public function __construct(
Storage $storage,
Absolute $location,
Table\LayoutPreference $preference
) {
$this->storage = $storage;
$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,
$wp_screen,
$this->preference
)
);
$list_key = $request->get( 'list_key' );
$list_id = $request->get( 'list_id' );
$list_screen = null;
if ( ListScreenId::is_valid_id( $list_id ) ) {
$list_screen = $this->storage->find( new ListScreenId( $list_id ) );
}
if ( ! $list_screen && $list_key && is_string( $list_key ) ) {
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
}
if ( ! $list_screen ) {
return;
}
if ( $list_screen->has_id() ) {
$this->preference->set( $list_screen->get_key(), $list_screen->get_id()->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 );
}
}