Completed
Pull Request — master (#34)
by Jason
05:39
created

VideoBlock::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.6296

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 2
cts 14
cp 0.1429
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
crap 1.6296
1
<?php
2
3
class VideoBlock extends Block
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Video Block';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Video Blocks';
14
15
    /**
16
     * @var array
17
     */
18
    private static $has_one = array(
19
        'Video' => 'SilverStripeYouTubeVideo',
20
    );
21
22
    /**
23
     * @return FieldList
24
     */
25 1
    public function getCMSFields()
26
    {
27 1
        $fields = parent::getCMSFields();
28
29
        $source = function(){
30
            return SilverStripeYouTubeVideo::get()->map()->toArray();
31
        };
32
33
34
        $fields->addFieldToTab(
35
            'Root.Main',
36
            DropdownField::create('VideoID')
37
                ->setTitle('Video')
38
                ->setSource($source())
39
                ->setEmptyString('')
40
                ->useAddNew('SilverStripeYouTubeVideo', $source)
41
        );
42
43
        return $fields;
44
    }
45
}
46