PageRowCMSFieldsFixes::decorateCMSFields()   C
last analyzed

Complexity

Conditions 14
Paths 2

Size

Total Lines 50
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
rs 5.3716
cc 14
eloc 28
nc 2
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class PageRowCMSFieldsFixes extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    /**
7
     * Update Fields
8
     * @return FieldList
9
     */
10
    public function decorateCMSFields(FieldList $fields)
11
    {
12
        //right titles ...
13
        $list = $fields->dataFields();
14
15
        $rightFieldDescriptions = Config::inst()->get($this->owner->ClassName, 'field_labels_right');
16
        if (is_array($rightFieldDescriptions) && count($rightFieldDescriptions)) {
17
            foreach ($list as $formField) {
18
19
                // right titles ...
20
                $desc = '';
21
                $fieldName = $formField->getName();
22
                if (isset($rightFieldDescriptions[$fieldName])) {
23
                    $desc = $rightFieldDescriptions[$fieldName];
24
                }
25
                if (!$desc) {
26
                    if (isset($rightFieldDescriptions[$fieldName.'ID'])) {
27
                        $desc = $rightFieldDescriptions[$fieldName];
28
                    }
29
                }
30
                if (!$desc) {
31
                    if (substr($fieldName, -2) === 'ID') {
32
                        $fieldName = substr($fieldName, -2);
33
                        if (isset($rightFieldDescriptions[$fieldName])) {
34
                            $desc = $rightFieldDescriptions[$fieldName];
35
                        }
36
                    }
37
                }
38
                if ($desc) {
39
                    if ($formField->hasMethod('setDescription')) {
40
                        $formField->setDescription($desc);
41
                    } else {
42
                        $formField->setRightTitle($desc);
43
                    }
44
                }
45
46
47
                //HTML Editor fields
48
                //HTML
49
                if ($formField instanceof HTMLEditorField) {
50
                    $formField->setRows(12)
51
                        ->setRightTitle('Need more room? Use the FULL SCREEN button (last button above).');
52
                }
53
                if ($formField instanceof DateField) {
54
                    $formField->setConfig('showcalendar', true);
55
                }
56
            }
57
        }
58
        return $fields;
59
    }
60
61
62
}
63