PluginProbe
The Innovative Form Builder – IvyForms / 0.6
The Innovative Form Builder – IvyForms v0.6
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Menu / MenuManager.php

MenuManager.php in The Innovative Form Builder – IvyForms 0.6, at backend/src/Services/Menu/MenuManager.php

91 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Services\Menu;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use Closure;
16
17 class MenuManager
18 {
19 private MenuMapper $menu;
20 private MenuService $menuService;
21
22 public function __construct(
23 MenuService $menuService,
24 MenuMapper $menu
25 ) {
26 $this->menuService = $menuService; // Dependency injected by PHP-DI
27 $this->menu = $menu;
28 }
29
30 public function registerMenus(): void
31 {
32 // Hook into WordPress 'admin_menu' action
33 add_action('admin_menu', [$this, 'addOptionsPages']);
34 }
35
36 public function addOptionsPages(): void
37 {
38 add_menu_page(
39 'IvyForms',
40 'IvyForms',
41 // TODO - Add IvyForms capability
42 'read',
43 'ivyforms',
44 null, // @phpstan-ignore argument.type
45 IVYFORMS_URL . 'frontend/src/assets/images/logos/logo-only-admin.svg'
46 );
47
48 foreach (($this->menu)() as $menu) {
49 $this->handleMenuItem($menu);
50 }
51
52 remove_submenu_page('ivyforms', 'ivyforms');
53 }
54
55 /**
56 *
57 * @param mixed[] $menu
58 * */
59 public function handleMenuItem(array $menu): void
60 {
61 $this->addSubmenuPage(
62 $menu['parentSlug'],
63 $menu['pageTitle'],
64 $menu['menuTitle'],
65 $menu['capability'],
66 $menu['menuSlug'],
67 function () use ($menu) {
68 $this->menuService->render($menu['menuSlug']);
69 }
70 );
71 }
72
73 private function addSubmenuPage(
74 string $parentSlug,
75 string $pageTitle,
76 string $menuTitle,
77 string $capability,
78 string $menuSlug,
79 Closure $function
80 ): void {
81 add_submenu_page(
82 $parentSlug,
83 $pageTitle,
84 $menuTitle,
85 $capability,
86 $menuSlug,
87 $function
88 );
89 }
90 }
91