Passed
Push — main ( 20d6d7...2f23ef )
by Axel
04:07
created

UserDashboardController::configureMenuItems()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 16
rs 9.9
cc 4
nc 5
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeBundle\Controller\Dashboard;
15
16
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
17
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Routing\Annotation\Route;
20
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuInterface;
21
use function Symfony\Component\Translation\t;
22
23
class UserDashboardController extends AbstractThemedDashboardController
24
{
25
    protected function getName(): string
26
    {
27
        return 'user';
28
    }
29
30
    public function configureDashboard(): Dashboard
31
    {
32
        return parent::getDashboardWithBranding(true);
33
    }
34
35
    public function configureMenuItems(): iterable
36
    {
37
        yield MenuItem::linkToDashboard(t('Home'), 'fas fa-home');
38
        yield MenuItem::linkToUrl(t('Administration'), 'fas fa-wrench', '/admin')->setPermission('ROLE_ADMIN');
39
40
        yield MenuItem::section();
41
        $menuItemsByBundle = $this->extensionMenuCollector->getAllByContext(ExtensionMenuInterface::CONTEXT_USER);
42
        foreach ($menuItemsByBundle as $bundleName => $extensionMenuItems) {
43
            $bundle = $this->kernel->getBundle($bundleName);
44
45
            $menuItems = is_array($extensionMenuItems) ? $extensionMenuItems : iterator_to_array($extensionMenuItems);
46
            if (!count($menuItems)) {
47
                continue;
48
            }
49
            $bundleInfo = $bundle->getMetaData();
0 ignored issues
show
Bug introduced by
The method getMetaData() does not exist on Symfony\Component\HttpKe...\Bundle\BundleInterface. It seems like you code against a sub-type of Symfony\Component\HttpKe...\Bundle\BundleInterface such as Zikula\CoreBundle\AbstractModule. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            /** @scrutinizer ignore-call */ 
50
            $bundleInfo = $bundle->getMetaData();
Loading history...
50
            yield MenuItem::subMenu($bundleInfo->getDisplayName(), $bundleInfo->getIcon())->setSubItems($menuItems);
51
            /*foreach ($menuItems as $item) {
52
                yield $item;
53
            }*/
54
        }
55
    }
56
57
    #[Route('/', name: 'user_home')]
58
    public function home(): Response
59
    {
60
        return $this->redirectToRoute('user_dashboard', ['_locale' => $this->defaultLocale]);
61
    }
62
63
    #[Route('/{_locale}', name: 'user_dashboard')]
64
    public function index(): Response
65
    {
66
        return parent::index();
67
    }
68
}
69