1 | <?php |
||
30 | class JavaScriptAssetHandlerConnector |
||
31 | { |
||
32 | /** |
||
33 | * List of JavaScript files which will be included whenever this view helper |
||
34 | * is used. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private $javaScriptFiles = [ |
||
39 | 'Formz.Main.js', |
||
40 | 'Formz.Misc.js', |
||
41 | 'Formz.EventsManager.js', |
||
42 | 'Formz.Result.js', |
||
43 | 'Formz.Localization.js', |
||
44 | 'Form/Formz.Form.js', |
||
45 | 'Form/Formz.Form.SubmissionService.js', |
||
46 | 'Field/Formz.Field.js', |
||
47 | 'Field/Formz.Field.DataAttributesService.js', |
||
48 | 'Field/Formz.Field.ValidationService.js', |
||
49 | 'Conditions/Formz.Condition.js', |
||
50 | 'Validators/Formz.Validation.js', |
||
51 | 'Validators/Formz.Validator.Ajax.js' |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @var AssetHandlerConnectorManager |
||
56 | */ |
||
57 | private $assetHandlerConnectorManager; |
||
58 | |||
59 | /** |
||
60 | * @param AssetHandlerConnectorManager $assetHandlerConnectorManager |
||
61 | */ |
||
62 | public function __construct(AssetHandlerConnectorManager $assetHandlerConnectorManager) |
||
66 | |||
67 | /** |
||
68 | * Will include all default JavaScript files declared in the property |
||
69 | * `$javaScriptFiles` of this class, as well as the main Formz |
||
70 | * configuration. |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function includeDefaultJavaScriptFiles() |
||
88 | |||
89 | /** |
||
90 | * This function will handle the JavaScript language files. |
||
91 | * |
||
92 | * A file will be created for the current language (there can be as many |
||
93 | * files as languages), containing the translations handling for JavaScript. |
||
94 | * If the file already exists, it is directly included. |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function includeLanguageJavaScriptFiles() |
||
115 | |||
116 | /** |
||
117 | * Includes Formz configuration JavaScript declaration. If the file exists, |
||
118 | * it is directly included, otherwise the JavaScript code is calculated, |
||
119 | * then put in the cache file. |
||
120 | * |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function generateAndIncludeFormzConfigurationJavaScript() |
||
139 | |||
140 | /** |
||
141 | * Will include the generated JavaScript, from multiple asset handlers |
||
142 | * sources. |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function generateAndIncludeJavaScript() |
||
176 | |||
177 | /** |
||
178 | * Here we generate the JavaScript code containing the submitted values, and |
||
179 | * the existing errors, which is dynamically created at each request. |
||
180 | * |
||
181 | * The code is then injected as inline code in the DOM. |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function generateAndIncludeInlineJavaScript() |
||
208 | |||
209 | /** |
||
210 | * Will include all new JavaScript files given, by checking that every given |
||
211 | * file was not already included. |
||
212 | * |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function includeJavaScriptValidationAndConditionFiles() |
||
230 | |||
231 | /** |
||
232 | * Returns the list of JavaScript files which are used for the current form |
||
233 | * object. |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | protected function getJavaScriptFiles() |
||
252 | |||
253 | /** |
||
254 | * We need an abstraction function because the footer inclusion for assets |
||
255 | * does not work in backend. It means we include every JavaScript asset in |
||
256 | * the header when the request is in a backend context. |
||
257 | * |
||
258 | * @see https://forge.typo3.org/issues/60213 |
||
259 | * |
||
260 | * @param string $path |
||
261 | */ |
||
262 | protected function includeJsFile($path) |
||
272 | |||
273 | /** |
||
274 | * @see includeJsFile() |
||
275 | * |
||
276 | * @param string $name |
||
277 | * @param string $javaScriptCode |
||
278 | */ |
||
279 | protected function addInlineJs($name, $javaScriptCode) |
||
289 | |||
290 | /** |
||
291 | * @return string |
||
292 | */ |
||
293 | protected function getAjaxUrl() |
||
305 | |||
306 | /** |
||
307 | * @return string |
||
308 | */ |
||
309 | protected function getDebugActivationCode() |
||
313 | |||
314 | /** |
||
315 | * @param FormObject $formObject |
||
316 | * @return ConditionProcessor |
||
317 | */ |
||
318 | protected function getConditionProcessor(FormObject $formObject) |
||
323 | |||
324 | /** |
||
325 | * @return FormzConfigurationJavaScriptAssetHandler|AbstractAssetHandler |
||
326 | */ |
||
327 | protected function getFormzConfigurationJavaScriptAssetHandler() |
||
333 | |||
334 | /** |
||
335 | * @return FormInitializationJavaScriptAssetHandler|AbstractAssetHandler |
||
336 | */ |
||
337 | protected function getFormInitializationJavaScriptAssetHandler() |
||
343 | |||
344 | /** |
||
345 | * @return FieldsValidationJavaScriptAssetHandler|AbstractAssetHandler |
||
346 | */ |
||
347 | protected function getFieldsValidationJavaScriptAssetHandler() |
||
353 | |||
354 | /** |
||
355 | * @return FieldsActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
356 | */ |
||
357 | protected function getFieldsActivationJavaScriptAssetHandler() |
||
363 | |||
364 | /** |
||
365 | * @return FieldsValidationActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
366 | */ |
||
367 | protected function getFieldsValidationActivationJavaScriptAssetHandler() |
||
373 | |||
374 | /** |
||
375 | * @return FormRequestDataJavaScriptAssetHandler|AbstractAssetHandler |
||
376 | */ |
||
377 | protected function getFormRequestDataJavaScriptAssetHandler() |
||
383 | |||
384 | /** |
||
385 | * @return FormzLocalizationJavaScriptAssetHandler|AbstractAssetHandler |
||
386 | */ |
||
387 | protected function getFormzLocalizationJavaScriptAssetHandler() |
||
393 | } |
||
394 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: