Passed
Push — main ( 674e66...68245a )
by Axel
04:12
created

AdminDashboardController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 29
c 1
b 0
f 0
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configureDashboard() 0 3 1
A getName() 0 3 1
A index() 0 8 2
B configureMenuItems() 0 32 6
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 Symfony\Component\Security\Http\Attribute\IsGranted;
21
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuInterface;
22
use Zikula\ThemeBundle\Helper\ResourceMenuProvider;
23
use function Symfony\Component\Translation\t;
24
25
#[IsGranted('ROLE_ADMIN')]
26
class AdminDashboardController extends AbstractThemedDashboardController
27
{
28
    protected function getName(): string
29
    {
30
        return 'admin';
31
    }
32
33
    public function configureDashboard(): Dashboard
34
    {
35
        return parent::getDashboardWithBranding(true, t('Administration'));
36
    }
37
38
    public function configureMenuItems(): iterable
39
    {
40
        yield MenuItem::linkToDashboard(t('Dashboard'), 'fa fa-gauge-high');
41
        yield MenuItem::linktoUrl(t('Website frontend'), 'fas fa-home', '/');
42
43
        foreach ($this->adminCategoryHelper->getCategories() as $category) {
44
            yield MenuItem::section($category->getName(), $category->getIcon());
45
            $bundleNames = $this->adminCategoryHelper->getBundleAssignments($category);
46
            $adminBundles = $this->adminBundleHelper->getAdminCapableBundles();
47
            foreach ($adminBundles as $bundle) {
48
                if (!in_array($bundle->getName(), $bundleNames, true)) {
49
                    continue;
50
                }
51
52
                $bundleInfo = $bundle->getMetaData();
53
                [$menuTextUrl, $menuText] = $this->adminBundleHelper->getAdminRouteInformation($bundleInfo);
54
55
                $bundleName = (string) $bundle->getName();
56
                $extensionMenuItems = $this->extensionMenuCollector->get($bundleName, ExtensionMenuInterface::CONTEXT_ADMIN);
57
                $isSubMenu = isset($extensionMenuItems);
58
59
                if ($isSubMenu) {
60
                    yield MenuItem::subMenu($menuText, $bundleInfo->getIcon())->setSubItems(iterator_to_array($extensionMenuItems));
61
                } else {
62
                    yield MenuItem::linktoRoute($menuText, $bundleInfo->getIcon(), $menuTextUrl);
63
                }
64
            }
65
        }
66
67
        $resources = ResourceMenuProvider::getResources();
68
        foreach ($resources as $resourceItem) {
69
            yield $resourceItem;
70
        }
71
    }
72
73
    #[Route('/admin', name: 'admin_dashboard')]
74
    public function index(): Response
75
    {
76
        if (!extension_loaded('intl')) {
77
            $this->addFlash('error', t('WARNING: The PHP extension intl is not loaded. All functions using this will default to "en". Seek assistance from your provider to install.'));
78
        }
79
80
        return parent::index();
81
    }
82
}
83