1 | <?php |
||
25 | class Service |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Holds the data instances. |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $datas; |
||
33 | |||
34 | /** |
||
35 | * Holds the map for overriding templates. |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $templates; |
||
39 | |||
40 | /** |
||
41 | * Holds whether CRUDlex manages i18n. |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $manageI18n = true; |
||
45 | |||
46 | /** |
||
47 | * Holds the URL generator. |
||
48 | * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface |
||
49 | */ |
||
50 | protected $urlGenerator; |
||
51 | |||
52 | /** |
||
53 | * Initializes the available locales. |
||
54 | * |
||
55 | * @param Translator $translator |
||
56 | * the translator |
||
57 | * |
||
58 | * @return array |
||
59 | * the available locales |
||
60 | */ |
||
61 | 78 | protected function initLocales(Translator $translator) |
|
71 | |||
72 | /** |
||
73 | * Initializes the children of the data entries. |
||
74 | */ |
||
75 | 78 | protected function initChildren() |
|
86 | |||
87 | /** |
||
88 | * Gets a map with localized entity labels from the CRUD YML. |
||
89 | * |
||
90 | * @param array $locales |
||
91 | * the available locales |
||
92 | * @param array $crud |
||
93 | * the CRUD entity map |
||
94 | * |
||
95 | * @return array |
||
96 | * the map with localized entity labels |
||
97 | */ |
||
98 | 78 | protected function getLocaleLabels(array $locales, array $crud) |
|
108 | |||
109 | /** |
||
110 | * Configures the EntityDefinition according to the given |
||
111 | * CRUD entity map. |
||
112 | * |
||
113 | * @param EntityDefinition $definition |
||
114 | * the definition to configure |
||
115 | * @param array $crud |
||
116 | * the CRUD entity map |
||
117 | */ |
||
118 | 78 | protected function configureDefinition(EntityDefinition $definition, array $crud) |
|
139 | |||
140 | /** |
||
141 | * Creates and setups an EntityDefinition instance. |
||
142 | * |
||
143 | * @param Translator $translator |
||
144 | * the Translator to use for some standard field labels |
||
145 | * @param EntityDefinitionFactoryInterface $entityDefinitionFactory |
||
146 | * the EntityDefinitionFactory to use |
||
147 | * @param array $locales |
||
148 | * the available locales |
||
149 | * @param array $crud |
||
150 | * the parsed YAML of a CRUD entity |
||
151 | * @param string $name |
||
152 | * the name of the entity |
||
153 | * |
||
154 | * @return EntityDefinition |
||
155 | * the EntityDefinition good to go |
||
156 | */ |
||
157 | 78 | protected function createDefinition(Translator $translator, EntityDefinitionFactoryInterface $entityDefinitionFactory, array $locales, array $crud, $name) |
|
178 | |||
179 | /** |
||
180 | * Initializes the instance. |
||
181 | * |
||
182 | * @param string $crudFile |
||
183 | * the CRUD YAML file |
||
184 | * @param string|null $crudFileCachingDirectory |
||
185 | * the writable directory to store the CRUD YAML file cache |
||
186 | * @param UrlGeneratorInterface $urlGenerator |
||
187 | * the URL generator to use |
||
188 | * @param Translator $translator |
||
189 | * the translator to use |
||
190 | * @param DataFactoryInterface $dataFactory |
||
191 | * the data factory to use |
||
192 | * @param EntityDefinitionFactoryInterface $entityDefinitionFactory |
||
193 | * the EntityDefinitionFactory to use |
||
194 | * @param FilesystemInterface $filesystem |
||
195 | * the filesystem to use |
||
196 | * @param EntityDefinitionValidatorInterface|null $validator |
||
197 | * the validator to use, null if no validation required |
||
198 | */ |
||
199 | 79 | public function __construct($crudFile, $crudFileCachingDirectory, UrlGeneratorInterface $urlGenerator, Translator $translator, DataFactoryInterface $dataFactory, EntityDefinitionFactoryInterface $entityDefinitionFactory, FilesystemInterface $filesystem, ?EntityDefinitionValidatorInterface $validator) |
|
224 | |||
225 | /** |
||
226 | * Getter for the AbstractData instances. |
||
227 | * |
||
228 | * @param string $name |
||
229 | * the entity name of the desired Data instance |
||
230 | * |
||
231 | * @return AbstractData |
||
232 | * the AbstractData instance or null on invalid name |
||
233 | */ |
||
234 | 70 | public function getData($name) |
|
241 | |||
242 | /** |
||
243 | * Getter for all available entity names. |
||
244 | * |
||
245 | * @return string[] |
||
246 | * a list of all available entity names |
||
247 | */ |
||
248 | 5 | public function getEntities() |
|
252 | |||
253 | /** |
||
254 | * Getter for the entities for the navigation bar. |
||
255 | * |
||
256 | * @return string[] |
||
257 | * a list of all available entity names with their group |
||
258 | */ |
||
259 | 11 | public function getEntitiesNavBar() |
|
272 | |||
273 | /** |
||
274 | * Sets a template to use instead of the build in ones. |
||
275 | * |
||
276 | * @param string $key |
||
277 | * the template key to use in this format: |
||
278 | * $section.$action.$entity |
||
279 | * $section.$action |
||
280 | * $section |
||
281 | * @param string $template |
||
282 | * the template to use for this key |
||
283 | */ |
||
284 | 79 | public function setTemplate($key, $template) |
|
288 | |||
289 | /** |
||
290 | * Determines the Twig template to use for the given parameters depending on |
||
291 | * the existance of certain template keys set in this order: |
||
292 | * |
||
293 | * $section.$action.$entity |
||
294 | * $section.$action |
||
295 | * $section |
||
296 | * |
||
297 | * If nothing exists, this string is returned: "@crud/<action>.twig" |
||
298 | * |
||
299 | * @param string $section |
||
300 | * the section of the template, either "layout" or "template" |
||
301 | * @param string $action |
||
302 | * the current calling action like "create" or "show" |
||
303 | * @param string $entity |
||
304 | * the current calling entity |
||
305 | * |
||
306 | * @return string |
||
307 | * the best fitting template |
||
308 | */ |
||
309 | 11 | public function getTemplate($section, $action, $entity) |
|
327 | |||
328 | /** |
||
329 | * Sets the locale to be used. |
||
330 | * |
||
331 | * @param string $locale |
||
332 | * the locale to be used. |
||
333 | */ |
||
334 | 3 | public function setLocale($locale) |
|
340 | |||
341 | /** |
||
342 | * Gets the available locales. |
||
343 | * |
||
344 | * @return array |
||
345 | * the available locales |
||
346 | */ |
||
347 | 78 | public function getLocales() |
|
365 | |||
366 | /** |
||
367 | * Gets whether CRUDlex manages the i18n. |
||
368 | * @return bool |
||
369 | * true if so |
||
370 | */ |
||
371 | 11 | public function isManageI18n() |
|
375 | |||
376 | /** |
||
377 | * Sets whether CRUDlex manages the i18n. |
||
378 | * @param bool $manageI18n |
||
379 | * true if so |
||
380 | */ |
||
381 | 1 | public function setManageI18n($manageI18n) |
|
385 | |||
386 | /** |
||
387 | * Generates an URL. |
||
388 | * @param string $name |
||
389 | * the name of the route |
||
390 | * @param mixed $parameters |
||
391 | * an array of parameters |
||
392 | * @return null|string |
||
393 | * the generated URL |
||
394 | */ |
||
395 | 11 | public function generateURL($name, $parameters) |
|
399 | |||
400 | } |
||
401 |