1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius. |
5
|
|
|
* |
6
|
|
|
* (c) Monsieur Biz <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace MonsieurBiz\SyliusRichEditorPlugin\UiElement; |
15
|
|
|
|
16
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
17
|
|
|
|
18
|
|
|
trait UiElementTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var MetadataInterface |
22
|
|
|
*/ |
23
|
|
|
protected MetadataInterface $metadata; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var TranslatorInterface |
27
|
|
|
*/ |
28
|
|
|
protected TranslatorInterface $translator; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
protected bool $ignored = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function setMetadata(MetadataInterface $metadata): void |
39
|
|
|
{ |
40
|
|
|
$this->metadata = $metadata; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function setTranslator(TranslatorInterface $translator): void |
47
|
|
|
{ |
48
|
|
|
$this->translator = $translator; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getCode(): string |
55
|
|
|
{ |
56
|
|
|
return $this->metadata->getCode(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getAlias(): ?string |
63
|
|
|
{ |
64
|
|
|
return $this->metadata->getAlias(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function isEnabled(): bool |
71
|
|
|
{ |
72
|
|
|
return $this->metadata->isEnabled(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getTitle(): string |
79
|
|
|
{ |
80
|
|
|
return $this->metadata->getParameter('title'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function getDescription(): string |
87
|
|
|
{ |
88
|
|
|
return $this->metadata->getParameter('description'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getIcon(): string |
95
|
|
|
{ |
96
|
|
|
return $this->metadata->getParameter('icon'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function getFormClass(): string |
103
|
|
|
{ |
104
|
|
|
return $this->metadata->getClass('form'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function getAdminFormTemplate(): string |
111
|
|
|
{ |
112
|
|
|
return $this->metadata->getTemplate('admin_form'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function getAdminRenderTemplate(): string |
119
|
|
|
{ |
120
|
|
|
return $this->metadata->getTemplate('admin_render'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
|
|
public function getFrontRenderTemplate(): string |
127
|
|
|
{ |
128
|
|
|
return $this->metadata->getTemplate('front_render'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function ignore(): void |
132
|
|
|
{ |
133
|
|
|
$this->ignored = true; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function jsonSerialize() |
140
|
|
|
{ |
141
|
|
|
return [ |
142
|
|
|
'code' => $this->getCode(), |
143
|
|
|
'description' => $this->translator->trans($this->getDescription()), |
144
|
|
|
'icon' => $this->getIcon(), |
145
|
|
|
'title' => $this->translator->trans($this->getTitle()), |
146
|
|
|
'ignored' => $this->ignored, |
147
|
|
|
'tags' => $this->metadata->getTags(), |
148
|
|
|
'enabled' => $this->isEnabled(), |
149
|
|
|
]; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|