|
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\CoreBundle\Site; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
18
|
|
|
|
|
19
|
|
|
class SiteDefinition implements SiteDefinitionInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private readonly RequestStack $requestStack, |
|
23
|
|
|
private readonly array $siteData, |
|
24
|
|
|
#[Autowire(param: 'kernel.default_locale')] |
|
25
|
|
|
private readonly string $defaultLocale |
|
26
|
|
|
) { |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getName(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getLocalizedField('sitename'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getSlogan(): string |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->getLocalizedField('slogan'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getPageTitle(): string |
|
40
|
|
|
{ |
|
41
|
|
|
$title = $this->getName(); |
|
42
|
|
|
$titleScheme = $this->getLocalizedField('page_title_scheme'); |
|
43
|
|
|
if (!empty($titleScheme)) { |
|
44
|
|
|
$title = str_replace('#sitename#', $this->getName(), $titleScheme); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $title; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getMetaDescription(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getLocalizedField('meta_description'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getLogoPath(): ?string |
|
56
|
|
|
{ |
|
57
|
|
|
return '/bundles/core/images/logo_with_title.png'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getMobileLogoPath(): ?string |
|
61
|
|
|
{ |
|
62
|
|
|
return '/bundles/core/images/zk-power.png'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getIconPath(): ?string |
|
66
|
|
|
{ |
|
67
|
|
|
return '/bundles/core/images/icon.png'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getStartController(): ?array |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getLocalizedField('start_controller'); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getAdminMail(): ?string |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getLocalizedField('admin_mail'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private function getLocale(): string |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->requestStack->getCurrentRequest()->getLocale(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function getLocalizedField(string $fieldName): string|array |
|
86
|
|
|
{ |
|
87
|
|
|
$locale = $this->getLocale(); |
|
88
|
|
|
if (array_key_exists($locale, $this->siteData) && isset($this->siteData[$locale][$fieldName])) { |
|
89
|
|
|
return $this->siteData[$locale][$fieldName]; |
|
90
|
|
|
} |
|
91
|
|
|
if (array_key_exists($this->defaultLocale, $this->siteData) && isset($this->siteData[$this->defaultLocale][$fieldName])) { |
|
92
|
|
|
return $this->siteData[$this->defaultLocale][$fieldName]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$firstSiteData = array_values($this->siteData)[0]; |
|
96
|
|
|
|
|
97
|
|
|
return $firstSiteData[$fieldName] ?? ''; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|