1 | <?php |
||
2 | |||
3 | namespace SilverStripe\UserForms\FormField; |
||
4 | |||
5 | use SilverStripe\Forms\FieldList; |
||
6 | use SilverStripe\UserForms\Model\EditableFormField; |
||
7 | |||
8 | /** |
||
9 | * A list of formfields which allows for iterative processing of nested composite fields |
||
10 | */ |
||
11 | class UserFormsFieldList extends FieldList implements UserFormsFieldContainer |
||
12 | { |
||
13 | public function processNext(EditableFormField $field) |
||
14 | { |
||
15 | $formField = $field->getFormField(); |
||
16 | if (!$formField) { |
||
17 | return $this; |
||
0 ignored issues
–
show
|
|||
18 | } |
||
19 | |||
20 | $this->push($formField); |
||
21 | |||
22 | if ($formField instanceof UserFormsFieldContainer) { |
||
23 | return $formField->setParent($this); |
||
24 | } |
||
25 | |||
26 | return $this; |
||
27 | } |
||
28 | |||
29 | public function getParent() |
||
30 | { |
||
31 | // Field list does not have a parent |
||
32 | return null; |
||
33 | } |
||
34 | |||
35 | public function setParent(UserFormsFieldContainer $parent) |
||
36 | { |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Remove all empty steps |
||
42 | */ |
||
43 | public function clearEmptySteps() |
||
44 | { |
||
45 | foreach ($this as $field) { |
||
46 | if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) { |
||
47 | $this->remove($field); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: