Completed
Push — master ( c77195...330b60 )
by Axel
10:09 queued 04:41
created

SiteDefinition::getMobileLogoPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 Foundation - 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\Bundle\CoreBundle\Site;
15
16
use Symfony\Component\HttpFoundation\RequestStack;
17
use Symfony\Contracts\Translation\TranslatorInterface;
18
use Zikula\Bundle\CoreBundle\Translation\TranslatorTrait;
19
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
20
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface;
21
22
class SiteDefinition implements SiteDefinitionInterface
23
{
24
    use TranslatorTrait;
25
26
    /**
27
     * @var RequestStack
28
     */
29
    private $requestStack;
30
31
    /**
32
     * @var VariableApiInterface
33
     */
34
    private $variableApi;
35
36
    /**
37
     * @var ExtensionRepositoryInterface
38
     */
39
    private $extensionRepository;
40
41
    public function __construct(
42
        TranslatorInterface $translator,
43
        RequestStack $requestStack,
44
        VariableApiInterface $variableApi,
45
        ExtensionRepositoryInterface $extensionRepository
46
    ) {
47
        $this->setTranslator($translator);
48
        $this->requestStack = $requestStack;
49
        $this->variableApi = $variableApi;
50
        $this->extensionRepository = $extensionRepository;
51
    }
52
53
    public function getTitle(): string
54
    {
55
        $title = $this->variableApi->getSystemVar('defaultpagetitle');
56
        $titleScheme = $this->variableApi->getSystemVar('pagetitle', '');
57
        if (!empty($titleScheme) && '%pagetitle%' !== $titleScheme) {
58
            $title = str_replace(
59
                ['%pagetitle%', '%sitename%'],
60
                [$title, $this->variableApi->getSystemVar('sitename', '')],
61
                $titleScheme
62
            );
63
64
            $moduleDisplayName = '';
65
            $request = $this->requestStack->getCurrentRequest();
66
            if (null !== $request && null !== $request->attributes->get('_controller')) {
67
                $controllerNameParts = explode('\\', $request->attributes->get('_controller'));
68
                $bundleName = count($controllerNameParts) > 1 ? $controllerNameParts[0] . $controllerNameParts[1] : '';
69
                if ('Module' === mb_substr($bundleName, -6)) {
70
                    $module = $this->extensionRepository->get($bundleName);
71
                    if (null !== $module) {
72
                        $moduleDisplayName = $module->getDisplayName();
73
                    }
74
                }
75
            }
76
            $title = str_replace('%modulename%', $moduleDisplayName, $title);
77
        }
78
79
        return $title;
80
    }
81
82
    public function getDescription(): string
83
    {
84
        return $this->variableApi->getSystemVar('defaultmetadescription');
85
    }
86
87
    public function getLogoPath(): ?string
88
    {
89
        return '@CoreBundle:images/logo_with_title.png';
90
    }
91
92
    public function getMobileLogoPath(): ?string
93
    {
94
        return '@CoreBundle:images/zk-power.png';
95
    }
96
97
    public function getIconPath(): ?string
98
    {
99
        return '@CoreBundle:images/logo.gif';
100
    }
101
}
102