1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\Menus; |
6
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Admin\MenuPages\AbstractMenuPage; |
8
|
|
|
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Admin menu class |
12
|
|
|
*/ |
13
|
|
|
abstract class AbstractMenu |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array<AbstractMenuPage> |
17
|
|
|
*/ |
18
|
|
|
protected array $menuPageObjects; |
19
|
|
|
|
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
$instanceManager = InstanceManagerFacade::getInstance(); |
23
|
|
|
$this->menuPageObjects = array_map( |
24
|
|
|
function ($menuPageClass) use ($instanceManager): AbstractMenuPage { |
25
|
|
|
/** |
26
|
|
|
* @var AbstractMenuPage |
27
|
|
|
*/ |
28
|
|
|
$menuPageObject = $instanceManager->getInstance($menuPageClass); |
29
|
|
|
return $menuPageObject; |
30
|
|
|
}, |
31
|
|
|
$this->getMenuPageClasses() |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
abstract public static function getName(): string; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string[] |
39
|
|
|
*/ |
40
|
|
|
protected function getMenuPageClasses(): array |
41
|
|
|
{ |
42
|
|
|
return []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Initialize the endpoints |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function initialize(): void |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Low priority to execute before adding the menus for the CPTs |
54
|
|
|
*/ |
55
|
|
|
\add_action( |
56
|
|
|
'admin_menu', |
57
|
|
|
[$this, 'addMenuPagesTop'], |
58
|
|
|
9 |
59
|
|
|
); |
60
|
|
|
/** |
61
|
|
|
* High priority to execute after adding the menus for the CPTs |
62
|
|
|
*/ |
63
|
|
|
\add_action( |
64
|
|
|
'admin_menu', |
65
|
|
|
[$this, 'addMenuPagesBottom'], |
66
|
|
|
20 |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Initialize my menu pages |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
foreach ($this->menuPageObjects as $menuPageObject) { |
75
|
|
|
$menuPageObject->initialize(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
public function addMenuPagesTop(): void |
79
|
|
|
{ |
80
|
|
|
// Initially empty |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function addMenuPagesBottom(): void |
84
|
|
|
{ |
85
|
|
|
// Initially empty |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|