AdminDashboardController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureDashboard() 0 3 1
A getName() 0 3 1
A home() 0 4 1
A index() 0 8 2
A configureMenuItems() 0 26 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\Attribute\Route;
20
use Symfony\Component\Security\Http\Attribute\IsGranted;
21
use Zikula\CoreBundle\Bundle\MetaData\MetaDataAwareBundleInterface;
22
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuInterface;
23
use Zikula\ThemeBundle\Helper\ResourceMenuProvider;
24
use function Symfony\Component\Translation\t;
25
26
#[IsGranted('ROLE_ADMIN')]
27
class AdminDashboardController extends AbstractThemedDashboardController
28
{
29
    protected function getName(): string
30
    {
31
        return 'admin';
32
    }
33
34
    public function configureDashboard(): Dashboard
35
    {
36
        return $this->getDashboardWithBranding(true, t('Administration'));
37
    }
38
39
    public function configureMenuItems(): iterable
40
    {
41
        yield MenuItem::linkToDashboard(t('Dashboard'), 'fa fa-gauge-high');
42
        yield MenuItem::linktoUrl(t('Website frontend'), 'fas fa-home', '/');
43
44
        $menuItemsByBundle = $this->extensionMenuCollector->getAllByContext(ExtensionMenuInterface::CONTEXT_ADMIN);
45
46
        foreach ($this->adminCategoryHelper->getCategories() as $category) {
47
            yield MenuItem::section($category->getName(), $category->getIcon());
48
            $bundleNames = $this->adminCategoryHelper->getBundleAssignments($category);
49
            foreach ($menuItemsByBundle as $bundleName => $extensionMenuItems) {
50
                $bundle = $this->kernel->getBundle($bundleName);
51
                if (!in_array($bundle->getName(), $bundleNames, true)) {
52
                    continue;
53
                }
54
                if (!($bundle instanceof MetaDataAwareBundleInterface)) {
55
                    continue;
56
                }
57
                $bundleInfo = $bundle->getMetaData();
58
                yield MenuItem::subMenu($bundleInfo->getDisplayName(), $bundleInfo->getIcon())->setSubItems(iterator_to_array($extensionMenuItems));
59
            }
60
        }
61
62
        $resources = ResourceMenuProvider::getResources();
63
        foreach ($resources as $resourceItem) {
64
            yield $resourceItem;
65
        }
66
    }
67
68
    #[Route('/admin', name: 'admin_home')]
69
    public function home(): Response
70
    {
71
        return $this->redirectToRoute('admin_dashboard', ['_locale' => $this->defaultLocale]);
72
    }
73
74
    #[Route('/admin/{_locale}', name: 'admin_dashboard')]
75
    public function index(): Response
76
    {
77
        if (!extension_loaded('intl')) {
78
            $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.'));
79
        }
80
81
        return parent::index();
82
    }
83
}
84