FormFieldExplanationDecorator::extraStatics()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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