Completed
Pull Request — master (#24)
by Jason
13:57
created

ProductDocCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
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
9
class ProductDocCollection extends \Page
10
{
11
    /**
12
     * @var array
13
     */
14
    private static $db = array(
15 1
        'ManagedClass' => 'Varchar(255)',
16
    );
17 1
18
    /**
19 1
     * @var string
20 1
     */
21 1
    private static $table_name = 'ProductDocCollection';
0 ignored issues
show
Unused Code introduced by
The property $table_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22 1
23 1
    /**
24
     * @return FieldList
25 1
     */
26 1
    public function getCMSFields()
27 1
    {
28 1
        $fields = parent::getCMSFields();
29
30 1
        if ($relations = ClassInfo::subclassesFor(ProductDoc::class)) {
31 1
            unset($relations[ProductDoc::class]);
32
            foreach ($relations as $key => $value) {
33 1
                $relations[$key] = singleton($value)->i18n_singular_name();
34
            }
35
36
            $fields->addFieldToTab(
37
                'Root.Main',
38
                DropdownField::create('ManagedClass', 'Files to display', $relations)
39
                    ->setEmptyString(''),
40
                'Content'
41
            );
42
        }
43
44
        return $fields;
45
    }
46
}