AdminGeneralOptionsGet.php
3 months ago
AdminGeneralOptionsPersist.php
3 months ago
CustomFieldKeys.php
3 months ago
EditorMenuFavorites.php
3 months ago
EditorMenuStatus.php
3 months ago
ExtendedValue.php
3 months ago
IntegrationToggle.php
3 months ago
Integrations.php
3 months ago
ListScreenAddColumn.php
3 months ago
ListScreenDelete.php
3 months ago
ListScreenOriginalColumns.php
3 months ago
ListScreenSave.php
3 months ago
ListScreenSelectColumn.php
3 months ago
ListScreenSettings.php
3 months ago
NetworkPostStati.php
3 months ago
NumberFormat.php
3 months ago
RestoreSettingsRequest.php
3 months ago
ScreenOptions.php
3 months ago
EditorMenuFavorites.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\RequestHandler\Ajax; |
| 6 | |
| 7 | use AC\Capabilities; |
| 8 | use AC\Nonce; |
| 9 | use AC\Request; |
| 10 | use AC\RequestAjaxHandler; |
| 11 | use AC\Response\Json; |
| 12 | use AC\Storage; |
| 13 | use AC\Type\TableId; |
| 14 | |
| 15 | class EditorMenuFavorites implements RequestAjaxHandler |
| 16 | { |
| 17 | |
| 18 | private Storage\Repository\EditorFavorites $favorite_repository; |
| 19 | |
| 20 | public function __construct(Storage\Repository\EditorFavorites $favorite_repository) |
| 21 | { |
| 22 | $this->favorite_repository = $favorite_repository; |
| 23 | } |
| 24 | |
| 25 | public function handle(): void |
| 26 | { |
| 27 | if ( ! current_user_can(Capabilities::MANAGE)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $request = new Request(); |
| 32 | $response = new Json(); |
| 33 | |
| 34 | if ( ! (new Nonce\Ajax())->verify($request)) { |
| 35 | $response->error(); |
| 36 | } |
| 37 | |
| 38 | $list_key = new TableId($request->get('list_key')); |
| 39 | |
| 40 | 'favorite' === $request->get('status') |
| 41 | ? $this->favorite_repository->add($list_key) |
| 42 | : $this->favorite_repository->remove($list_key); |
| 43 | |
| 44 | $response->success(); |
| 45 | } |
| 46 | |
| 47 | } |