Passed
Push — main ( d414ab...947d8d )
by Axel
04:23
created

AbstractThemedDashboardController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getDashboardWithBranding() 0 22 6
A configureAssets() 0 5 1
A configureCrud() 0 4 1
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\Assets;
17
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
18
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
19
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
20
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
21
use Symfony\Component\HttpKernel\KernelInterface;
22
use Zikula\Bundle\CoreBundle\Site\SiteDefinitionInterface;
23
use Zikula\PermissionsBundle\Api\ApiInterface\PermissionApiInterface;
24
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuCollector;
25
use Zikula\ThemeBundle\Helper\AdminBundleHelper;
26
use Zikula\ThemeBundle\Helper\AdminCategoryHelper;
27
28
abstract class AbstractThemedDashboardController extends AbstractDashboardController
29
{
30
    public function __construct(
31
        protected readonly KernelInterface $kernel,
32
        protected readonly AdminUrlGenerator $adminUrlGenerator,
33
        protected readonly AdminCategoryHelper $adminCategoryHelper,
34
        protected readonly AdminBundleHelper $adminBundleHelper,
35
        protected readonly ExtensionMenuCollector $extensionMenuCollector,
36
        protected readonly PermissionApiInterface $permissionApi,
37
        protected readonly SiteDefinitionInterface $site
38
    ) {
39
    }
40
41
    abstract protected function getName(): string;
42
43
    protected function getDashboardWithBranding(bool $showLogo, ?string $title = null): Dashboard
44
    {
45
        $siteName = $this->site->getName();
46
        if ($showLogo) {
47
            $logoPath = $this->site->getMobileLogoPath() ?? $this->site->getLogoPath();
48
            $logo = $logoPath ? '<img src="' . $logoPath . '" alt="' . str_replace('"', '', $siteName) . '" /><br />' : '';
49
        } else {
50
            $logo = '';
51
        }
52
53
        $titlePrefix = $logo ?: $siteName;
54
        $titleSuffix = $title ? ' ' . $title : '';
55
56
        $dashboard = parent::configureDashboard()
57
            ->setTitle($titlePrefix . $titleSuffix);
58
59
        $iconPath = $this->site->getIconPath();
60
        if (null !== $iconPath) {
61
            $dashboard->setFaviconPath($iconPath);
62
        }
63
64
        return $dashboard;
65
    }
66
67
    public function configureAssets(): Assets
68
    {
69
        return parent::configureAssets()
70
            ->addCssFile('bundles/zikulatheme/dashboard/' . $this->getName() . '.css')
71
            ->addJsFile('bundles/zikulatheme/dashboard/' . $this->getName() . '.js')
72
        ;
73
    }
74
75
    public function configureCrud(): Crud
76
    {
77
        return parent::configureCrud()
78
            ->overrideTemplate('layout', '@ZikulaTheme/Dashboard/layout_' . $this->getName() . '.html.twig')
79
        ;
80
    }
81
}
82