-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePresenterTrait.php
More file actions
110 lines (93 loc) · 3.38 KB
/
Copy pathBasePresenterTrait.php
File metadata and controls
110 lines (93 loc) · 3.38 KB
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
<?php
namespace ADT\FancyAdmin\UI\Presenters;
use ADT\FancyAdmin\DI\Injects\EntityManagerInject;
use ADT\FancyAdmin\DI\Injects\FancyAdminInject;
use ADT\FancyAdmin\DI\Injects\TranslatorInject;
use ADT\FancyAdmin\Model\Security\SecurityUser;
use Exception;
use Nette\Application\Attributes\Persistent;
use Nette\Utils\Json;
use stdClass;
trait BasePresenterTrait
{
use PresenterTrait;
use FancyAdminInject;
use EntityManagerInject;
use TranslatorInject;
protected bool $primaryTemplate = false;
#[Persistent]
public string $backlink = '';
protected function beforeRender(): void
{
parent::beforeRender();
$this->getTemplate()->originalTemplate = __DIR__ . '/@layout.latte';
$this->getTemplate()->primaryTemplate = $this->primaryTemplate;
$this->getTemplate()->jsComponentsConfig = Json::encode($this->_fancyAdmin->getJsComponentsConfig());
$this->getTemplate()->logoFileName = $this->_fancyAdmin->getLogoPublicPath();
$this->getTemplate()->faviconFileNamePng = $this->_fancyAdmin->getFaviconFileNamePng();
$this->getTemplate()->faviconFileNameSvg = $this->_fancyAdmin->getFaviconFileNameSvg();
$this->getTemplate()->icon = $this->_fancyAdmin->getLogoMenuPath();
$this->getTemplate()->loginPageLogoPath = $this->_fancyAdmin->getLoginPageLogoPath();
$this->getTemplate()->hmr = $this->_fancyAdmin->getHmr();
$this->getTemplate()->projectName = $this->_fancyAdmin->getProjectName();
}
/************************
**** FLASH MESSAGES ****
***********************
* @param string $message
* @param string $type
* @return stdClass
* @throws Exception
*/
public function flashMessage($message, string $type = 'info'): stdClass
{
throw new Exception('Use one of flashMessageError / flashMessageWarning / flashMessageSuccess / flashMessageInfo method instead.');
}
public function flashMessageError(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'danger', $autoCloseDuration);
}
public function flashMessageWarning(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'warning', $autoCloseDuration);
}
public function flashMessageSuccess(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'success', $autoCloseDuration);
}
public function flashMessageInfo(string $message, ?int $autoCloseDuration = null): stdClass
{
return $this->flashMessageCommon($message, 'info', $autoCloseDuration);
}
/** @internal */
private function flashMessageCommon(string $message, string $type, ?int $autoCloseDuration = null)
{
//$this->redrawControl('flashes');
$flash = parent::flashMessage($this->_translator->translate($message), $type);
$flash->closeDuration = $autoCloseDuration ?? BasePresenter::DEFAULT_AUTO_CLOSE_DURATION;
return $flash;
}
public function afterRender(): void
{
if (!$this->isControlInvalid()) {
$this->redrawControl('title');
$this->redrawControl('body');
}
}
/**
* Formats view template file names.
* @return array
*/
public function formatTemplateFiles(): array
{
$list = parent::formatTemplateFiles();
$list[] = __DIR__ . '/' . explode(':', $this->name)[1] . '/' . $this->view . '.latte';
return $list;
}
public function formatLayoutTemplateFiles(): array
{
$list = parent::formatLayoutTemplateFiles();
$list[] = __DIR__ . "/@layout.latte";
return $list;
}
}