AjaxScreenOption.php
1.12 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
<?php
namespace ACP\QuickAdd\Controller;
use AC;
use AC\ListScreenRepository\Storage;
use AC\Registerable;
use AC\Type\ListScreenId;
use ACP\QuickAdd\Table;
class AjaxScreenOption implements Registerable {
private $storage;
private $preference_button;
public function __construct( Storage $storage, Table\Preference\ShowButton $preference_button ) {
$this->storage = $storage;
$this->preference_button = $preference_button;
}
public function register() {
$this->get_ajax_handler()->register();
}
protected function get_ajax_handler(): AC\Ajax\Handler {
$handler = new AC\Ajax\Handler();
$handler->set_action( 'acp_new_inline_show_button' )
->set_callback( [ $this, 'update_table_option' ] );
return $handler;
}
public function update_table_option(): void {
$this->get_ajax_handler()->verify_request();
$list_screen = $this->storage->find_by_user( new ListScreenId( filter_input( INPUT_POST, 'layout' ) ), wp_get_current_user() );
if ( ! $list_screen ) {
exit;
}
echo $this->preference_button->set( $list_screen->get_key(), 'true' === filter_input( INPUT_POST, 'value' ) );
exit;
}
}