FormFieldExplanationDecorator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set_show_fields_in_cms() 0 4 1
A get_show_fields_in_cms() 0 4 1
A extraStatics() 0 8 1
A updateCMSFields() 0 8 3
A getFormFieldExplanationHasManyTable() 0 18 2
1
<?php
2
3
/**
4
 *@author nicolaas[at]sunnysideup.co.nz
5
 *@description contains a list of form fields and their explantions, is added to SiteTree
6
 *
7
 **/
8
9
10
class FormFieldExplanationDecorator extends DataObjectDecorator
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...
11
{
12
    protected static $show_fields_in_cms = false;
13
    public static function set_show_fields_in_cms($v)
14
    {
15
        self::$show_fields_in_cms = $v;
16
    }
17
    public static function get_show_fields_in_cms()
18
    {
19
        return self::$show_fields_in_cms;
20
    }
21
22
    public function extraStatics()
23
    {
24
        return array(
25
            'has_many' => array(
26
                'FormFieldExplanation' => 'FormFieldExplanation'
27
            )
28
        );
29
    }
30
31
    public function updateCMSFields(FieldSet &$fields)
32
    {
33
        $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
34
        if (DataObject::get_one("FormFieldExplanation", "{$bt}ParentID{$bt} = ".$this->owner->ID)) {
35
            $fields->addFieldToTab("Root.Content.FormExplanations", $this->getFormFieldExplanationHasManyTable());
36
        }
37
        return $fields;
38
    }
39
40
41
    public function getFormFieldExplanationHasManyTable()
42
    {
43
        $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
44
        $field = new HasManyComplexTableField(
45
            $controller = $this->owner,
46
            $name = "FormFieldExplanation",
47
            $sourceClass = "FormFieldExplanation",
48
            $fieldList = array("Title" => "Title"),
49
            $detailFormFields = null,
50
            $sourceFilter = "{$bt}ParentID{$bt} =".$this->owner->ID,
51
            $sourceSort = "",
52
            $sourceJoin = ""
53
        );
54
        $field->setPermissions(array("edit", "delete"));
55
        $field->setParentClass($this->owner->class);
56
        $field->relationAutoSetting = true;
57
        return $field;
58
    }
59
}
60