InuitFieldList::performInuitTransformation()   D
last analyzed

Complexity

Conditions 9
Paths 65

Size

Total Lines 40
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 4.909
c 0
b 0
f 0
cc 9
eloc 23
nc 65
nop 0
1
<?php namespace StudioBonito\SilverStripe\Inuit\Forms\Extensions;
2
3
use ClassInfo;
4
use FieldGroup;
5
use SSViewer;
6
use Tab;
7
use TabSet;
8
9
/**
10
 * An extension to transform the {@link \FormField} objects
11
 * of a {@FieldList} so they use inuit form templates.
12
 *
13
 * @author       Tom Densham <[email protected]>
14
 * @copyright    Studio Bonito Ltd.
15
 */
16
class InuitFieldList extends \Extension
17
{
18
    /**
19
     * Transform all the {@link \FormField} objects in
20
     * the {@link \FieldList} to use inuit form templates.
21
     *
22
     * @return \FieldList
23
     */
24
    public function performInuitTransformation()
25
    {
26
        foreach ($this->owner as $field) {
27
28
            // If we have a Tabset, performInuitTransformation all Tabs
29
            if ($field instanceof TabSet) {
30
                $field->Tabs()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
            }
32
33
            // If we have a Tab, performInuitTransformation all its Fields
34
            if ($field instanceof Tab) {
35
                $field->Fields()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
            }
37
38
            if ($field instanceof FieldGroup) {
39
                $field->FieldList()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
            }
41
42
            $template = "Inuit{$field->class}_holder";
43
            if (SSViewer::hasTemplate($template)) {
44
                $field->setFieldHolderTemplate($template);
45
            } else {
46
                $field->setFieldHolderTemplate("InuitFormField_holder");
47
            }
48
49
            foreach (array_reverse(ClassInfo::ancestry($field)) as $className) {
50
                $inuitCandidate = "Inuit{$className}";
51
                $nativeCandidate = $className;
52
                if (SSViewer::hasTemplate($inuitCandidate)) {
53
                    $field->setTemplate($inuitCandidate);
54
                    break;
55
                } elseif (SSViewer::hasTemplate($nativeCandidate)) {
56
                    $field->setTemplate($nativeCandidate);
57
                    break;
58
                }
59
            }
60
        }
61
62
        return $this->owner;
63
    }
64
}