Completed
Push — master ( 878388...c75ae2 )
by Axel
04:48
created

SiteDefinition::getPageTitle()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 18
c 0
b 0
f 0
nc 8
nop 0
dl 0
loc 27
rs 8.4444
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 getName(): string
54
    {
55
        return $this->variableApi->getSystemVar('sitename', '');
56
    }
57
58
    public function getSlogan(): string
59
    {
60
        // not used yet, refs #3972
61
        return $this->variableApi->getSystemVar('slogan', '');
62
    }
63
64
    public function getPageTitle(): string
65
    {
66
        $title = $this->variableApi->getSystemVar('defaultpagetitle', '');
67
        $titleScheme = $this->variableApi->getSystemVar('pagetitle', '');
68
        if (!empty($titleScheme) && '%pagetitle%' !== $titleScheme) {
69
            $title = str_replace(
70
                ['%pagetitle%', '%sitename%'],
71
                [$title, $this->getName()],
72
                $titleScheme
73
            );
74
75
            $moduleDisplayName = '';
76
            $request = $this->requestStack->getCurrentRequest();
77
            if (null !== $request && null !== $request->attributes->get('_controller')) {
78
                $controllerNameParts = explode('\\', $request->attributes->get('_controller'));
79
                $bundleName = count($controllerNameParts) > 1 ? $controllerNameParts[0] . $controllerNameParts[1] : '';
80
                if ('Module' === mb_substr($bundleName, -6)) {
81
                    $module = $this->extensionRepository->get($bundleName);
82
                    if (null !== $module) {
83
                        $moduleDisplayName = $module->getDisplayName();
84
                    }
85
                }
86
            }
87
            $title = str_replace('%modulename%', $moduleDisplayName, $title);
88
        }
89
90
        return $title;
91
    }
92
93
    public function getMetaDescription(): string
94
    {
95
        return $this->variableApi->getSystemVar('defaultmetadescription', '');
96
    }
97
98
    public function getLogoPath(): ?string
99
    {
100
        // not used yet, refs #3972
101
        return '@CoreBundle:images/logo_with_title.png';
102
    }
103
104
    public function getMobileLogoPath(): ?string
105
    {
106
        // not used yet, refs #3972
107
        return '@CoreBundle:images/zk-power.png';
108
    }
109
110
    public function getIconPath(): ?string
111
    {
112
        // not used yet, refs #3972
113
        return '@CoreBundle:images/logo.gif';
114
    }
115
}
116