1 | <?php |
||
35 | class JavaScriptAssetHandlerConnector |
||
36 | { |
||
37 | /** |
||
38 | * List of JavaScript files which will be included whenever this view helper |
||
39 | * is used. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | private $javaScriptFiles = [ |
||
44 | 'Formz.Main.js', |
||
45 | 'Formz.Misc.js', |
||
46 | 'Formz.EventsManager.js', |
||
47 | 'Formz.Result.js', |
||
48 | 'Formz.Localization.js', |
||
49 | 'Form/Formz.Form.js', |
||
50 | 'Form/Formz.Form.SubmissionService.js', |
||
51 | 'Field/Formz.Field.js', |
||
52 | 'Field/Formz.Field.DataAttributesService.js', |
||
53 | 'Field/Formz.Field.ValidationService.js', |
||
54 | 'Conditions/Formz.Condition.js', |
||
55 | 'Validators/Formz.Validation.js', |
||
56 | 'Validators/Formz.Validator.Ajax.js' |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * @var AssetHandlerConnectorManager |
||
61 | */ |
||
62 | private $assetHandlerConnectorManager; |
||
63 | |||
64 | /** |
||
65 | * @var AssetHandlerFactory |
||
66 | */ |
||
67 | private $assetHandlerFactory; |
||
68 | |||
69 | /** |
||
70 | * @var EnvironmentService |
||
71 | */ |
||
72 | protected $environmentService; |
||
73 | /** |
||
74 | * @param AssetHandlerConnectorManager $assetHandlerConnectorManager |
||
75 | */ |
||
76 | public function __construct(AssetHandlerConnectorManager $assetHandlerConnectorManager) |
||
81 | |||
82 | /** |
||
83 | * Will include all default JavaScript files declared in the property |
||
84 | * `$javaScriptFiles` of this class, as well as the main FormZ |
||
85 | * configuration. |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function includeDefaultJavaScriptFiles() |
||
103 | |||
104 | /** |
||
105 | * This function will handle the JavaScript language files. |
||
106 | * |
||
107 | * A file will be created for the current language (there can be as many |
||
108 | * files as languages), containing the translations handling for JavaScript. |
||
109 | * If the file already exists, it is directly included. |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function includeLanguageJavaScriptFiles() |
||
130 | |||
131 | /** |
||
132 | * Includes FormZ configuration JavaScript declaration. If the file exists, |
||
133 | * it is directly included, otherwise the JavaScript code is calculated, |
||
134 | * then put in the cache file. |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function generateAndIncludeFormzConfigurationJavaScript() |
||
154 | |||
155 | /** |
||
156 | * Will include the generated JavaScript, from multiple asset handlers |
||
157 | * sources. |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function generateAndIncludeJavaScript() |
||
191 | |||
192 | /** |
||
193 | * Here we generate the JavaScript code containing the submitted values, and |
||
194 | * the existing errors, which is dynamically created at each request. |
||
195 | * |
||
196 | * The code is then injected as inline code in the DOM. |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function generateAndIncludeInlineJavaScript() |
||
222 | |||
223 | /** |
||
224 | * Will include all new JavaScript files given, by checking that every given |
||
225 | * file was not already included. |
||
226 | * |
||
227 | * @return $this |
||
228 | */ |
||
229 | public function includeJavaScriptValidationAndConditionFiles() |
||
244 | |||
245 | /** |
||
246 | * Returns the list of JavaScript files which are used for the current form |
||
247 | * object. |
||
248 | * |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function getJavaScriptFiles() |
||
264 | |||
265 | /** |
||
266 | * We need an abstraction function because the footer inclusion for assets |
||
267 | * does not work in backend. It means we include every JavaScript asset in |
||
268 | * the header when the request is in a backend context. |
||
269 | * |
||
270 | * @see https://forge.typo3.org/issues/60213 |
||
271 | * |
||
272 | * @param string $path |
||
273 | */ |
||
274 | protected function includeJsFile($path) |
||
284 | |||
285 | /** |
||
286 | * @see includeJsFile() |
||
287 | * |
||
288 | * @param string $name |
||
289 | * @param string $javaScriptCode |
||
290 | */ |
||
291 | protected function addInlineJs($name, $javaScriptCode) |
||
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | protected function getAjaxUrl() |
||
316 | |||
317 | /** |
||
318 | * @return string |
||
319 | */ |
||
320 | protected function getDebugActivationCode() |
||
324 | |||
325 | /** |
||
326 | * @param FormObject $formObject |
||
327 | * @return ConditionProcessor |
||
328 | */ |
||
329 | protected function getConditionProcessor(FormObject $formObject) |
||
334 | |||
335 | /** |
||
336 | * @return FormzConfigurationJavaScriptAssetHandler|AbstractAssetHandler |
||
337 | */ |
||
338 | protected function getFormzConfigurationJavaScriptAssetHandler() |
||
342 | |||
343 | /** |
||
344 | * @return FormInitializationJavaScriptAssetHandler|AbstractAssetHandler |
||
345 | */ |
||
346 | protected function getFormInitializationJavaScriptAssetHandler() |
||
350 | |||
351 | /** |
||
352 | * @return FieldsValidationJavaScriptAssetHandler|AbstractAssetHandler |
||
353 | */ |
||
354 | protected function getFieldsValidationJavaScriptAssetHandler() |
||
358 | |||
359 | /** |
||
360 | * @return FieldsActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
361 | */ |
||
362 | protected function getFieldsActivationJavaScriptAssetHandler() |
||
366 | |||
367 | /** |
||
368 | * @return FieldsValidationActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
369 | */ |
||
370 | protected function getFieldsValidationActivationJavaScriptAssetHandler() |
||
374 | |||
375 | /** |
||
376 | * @return FormRequestDataJavaScriptAssetHandler|AbstractAssetHandler |
||
377 | */ |
||
378 | protected function getFormRequestDataJavaScriptAssetHandler() |
||
382 | |||
383 | /** |
||
384 | * @return FormzLocalizationJavaScriptAssetHandler|AbstractAssetHandler |
||
385 | */ |
||
386 | protected function getFormzLocalizationJavaScriptAssetHandler() |
||
390 | |||
391 | /** |
||
392 | * @param EnvironmentService $environmentService |
||
393 | */ |
||
394 | public function injectEnvironmentService(EnvironmentService $environmentService) |
||
398 | } |
||
399 |
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: