Passed
Pull Request — master (#51)
by Robbie
02:40
created

Dropdown::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\CKANRegistry\Model\ResourceFilter;
4
5
use SilverStripe\CKANRegistry\Model\ResourceFilter;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\TextField;
9
10
/**
11
 * Provides a single select option for CKAN resources to be filtered by
12
 */
13
class Dropdown extends ResourceFilter
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
        'Options' => 'Varchar',
17
    ];
18
19
    private static $table_name = 'CKANFilter_Dropdown';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
20
21
    private static $singular_name = 'Dropdown Filter';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
22
23
    protected $fieldType = DropdownField::class;
24
25
    public function getCMSFields()
26
    {
27
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
28
            $fields->push(TextField::create(
29
                'Options',
30
                _t(__CLASS__ . '.Options', 'Dropdown options')
31
            ));
32
33
            $fields->removeByName('FilterForID');
34
        });
35
36
        return parent::getCMSFields();
37
    }
38
}
39