ColumnRequest
2 years ago
ListScreen
2 years ago
Middleware
2 years ago
AjaxColumnModalValue.php
2 years ago
AjaxColumnRequest.php
2 years ago
AjaxColumnValue.php
2 years ago
AjaxGeneralOptions.php
2 years ago
AjaxRequestCustomFieldKeys.php
2 years ago
AjaxScreenOptions.php
2 years ago
ColumnRequest.php
2 years ago
DefaultColumns.php
2 years ago
ListScreenRestoreColumns.php
2 years ago
RestoreSettingsRequest.php
2 years ago
TableListScreenSetter.php
2 years ago
TableListScreenSetter.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Controller; |
| 4 | |
| 5 | use AC\Asset\Location\Absolute; |
| 6 | use AC\ColumnSize; |
| 7 | use AC\ListScreen; |
| 8 | use AC\ListScreenFactory; |
| 9 | use AC\ListScreenRepository\Storage; |
| 10 | use AC\Registerable; |
| 11 | use AC\Request; |
| 12 | use AC\Settings\General\EditButton; |
| 13 | use AC\Table; |
| 14 | use WP_Screen; |
| 15 | |
| 16 | class TableListScreenSetter implements Registerable |
| 17 | { |
| 18 | |
| 19 | private $storage; |
| 20 | |
| 21 | private $location; |
| 22 | |
| 23 | private $list_screen_factory; |
| 24 | |
| 25 | private $preference; |
| 26 | |
| 27 | private $primary_column_factory; |
| 28 | |
| 29 | private $edit_button; |
| 30 | |
| 31 | public function __construct( |
| 32 | Storage $storage, |
| 33 | Absolute $location, |
| 34 | ListScreenFactory $list_screen_factory, |
| 35 | Table\LayoutPreference $preference, |
| 36 | Table\PrimaryColumnFactory $primary_column_factory, |
| 37 | EditButton $edit_button |
| 38 | ) { |
| 39 | $this->storage = $storage; |
| 40 | $this->list_screen_factory = $list_screen_factory; |
| 41 | $this->location = $location; |
| 42 | $this->preference = $preference; |
| 43 | $this->primary_column_factory = $primary_column_factory; |
| 44 | $this->edit_button = $edit_button; |
| 45 | } |
| 46 | |
| 47 | public function register(): void |
| 48 | { |
| 49 | add_action('current_screen', [$this, 'handle']); |
| 50 | } |
| 51 | |
| 52 | public function handle(WP_Screen $wp_screen): void |
| 53 | { |
| 54 | $request = new Request(); |
| 55 | |
| 56 | $request->add_middleware( |
| 57 | new Middleware\ListScreenTable( |
| 58 | $this->storage, |
| 59 | $this->list_screen_factory, |
| 60 | $wp_screen, |
| 61 | $this->preference |
| 62 | ) |
| 63 | ); |
| 64 | |
| 65 | $list_screen = $request->get('list_screen'); |
| 66 | |
| 67 | if ( ! $list_screen instanceof ListScreen) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if ($list_screen->has_id()) { |
| 72 | $this->preference->set($list_screen->get_key(), (string)$list_screen->get_id()); |
| 73 | } |
| 74 | |
| 75 | $table_screen = new Table\Screen( |
| 76 | $this->location, |
| 77 | $list_screen, |
| 78 | new ColumnSize\ListStorage($this->storage), |
| 79 | new ColumnSize\UserStorage(new ColumnSize\UserPreference()), |
| 80 | $this->primary_column_factory, |
| 81 | $this->edit_button |
| 82 | ); |
| 83 | $table_screen->register(); |
| 84 | |
| 85 | do_action('ac/table', $table_screen); |
| 86 | } |
| 87 | |
| 88 | } |