Skip to content

Commit f9068e2

Browse files
committed
re-added missing trait
1 parent 90f007c commit f9068e2

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

app/base/traits/FrontendTrait.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* SiteBase
4+
* PHP Version 7.0
5+
*
6+
* @category CMS / Framework
7+
* @package Degami\Sitebase
8+
* @author Mirko De Grandis <degami@github.com>
9+
* @license MIT https://opensource.org/licenses/mit-license.php
10+
* @link https://github.com/degami/sitebase
11+
*/
12+
namespace App\Base\Traits;
13+
14+
use \App\Base\Abstracts\ContainerAwareObject;
15+
use \App\Base\Abstracts\Model;
16+
17+
/**
18+
* Frontend pages Trait
19+
*/
20+
trait FrontendTrait
21+
{
22+
use PageTrait;
23+
24+
/**
25+
* @var array template data
26+
*/
27+
protected $templateData = [];
28+
29+
/**
30+
* gets route group
31+
*
32+
* @return string
33+
*/
34+
public static function getRouteGroup()
35+
{
36+
return '';
37+
}
38+
39+
/**
40+
* {@inheritdocs}
41+
*
42+
* @return array
43+
*/
44+
protected function getTemplateData()
45+
{
46+
return $this->templateData;
47+
}
48+
49+
/**
50+
* sets object to show
51+
*
52+
* @param Model $object
53+
*/
54+
protected function setObject(Model $object)
55+
{
56+
$this->templateData['object'] = $object;
57+
return $this;
58+
}
59+
60+
/**
61+
* gets object to show
62+
*
63+
* @return Model|null
64+
*/
65+
protected function getObject()
66+
{
67+
return $this->templateData['object'] ?? null;
68+
}
69+
70+
71+
/**
72+
* {@inheritdocs}
73+
*
74+
* @return array
75+
*/
76+
public function getTranslations()
77+
{
78+
return array_map(
79+
function ($el) {
80+
return $this->getRouting()->getBaseUrl() . $el;
81+
},
82+
$this->getContainer()->call([$this->getObject(), 'getTranslations'])
83+
);
84+
}
85+
86+
87+
/**
88+
* {@inheritdocs}
89+
*
90+
* @return string
91+
*/
92+
public function getCurrentLocale()
93+
{
94+
if (isset($this->templateData['object']) && ($this->templateData['object'] instanceof Model) && $this->templateData['object']->isLoaded()) {
95+
if ($this->templateData['object']->getLocale()) {
96+
return $this->getApp()->setCurrentLocale($this->templateData['object']->getLocale())->getCurrentLocale();
97+
}
98+
}
99+
100+
return $this->getApp()->setCurrentLocale(parent::getCurrentLocale())->getCurrentLocale();
101+
}
102+
}

0 commit comments

Comments
 (0)