Passed
Pull Request — 4 (#9655)
by Ingo
06:58
created

Person::getCMSValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\Forms\GridField\GridField;
7
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
8
use SilverStripe\Forms\RequiredFields;
9
use SilverStripe\ORM\DataObject;
10
11
class Person extends DataObject implements TestOnly
12
{
13
    private static $table_name = 'GridFieldDetailFormTest_Person';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
14
15
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
16
        'FirstName' => 'Varchar',
17
        'Surname' => 'Varchar'
18
    ];
19
20
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
21
        'Group' => PeopleGroup::class
22
    ];
23
24
    private static $many_many = [
0 ignored issues
show
introduced by
The private property $many_many is not used, and could be removed.
Loading history...
25
        'Categories' => Category::class,
26
        'FavouriteGroups' => PeopleGroup::class
27
    ];
28
29
    private static $many_many_extraFields = [
0 ignored issues
show
introduced by
The private property $many_many_extraFields is not used, and could be removed.
Loading history...
30
        'Categories' => [
31
            'IsPublished' => 'Boolean',
32
            'PublishedBy' => 'Varchar'
33
        ]
34
    ];
35
36
    private static $default_sort = '"FirstName"';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
37
38
    public function getCMSFields()
39
    {
40
        $fields = parent::getCMSFields();
41
        // TODO No longer necessary once FormScaffolder uses GridField
42
        $fields->replaceField(
43
            'Categories',
44
            GridField::create(
45
                'Categories',
46
                'Categories',
47
                $this->Categories(),
0 ignored issues
show
Bug introduced by
The method Categories() does not exist on SilverStripe\Forms\Tests...ldDetailFormTest\Person. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
                $this->/** @scrutinizer ignore-call */ 
48
                       Categories(),
Loading history...
48
                GridFieldConfig_RelationEditor::create()
49
            )
50
        );
51
        $fields->replaceField(
52
            'FavouriteGroups',
53
            GridField::create(
54
                'FavouriteGroups',
55
                'Favourite Groups',
56
                $this->FavouriteGroups(),
0 ignored issues
show
Bug introduced by
The method FavouriteGroups() does not exist on SilverStripe\Forms\Tests...ldDetailFormTest\Person. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                $this->/** @scrutinizer ignore-call */ 
57
                       FavouriteGroups(),
Loading history...
57
                GridFieldConfig_RelationEditor::create()
58
            )
59
        );
60
        return $fields;
61
    }
62
63
    public function getCMSValidator()
64
    {
65
        return new RequiredFields(
66
            [
67
            'FirstName',
68
            'Surname'
69
            ]
70
        );
71
    }
72
73
    public function CMSEditLink()
74
    {
75
        return sprintf('my-admin/%d', $this->ID);
76
    }
77
}
78