PHP code example of shegroup / menu-bundle

1. Go to this page and download the library: Download shegroup/menu-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shegroup / menu-bundle example snippets


// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new SheGroup\MenuBundle\SheGroupMenuBundle(),
        );

        // ...
    }

    // ...
}




declare(strict_types=1);

namespace AppBundle\Menu;

use SheGroup\MenuBundle\Menu\MenuInterface;

final class MainMenu implements MenuInterface
{
    public function getMenu(): array
    {
        $contact = ...

        return [
            'class' => 'sidebar-menu',
            'items' => [
                [
                    'name' => 'Users',
                    'icon' => 'fa fa-user',
                    'items' => [
                        [
                            'name' => 'Admins',
                            'route' => 'admin_core_user_admin_list',
                            'active_routes' => [
                                'admin_core_user_admin_[\w]+',
                            ],
                        ],
                        [
                            'name' => 'Clients',
                            'route' => 'admin_core_user_client_list',
                            'active_routes' => [
                                'admin_core_user_client_[\w]+',
                                static function (Closure $matcher) use ($contact) {
                                    if (!$matcher->__invoke('_app.contact[\w\_\.]+')) {
                                        return false;
                                    }
                                    if ($contact instanceof Person) {
                                        return PersonType::isClientRelated($contact->getPersonType());
                                    }
            
                                    return $contact instanceof Client;
                                },
                            ],
                        ],
                    ],
                ],                
                [
                    'name' => 'Groups',
                    'route' => 'admin_core_group_list',
                    'icon' => 'fa fa-users',
                    'active_routes' => [
                        'admin_core_group_[\w]+',
                        '_admin.group.[\w\.]',
                    ],
                ],
            ],
        ];
    }
}