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

AdminDashboardController::home()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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
        $menuItemsByBundle = $this->extensionMenuCollector->getAllByContext(ExtensionMenuInterface::CONTEXT_ADMIN);
44
45
        foreach ($this->adminCategoryHelper->getCategories() as $category) {
46
            yield MenuItem::section($category->getName(), $category->getIcon());
47
            $bundleNames = $this->adminCategoryHelper->getBundleAssignments($category);
48
            foreach ($menuItemsByBundle as $bundleName => $extensionMenuItems) {
49
                $bundle = $this->kernel->getBundle($bundleName);
50
                if (!in_array($bundle->getName(), $bundleNames, true)) {
51
                    continue;
52
                }
53
                $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

53
                /** @scrutinizer ignore-call */ 
54
                $bundleInfo = $bundle->getMetaData();
Loading history...
54
                yield MenuItem::subMenu($bundleInfo->getDisplayName(), $bundleInfo->getIcon())->setSubItems(iterator_to_array($extensionMenuItems));
55
            }
56
        }
57
58
        $resources = ResourceMenuProvider::getResources();
59
        foreach ($resources as $resourceItem) {
60
            yield $resourceItem;
61
        }
62
    }
63
64
    #[Route('/admin', name: 'admin_home')]
65
    public function home(): Response
66
    {
67
        return $this->redirectToRoute('admin_dashboard', ['_locale' => $this->defaultLocale]);
68
    }
69
70
    #[Route('/admin/{_locale}', name: 'admin_dashboard')]
71
    public function index(): Response
72
    {
73
        if (!extension_loaded('intl')) {
74
            $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.'));
75
        }
76
77
        return parent::index();
78
    }
79
}
80