1 | <?php |
||
17 | class Moo_EditableFieldMultipleOption extends Moo_EditableField |
||
18 | { |
||
19 | private static $has_many = [ |
||
20 | 'Options' => 'Moo_EditableFieldOption', |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * Deletes all the options attached to this field before deleting the |
||
25 | * field. Keeps stray options from floating around. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | public function delete() |
||
41 | |||
42 | /** |
||
43 | * Duplicate a pages content. We need to make sure all the fields attached |
||
44 | * to that page go with it. |
||
45 | * |
||
46 | * @param bool $doWrite |
||
47 | * |
||
48 | * @return DataObject |
||
49 | */ |
||
50 | 1 | public function duplicate($doWrite = true) |
|
51 | { |
||
52 | 1 | $clonedNode = parent::duplicate($doWrite); |
|
53 | |||
54 | 1 | if ($this->Options()) { |
|
55 | 1 | foreach ($this->Options() as $field) { |
|
56 | 1 | $newField = $field->duplicate(); |
|
57 | 1 | $newField->ParentID = $clonedNode->ID; |
|
58 | 1 | $newField->write(); |
|
59 | 1 | } |
|
60 | 1 | } |
|
61 | |||
62 | 1 | return $clonedNode; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get extra configuration fields. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getFieldConfiguration() |
||
97 | |||
98 | /** |
||
99 | * Return the form field for this object in the front end form view. |
||
100 | * |
||
101 | * @return FormField |
||
102 | */ |
||
103 | 1 | protected function initFormField() |
|
109 | } |
||
110 |
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: