ProductDocCollection::getCMSFields()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 0
dl 0
loc 19
rs 9.9
c 0
b 0
f 0
ccs 12
cts 12
cp 1
crap 3
1
<?php
2
3
namespace Dynamic\ProductCatalog\Page;
4
5
use Dynamic\ProductCatalog\Docs\ProductDoc;
6
use SilverStripe\Core\ClassInfo;
7
use SilverStripe\Forms\DropdownField;
8
use SilverStripe\Forms\FieldList;
9
10
class ProductDocCollection extends \Page
11
{
12
    /**
13
     * @var array
14
     */
15
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
16
        'ManagedClass' => 'Varchar(255)',
17
    );
18
19
    /**
20
     * @var string
21
     */
22
    private static $table_name = 'ProductDocCollection';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @return FieldList
26
     */
27 1
    public function getCMSFields()
28
    {
29 1
        $fields = parent::getCMSFields();
30
31 1
        if ($relations = ClassInfo::subclassesFor(ProductDoc::class)) {
32 1
            unset($relations[ProductDoc::class]);
33 1
            foreach ($relations as $key => $value) {
34 1
                $relations[$key] = singleton($value)->i18n_singular_name();
35
            }
36
37 1
            $fields->addFieldToTab(
38 1
                'Root.Main',
39 1
                DropdownField::create('ManagedClass', 'Files to display', $relations)
40 1
                    ->setEmptyString(''),
41 1
                'Content'
42
            );
43
        }
44
45 1
        return $fields;
46
    }
47
}
48