Passed
Pull Request — master (#20)
by Jason
02:33
created

ElementSlideshow::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dynamic\Elements\Flexslider\Elements;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use Dynamic\FlexSlider\Model\SlideImage;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\ORM\FieldType\DBField;
9
10
/**
11
 * Class ElementSlideshow
12
 * @package Dynamic\Elements\Flexslider\Elements
13
 *
14
 * @property string Content
15
 */
16
class ElementSlideshow extends BaseElement
17
{
18
    /**
19
     * @var string
20
     */
21
    private static $icon = 'font-icon-block-carousel';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
22
23
    /**
24
     * @var string
25
     */
26
    private static $table_name = 'ElementSlideshow';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
27
28
    /**
29
     * @var array
30
     */
31
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
32
        'Content' => 'HTMLText',
33
    ];
34
35
    /**
36
     * Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be
37
     * clickable and a GridFieldDetailForm will be used.
38
     *
39
     * @config
40
     * @var bool
41
     */
42
    private static $inline_editable = false;
0 ignored issues
show
introduced by
The private property $inline_editable is not used, and could be removed.
Loading history...
43
44
    /**
45
     * @var string
46
     */
47
    private static $slide_tab_title = 'Main';
0 ignored issues
show
introduced by
The private property $slide_tab_title is not used, and could be removed.
Loading history...
48
49
    /**
50
     * @param bool $includerelations
51
     * @return array
52
     */
53 1
    public function fieldLabels($includerelations = true)
54
    {
55 1
        $labels = parent::fieldLabels($includerelations);
56
57 1
        $labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Description');
58
59 1
        return $labels;
60
    }
61
62
    /**
63
     * @return FieldList
64
     */
65
    public function getCMSFields()
66
    {
67 1
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
68 1
            $fields->dataFieldByName('Content')
69 1
                ->setRows(5)
70 1
                ->setDescription(_t(__CLASS__ . '.ContentDescription', 'optional. Add introductory copy to your slideshow.'));
71 1
        });
72
73 1
        return parent::getCMSFields();
74
    }
75
76
    /**
77
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
78
     */
79 1
    public function getSummary()
80
    {
81 1
        $count = $this->Slides()->count();
0 ignored issues
show
Bug introduced by
The method Slides() does not exist on Dynamic\Elements\Flexsli...ements\ElementSlideshow. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $count = $this->/** @scrutinizer ignore-call */ Slides()->count();
Loading history...
82 1
        $label = _t(
83 1
            SlideImage::class . '.PLURALS',
84 1
            '{count} Slide|{count} Slides',
85 1
            [ 'count' => $count ]
86
        );
87 1
        return DBField::create_field('HTMLText', $label)->Summary(20);
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    protected function provideBlockSchema()
94
    {
95
        $blockSchema = parent::provideBlockSchema();
96
        $blockSchema['content'] = $this->getSummary();
97
        return $blockSchema;
98
    }
99
100
    /**
101
     * @return string
102
     */
103 1
    public function getType()
104
    {
105 1
        return _t(__CLASS__.'.BlockType', 'Slideshow');
106
    }
107
}
108