1 | <?php |
||
33 | class ThemeManager extends \hiqdev\yii2\collection\Manager implements \yii\base\BootstrapInterface |
||
34 | { |
||
35 | /** |
||
36 | * @var array basic pathMap for all themes, will be merged with theme own pathMap |
||
37 | */ |
||
38 | public $pathMap = []; |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | protected $_itemClass = Theme::class; |
||
44 | |||
45 | /** |
||
46 | * @var string default theme name |
||
47 | */ |
||
48 | protected $_defaultTheme; |
||
49 | |||
50 | /** |
||
51 | * Sets the default theme name. |
||
52 | * |
||
53 | * @param string $theme default theme name |
||
54 | */ |
||
55 | public function setDefaultTheme($theme) |
||
59 | |||
60 | /** |
||
61 | * Returns the default theme. Returns the first of available themes by default. |
||
62 | * |
||
63 | * @return string default theme name |
||
64 | */ |
||
65 | public function getDefaultTheme() |
||
74 | |||
75 | protected $_view; |
||
76 | |||
77 | /** |
||
78 | * @return \yii\web\View |
||
79 | * @see setView |
||
80 | */ |
||
81 | public function getView() |
||
89 | |||
90 | /** |
||
91 | * You can change the View for theme manager. |
||
92 | * @param \yii\web\View $view the view object that will be used to render views or view files |
||
93 | */ |
||
94 | public function setView($view) |
||
98 | |||
99 | /** |
||
100 | * @var Theme current theme object |
||
101 | */ |
||
102 | protected $_theme; |
||
103 | |||
104 | /** |
||
105 | * Changes theme. |
||
106 | * @param string theme name |
||
107 | * @throws InvalidConfigException |
||
108 | */ |
||
109 | public function setTheme($name) |
||
110 | { |
||
111 | if (!$name) { |
||
112 | throw new InvalidConfigException('no theme to set'); |
||
113 | } |
||
114 | $this->_theme = $name; |
||
115 | } |
||
116 | |||
117 | public function getTheme() |
||
118 | { |
||
119 | if (is_string($this->_theme)) { |
||
120 | if (!$this->has($this->_theme)) { |
||
121 | throw new InvalidConfigException('unknown theme: ' . $this->_theme); |
||
122 | } |
||
123 | $this->_theme = $this->getItem($this->_theme); |
||
124 | $this->getView()->theme = $this->_theme; |
||
125 | } |
||
126 | |||
127 | return $this->_theme; |
||
128 | } |
||
129 | |||
130 | public function getSettings() |
||
134 | |||
135 | /** |
||
136 | * @return bool |
||
137 | */ |
||
138 | public static function isHomePage() |
||
139 | { |
||
140 | $controller = Yii::$app->controller; |
||
141 | $default_controller = Yii::$app->defaultRoute; |
||
142 | return ($controller->id === $default_controller) && ($controller->action->id === $controller->defaultAction); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @var AssetBundle[] assets to be registered at bootstrap |
||
147 | */ |
||
148 | public $assets = []; |
||
149 | |||
150 | /** |
||
151 | * Register all the assets. |
||
152 | */ |
||
153 | public function registerAssets() |
||
160 | |||
161 | /** |
||
162 | * @var bool is already bootstrapped |
||
163 | */ |
||
164 | protected $_isBootstrapped = false; |
||
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | public function bootstrap($app) |
||
186 | |||
187 | /** |
||
188 | * @return SettingsStorageInterface |
||
189 | */ |
||
190 | public function getSettingsStorage() |
||
194 | |||
195 | /** |
||
196 | * @return array |
||
197 | */ |
||
198 | public function getThemeSettings() |
||
202 | } |
||
203 |