Make "themePreview" work correctly with themes that override templates

This commit is contained in:
Celestora 2021-12-12 15:11:44 +02:00
parent 8b86fdecd3
commit e73857cdc3

View file

@ -34,10 +34,10 @@ abstract class OpenVKPresenter extends SimplePresenter
])); ]));
} }
protected function setTempTheme(string $theme): void protected function setTempTheme(string $theme): void
{ {
Session::i()->set("_tempTheme", $theme); Session::i()->set("_tempTheme", $theme);
} }
protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL): void protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL): void
{ {
@ -221,25 +221,19 @@ abstract class OpenVKPresenter extends SimplePresenter
{ {
parent::onBeforeRender(); parent::onBeforeRender();
if(!is_null($this->user)) { if(Session::i()->get("_tempTheme"))
$theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")];
else if($this->requestParam("themePreview"))
$theme = Themepacks::i()[$this->requestParam("themePreview")];
else if($this->user->identity !== null && $this->user->identity->getTheme())
$theme = $this->user->identity->getTheme(); $theme = $this->user->identity->getTheme();
if(!is_null($theme) && $theme->overridesTemplates()) {
$this->template->_templatePath = $theme->getBaseDir() . "/tpl"; if(!is_null($theme) && $theme->overridesTemplates())
} $this->template->_templatePath = $theme->getBaseDir() . "/tpl";
}
if(!is_null(Session::i()->get("_error"))) { if(!is_null(Session::i()->get("_error"))) {
$this->template->flashMessage = json_decode(Session::i()->get("_error")); $this->template->flashMessage = json_decode(Session::i()->get("_error"));
Session::i()->set("_error", NULL); Session::i()->set("_error", NULL);
} }
if(Session::i()->get("_tempTheme"))
$this->template->theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")];
else if($this->requestParam("themePreview"))
$this->template->theme = Themepacks::i()[$this->requestParam("themePreview")];
else if($this->user->identity !== null && $this->user->identity->getTheme())
$this->template->theme = $this->user->identity->getTheme();
// Знаю, каша ебаная, целестора рефактор всё равно сделает :)))
} }
} }