# ivyforms/0.5/backend/src/Services/Menu/MenuManager.php

The Innovative Form Builder – IvyForms, version 0.5. 91 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Menu/MenuManager.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.5/raw/backend/src/Services/Menu/MenuManager.php
- Modified: 2025-10-23T15:35:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Menu/MenuManager.php#L10-L20`.

```php
<?php

/**
 * @copyright © TMS-Plugins. All rights reserved.
 * @licence   See LICENCE.md for license details.
 */

namespace IvyForms\Services\Menu;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

use Closure;

class MenuManager
{
    private MenuMapper $menu;
    private MenuService $menuService;

    public function __construct(
        MenuService $menuService,
        MenuMapper $menu
    ) {
        $this->menuService = $menuService; // Dependency injected by PHP-DI
        $this->menu = $menu;
    }

    public function registerMenus(): void
    {
        // Hook into WordPress 'admin_menu' action
        add_action('admin_menu', [$this, 'addOptionsPages']);
    }

    public function addOptionsPages(): void
    {
        add_menu_page(
            'IvyForms',
            'IvyForms',
            // TODO - Add IvyForms capability
            'read',
            'ivyforms',
            null, // @phpstan-ignore argument.type
            IVYFORMS_URL . 'frontend/src/assets/images/logos/logo-only-admin.svg'
        );

        foreach (($this->menu)() as $menu) {
            $this->handleMenuItem($menu);
        }

        remove_submenu_page('ivyforms', 'ivyforms');
    }

    /**
     *
     * @param mixed[] $menu
     * */
    public function handleMenuItem(array $menu): void
    {
        $this->addSubmenuPage(
            $menu['parentSlug'],
            $menu['pageTitle'],
            $menu['menuTitle'],
            $menu['capability'],
            $menu['menuSlug'],
            function () use ($menu) {
                $this->menuService->render($menu['menuSlug']);
            }
        );
    }

    private function addSubmenuPage(
        string $parentSlug,
        string $pageTitle,
        string $menuTitle,
        string $capability,
        string $menuSlug,
        Closure $function
    ): void {
        add_submenu_page(
            $parentSlug,
            $pageTitle,
            $menuTitle,
            $capability,
            $menuSlug,
            $function
        );
    }
}

```
