-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
45 lines (33 loc) · 1.44 KB
/
Bootstrap.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
<?php
namespace cozumel\ThemePicker;
use yii\base\BootstrapInterface;
use yii\base\Application;
class Bootstrap implements BootstrapInterface {
public function bootstrap($app) {
$app->on(Application::EVENT_BEFORE_REQUEST, function () {
//get theme value from cookie
if (\Yii::$app->request->post('theme_picker') !== null && in_array(\Yii::$app->request->post('theme_picker'), $themes, true)) {
$themeName = \Yii::$app->request->post('theme_picker');
} else {
$themeName = \Yii::$app->getRequest()->getCookies()->getValue('theme_picker');
}
//check theme still exists
$themes = ThemePicker::getThemes();
if (in_array($themeName, $themes, true)) {
//it exists so set theme
\Yii::$app->view->theme = new \yii\base\Theme([
//change your pathmap if ncessary
//'@app/web/themes/'
'pathMap' => [
'@app/views' => '@app/themes/' . $themeName,
'@app/modules' => '@app/themes/' . $themeName . '/modules',
],
'baseUrl' => '@app/themes/' . $themeName
]);
} else {
//theme doesn't exist so remove cookie
\Yii::$app->getResponse()->getCookies()->remove('theme_picker');
}
});
}
}