This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtension.php
112 lines (92 loc) · 2.85 KB
/
Extension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace Bolt\Extension\RixBeck\Languages;
use Bolt\Extension\RixBeck\Languages\Controller\LanguageController;
class Extension extends \Bolt\BaseExtension
{
const NAME = 'languages';
const CONTAINER = 'extensions.languages';
protected $language;
public function getName()
{
return static::NAME;
}
/**
*/
public function initialize()
{
/*
* Frontend
*/
if ($this->app['config']->getWhichEnd() == 'frontend') {
$twigmodule = new Twig\LanguageToolset($this->app);
$this->app['twig']->addExtension($twigmodule);
}
}
public function setLanguageByContenttype($contenttypeslug)
{
// Get the language of current cttype
$contenttype = $this->app['storage']->getContenttype($contenttypeslug);
// if current land differs than req slug, align current lang
if ($contenttype['language']) {
$lang = $contenttype['language']['id'];
if ($this->getCurrentLanguage() != $lang) {
$this->setCurrentLanguage($lang);
}
}
return $this;
}
public function getContenttypeSlug($contenttypeslug)
{
$contenttype = $this->app['storage']->getContenttype($contenttypeslug);
if ($contenttype['language']) {
$lang = $this->getCurrentLanguage();
if ($lang !== $contenttype['language']['id']) {
$contenttypeslug = $contenttype['language'][$lang];
}
}
return $contenttypeslug;
}
public function getHomepage()
{
return $this->getConfig('homepage')[$this->getCurrentLanguage()];
}
public function createEntryUri()
{
return $this->app['config']->get('general/branding/path') . '/extensions/' . strtolower($this->getName());
}
public function getConfig($path = '', $delim = '/')
{
$conf = parent::getConfig();
if ($path) {
$segments = explode($delim, $path);
foreach ($segments as $index) {
if (array_key_exists($index, $conf)) {
$conf = $conf[$index];
} else {
return false;
}
}
}
return $conf;
}
public function getCurrentLanguage()
{
if ($this->language) {
return $this->language;
}
$this->language = $this->app['session']->get(self::CONTAINER . '.lang');
if (! $this->language) {
$this->setCurrentLanguage($this->getDefaultLanguage());
}
return $this->language;
}
public function getDefaultLanguage()
{
return 'en';
}
public function setCurrentLanguage($lang)
{
$this->app['session']->set(self::CONTAINER . '.lang', $this->language = $lang);
return $this;
}
}