1 | <?php |
||
30 | class LocalizationJavaScriptAssetHandler extends AbstractAssetHandler |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * Contains the full list of keys/translations. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $translations = []; |
||
39 | |||
40 | /** |
||
41 | * Contains the list of keys which are bound to translations, for a field |
||
42 | * validator. The value is an array of keys, because a validator may have |
||
43 | * several messages. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $translationKeysForFieldValidator = []; |
||
48 | |||
49 | /** |
||
50 | * Contains the list of fields validators which were already processed by |
||
51 | * this asset handler. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $injectedTranslationKeysForFieldValidator = []; |
||
56 | |||
57 | /** |
||
58 | * Will generate and return the JavaScript code which add all registered |
||
59 | * translations to the JavaScript library. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getJavaScriptCode() |
||
81 | |||
82 | /** |
||
83 | * Returns the keys which are bound to translations, for a given field |
||
84 | * validator. |
||
85 | * |
||
86 | * @param Field $field |
||
87 | * @param Validator $validator |
||
88 | * @return array |
||
89 | */ |
||
90 | public function getTranslationKeysForFieldValidator(Field $field, Validator $validator) |
||
98 | |||
99 | /** |
||
100 | * Will loop on each field of the given form, and get every translations for |
||
101 | * the validator rules messages. |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function injectTranslationsForFormFieldsValidator() |
||
115 | |||
116 | /** |
||
117 | * Will loop on each validator rule of the given field, and get the |
||
118 | * translations of the rule messages. |
||
119 | * |
||
120 | * @param Field $field |
||
121 | * @return $this |
||
122 | */ |
||
123 | protected function storeTranslationsForFieldValidator(Field $field) |
||
148 | |||
149 | /** |
||
150 | * Adds a global translation value which will be added to the FormZ |
||
151 | * JavaScript localization service. |
||
152 | * |
||
153 | * @param string $key |
||
154 | * @param string $value |
||
155 | */ |
||
156 | protected function addTranslation($key, $value) |
||
160 | |||
161 | /** |
||
162 | * Checks if the given field validator were already handled by this |
||
163 | * asset handler. |
||
164 | * |
||
165 | * @param Field $field |
||
166 | * @return bool |
||
167 | */ |
||
168 | protected function translationsForFieldValidatorWereInjected(Field $field) |
||
174 | |||
175 | /** |
||
176 | * @param Field $field |
||
177 | * @param Validator $validator |
||
178 | * @param string $messageKey |
||
179 | * @return string |
||
180 | */ |
||
181 | protected function getIdentifierForFieldValidator(Field $field, Validator $validator, $messageKey) |
||
185 | |||
186 | /** |
||
187 | * This function is here to help unit tests mocking. |
||
188 | * |
||
189 | * @param string $realTranslations |
||
190 | * @return string |
||
191 | */ |
||
192 | protected function handleRealTranslations($realTranslations) |
||
196 | |||
197 | /** |
||
198 | * This function is here to help unit tests mocking. |
||
199 | * |
||
200 | * @param string $translationsBinding |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function handleTranslationsBinding($translationsBinding) |
||
207 | } |
||
208 |