EditableFieldGroup   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A showInReports() 0 3 1
A getInlineClassnameField() 0 3 1
A getCMSTitle() 0 10 3
A getCMSFields() 0 5 1
A updateFormField() 0 11 3
A getFormField() 0 7 2
1
<?php
2
3
namespace SilverStripe\UserForms\Model\EditableFormField;
4
5
use SilverStripe\Core\Convert;
6
use SilverStripe\Forms\LabelField;
7
use SilverStripe\UserForms\FormField\UserFormsGroupField;
8
use SilverStripe\UserForms\Model\EditableFormField;
9
10
/**
11
 * Specifies that this ends a group of fields
12
 */
13
class EditableFieldGroup extends EditableFormField
14
{
15
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
16
        'End' => EditableFieldGroupEnd::class,
17
    ];
18
19
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
20
        'End',
21
    ];
22
23
    private static $cascade_deletes = [
0 ignored issues
show
introduced by
The private property $cascade_deletes is not used, and could be removed.
Loading history...
24
        'End',
25
    ];
26
27
    /**
28
     * Disable selection of group class
29
     *
30
     * @config
31
     * @var bool
32
     */
33
    private static $hidden = true;
0 ignored issues
show
introduced by
The private property $hidden is not used, and could be removed.
Loading history...
34
35
    /**
36
     * Non-data field type
0 ignored issues
show
Bug introduced by
The type SilverStripe\UserForms\M...\EditableFormField\type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
     *
38
     * @var type
39
     */
40
    private static $literal = true;
0 ignored issues
show
introduced by
The private property $literal is not used, and could be removed.
Loading history...
41
42
    private static $table_name = 'EditableFieldGroup';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
43
44
    public function getCMSFields()
45
    {
46
        $fields = parent::getCMSFields();
47
        $fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
48
        return $fields;
49
    }
50
51
    public function getCMSTitle()
52
    {
53
        $title = $this->getFieldNumber()
54
            ?: $this->Title
55
            ?: 'group';
56
57
        return _t(
58
            'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFieldGroupEnd.FIELD_GROUP_START',
59
            'Group {group}',
60
            ['group' => $title]
61
        );
62
    }
63
64
    public function getInlineClassnameField($column, $fieldClasses)
65
    {
66
        return LabelField::create($column, $this->CMSTitle);
0 ignored issues
show
Bug Best Practice introduced by
The property CMSTitle does not exist on SilverStripe\UserForms\M...ield\EditableFieldGroup. Since you implemented __get, consider adding a @property annotation.
Loading history...
67
    }
68
69
    public function showInReports()
70
    {
71
        return false;
72
    }
73
74
    public function getFormField()
75
    {
76
        $field = UserFormsGroupField::create()
77
            ->setTitle($this->Title ?: false)
78
            ->setName($this->Name);
79
        $this->doUpdateFormField($field);
80
        return $field;
81
    }
82
83
    protected function updateFormField($field)
84
    {
85
        // set the right title on this field
86
        if ($this->RightTitle) {
0 ignored issues
show
Bug Best Practice introduced by
The property RightTitle does not exist on SilverStripe\UserForms\M...ield\EditableFieldGroup. Since you implemented __get, consider adding a @property annotation.
Loading history...
87
            // Since this field expects raw html, safely escape the user data prior
88
            $field->setRightTitle(Convert::raw2xml($this->RightTitle));
89
        }
90
91
        // if this field has an extra class
92
        if ($this->ExtraClass) {
0 ignored issues
show
Bug Best Practice introduced by
The property ExtraClass does not exist on SilverStripe\UserForms\M...ield\EditableFieldGroup. Since you implemented __get, consider adding a @property annotation.
Loading history...
93
            $field->addExtraClass($this->ExtraClass);
94
        }
95
    }
96
}
97