1 | <?php |
||
31 | class JavaScriptAssetHandlerConnector |
||
32 | { |
||
33 | /** |
||
34 | * List of JavaScript files which will be included whenever this view helper |
||
35 | * is used. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $javaScriptFiles = [ |
||
40 | 'Formz.Main.js', |
||
41 | 'Formz.Misc.js', |
||
42 | 'Formz.EventsManager.js', |
||
43 | 'Formz.Result.js', |
||
44 | 'Formz.Localization.js', |
||
45 | 'Form/Formz.Form.js', |
||
46 | 'Form/Formz.Form.SubmissionService.js', |
||
47 | 'Field/Formz.Field.js', |
||
48 | 'Field/Formz.Field.DataAttributesService.js', |
||
49 | 'Field/Formz.Field.ValidationService.js', |
||
50 | 'Conditions/Formz.Condition.js', |
||
51 | 'Validators/Formz.Validation.js', |
||
52 | 'Validators/Formz.Validator.Ajax.js' |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @var AssetHandlerConnectorManager |
||
57 | */ |
||
58 | private $assetHandlerConnectorManager; |
||
59 | |||
60 | /** |
||
61 | * @var EnvironmentService |
||
62 | */ |
||
63 | protected $environmentService; |
||
64 | /** |
||
65 | * @param AssetHandlerConnectorManager $assetHandlerConnectorManager |
||
66 | */ |
||
67 | public function __construct(AssetHandlerConnectorManager $assetHandlerConnectorManager) |
||
71 | |||
72 | /** |
||
73 | * Will include all default JavaScript files declared in the property |
||
74 | * `$javaScriptFiles` of this class, as well as the main Formz |
||
75 | * configuration. |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function includeDefaultJavaScriptFiles() |
||
93 | |||
94 | /** |
||
95 | * This function will handle the JavaScript language files. |
||
96 | * |
||
97 | * A file will be created for the current language (there can be as many |
||
98 | * files as languages), containing the translations handling for JavaScript. |
||
99 | * If the file already exists, it is directly included. |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function includeLanguageJavaScriptFiles() |
||
120 | |||
121 | /** |
||
122 | * Includes Formz configuration JavaScript declaration. If the file exists, |
||
123 | * it is directly included, otherwise the JavaScript code is calculated, |
||
124 | * then put in the cache file. |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function generateAndIncludeFormzConfigurationJavaScript() |
||
144 | |||
145 | /** |
||
146 | * Will include the generated JavaScript, from multiple asset handlers |
||
147 | * sources. |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function generateAndIncludeJavaScript() |
||
181 | |||
182 | /** |
||
183 | * Here we generate the JavaScript code containing the submitted values, and |
||
184 | * the existing errors, which is dynamically created at each request. |
||
185 | * |
||
186 | * The code is then injected as inline code in the DOM. |
||
187 | * |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function generateAndIncludeInlineJavaScript() |
||
213 | |||
214 | /** |
||
215 | * Will include all new JavaScript files given, by checking that every given |
||
216 | * file was not already included. |
||
217 | * |
||
218 | * @return $this |
||
219 | */ |
||
220 | public function includeJavaScriptValidationAndConditionFiles() |
||
235 | |||
236 | /** |
||
237 | * Returns the list of JavaScript files which are used for the current form |
||
238 | * object. |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | protected function getJavaScriptFiles() |
||
257 | |||
258 | /** |
||
259 | * We need an abstraction function because the footer inclusion for assets |
||
260 | * does not work in backend. It means we include every JavaScript asset in |
||
261 | * the header when the request is in a backend context. |
||
262 | * |
||
263 | * @see https://forge.typo3.org/issues/60213 |
||
264 | * |
||
265 | * @param string $path |
||
266 | */ |
||
267 | protected function includeJsFile($path) |
||
277 | |||
278 | /** |
||
279 | * @see includeJsFile() |
||
280 | * |
||
281 | * @param string $name |
||
282 | * @param string $javaScriptCode |
||
283 | */ |
||
284 | protected function addInlineJs($name, $javaScriptCode) |
||
294 | |||
295 | /** |
||
296 | * @return string |
||
297 | */ |
||
298 | protected function getAjaxUrl() |
||
310 | |||
311 | /** |
||
312 | * @return string |
||
313 | */ |
||
314 | protected function getDebugActivationCode() |
||
318 | |||
319 | /** |
||
320 | * @param FormObject $formObject |
||
321 | * @return ConditionProcessor |
||
322 | */ |
||
323 | protected function getConditionProcessor(FormObject $formObject) |
||
328 | |||
329 | /** |
||
330 | * @return FormzConfigurationJavaScriptAssetHandler|AbstractAssetHandler |
||
331 | */ |
||
332 | protected function getFormzConfigurationJavaScriptAssetHandler() |
||
338 | |||
339 | /** |
||
340 | * @return FormInitializationJavaScriptAssetHandler|AbstractAssetHandler |
||
341 | */ |
||
342 | protected function getFormInitializationJavaScriptAssetHandler() |
||
348 | |||
349 | /** |
||
350 | * @return FieldsValidationJavaScriptAssetHandler|AbstractAssetHandler |
||
351 | */ |
||
352 | protected function getFieldsValidationJavaScriptAssetHandler() |
||
358 | |||
359 | /** |
||
360 | * @return FieldsActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
361 | */ |
||
362 | protected function getFieldsActivationJavaScriptAssetHandler() |
||
368 | |||
369 | /** |
||
370 | * @return FieldsValidationActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
371 | */ |
||
372 | protected function getFieldsValidationActivationJavaScriptAssetHandler() |
||
378 | |||
379 | /** |
||
380 | * @return FormRequestDataJavaScriptAssetHandler|AbstractAssetHandler |
||
381 | */ |
||
382 | protected function getFormRequestDataJavaScriptAssetHandler() |
||
388 | |||
389 | /** |
||
390 | * @return FormzLocalizationJavaScriptAssetHandler|AbstractAssetHandler |
||
391 | */ |
||
392 | protected function getFormzLocalizationJavaScriptAssetHandler() |
||
398 | |||
399 | /** |
||
400 | * @param EnvironmentService $environmentService |
||
401 | */ |
||
402 | public function injectEnvironmentService(EnvironmentService $environmentService) |
||
406 | } |
||
407 |
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: