Completed
Pull Request — master (#12)
by Jason
06:23
created

VideoBlock   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 6
dl 0
loc 43
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 20 1
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
    public function getCMSFields()
26
    {
27
        $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