Completed
Push — develop ( a0b39d...6e6eeb )
by Tino
07:33
created

Title::renderSiteSubTitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) by the ACP3 Developers.
5
 * See the LICENSE file at the top-level module directory for licensing details.
6
 */
7
8
namespace ACP3\Modules\ACP3\System\Core\Breadcrumb;
9
10
use ACP3\Core\Breadcrumb\Steps;
11
use ACP3\Core\Http\RequestInterface;
12
use ACP3\Core\Settings\SettingsInterface;
13
use ACP3\Modules\ACP3\System\Installer\Schema;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
16
class Title extends \ACP3\Core\Breadcrumb\Title
17
{
18
    /**
19
     * @var SettingsInterface
20
     */
21
    private $settings;
22
    /**
23
     * @var RequestInterface
24
     */
25
    private $request;
26
    /**
27
     * @var array
28
     */
29
    private $systemSettings = [];
30
31
    /**
32
     * Title constructor.
33
     *
34
     * @param RequestInterface         $request
35
     * @param Steps                    $steps
36
     * @param EventDispatcherInterface $eventDispatcher
37
     * @param SettingsInterface        $settings
38
     */
39
    public function __construct(
40
        RequestInterface $request,
41
        Steps $steps,
42
        EventDispatcherInterface $eventDispatcher,
43
        SettingsInterface $settings
44
    ) {
45
        parent::__construct($steps, $eventDispatcher);
46
47
        $this->settings = $settings;
48
        $this->request = $request;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    private function getSettings()
55
    {
56
        if (empty($this->systemSettings)) {
57
            $this->systemSettings = $this->settings->getSettings(Schema::MODULE_NAME);
58
        }
59
60
        return $this->systemSettings;
61
    }
62
63
    public function getSiteAndPageTitle()
64
    {
65
        $settings = $this->getSettings();
66
67
        if ($this->allowSystemSubtitle()) {
68
            if ($this->request->isHomepage()) {
69
                if ($settings['site_subtitle_homepage_mode'] == 1) {
70
                    $title = $this->getSiteSubtitle();
71
                    $title .= $this->getSiteTitleSeparator() . $this->getSiteTitle();
72
73
                    return $title;
74
                }
75
            } elseif ($settings['site_subtitle_mode'] == 2) {
76
                $this->setSiteSubtitle('');
77
            }
78
        }
79
80
        return parent::getSiteAndPageTitle();
81
    }
82
83
    private function allowSystemSubtitle(): bool
84
    {
85
        return $this->getSettings()['site_subtitle_mode'] != 3;
86
    }
87
88
    protected function renderSiteSubTitle(): string
89
    {
90
        if ($this->allowSystemSubtitle()) {
91
            return parent::renderSiteSubTitle();
92
        }
93
94
        return '';
95
    }
96
}
97