1 | <?php |
||
19 | class PrefillFieldViewHelper extends AbstractViewHelper |
||
20 | { |
||
21 | /** |
||
22 | * Initialize arguments |
||
23 | */ |
||
24 | public function initializeArguments() |
||
29 | |||
30 | /** |
||
31 | * Returns a string to be used as prefill value for the given registration field (type=input). If the form |
||
32 | * has already been submitted, the submitted value for the field is returned. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public function render() |
||
48 | |||
49 | /** |
||
50 | * Returns the submitted value for the given field uid |
||
51 | * |
||
52 | * @param array $submittedValues |
||
53 | * @param int $fieldUid |
||
54 | * @return string |
||
55 | */ |
||
56 | protected function getFieldValueFromArguments($submittedValues, $fieldUid) |
||
66 | |||
67 | /** |
||
68 | * Shortcut for retrieving the request from the controller context |
||
69 | * |
||
70 | * @return \TYPO3\CMS\Extbase\Mvc\Request |
||
71 | */ |
||
72 | protected function getRequest() |
||
76 | } |
||
77 |
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 implementation 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 interface: