ElementSlideshow::provideBlockSchema()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
nc 1
nop 0
crap 2
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
     * @var array
37
     */
38
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
39
        'Slides',
40
    ];
41
42
    /**
43
     * @var bool
44
     */
45
    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...
46
47
    /**
48
     * @var string
49
     */
50
    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...
51
52
    /**
53
     * @param bool $includerelations
54
     * @return array
55
     */
56 1
    public function fieldLabels($includerelations = true)
57
    {
58 1
        $labels = parent::fieldLabels($includerelations);
59
60 1
        $labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Description');
61
62 1
        return $labels;
63
    }
64
65
    /**
66
     * @return FieldList
67
     */
68
    public function getCMSFields()
69
    {
70 1
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
71 1
            $fields->dataFieldByName('Content')
72 1
                ->setRows(5)
73 1
                ->setDescription(_t(
74 1
                    __CLASS__ . '.ContentDescription',
75 1
                    'optional. Add introductory copy to your slideshow.'
76
                ));
77 1
        });
78
79 1
        return parent::getCMSFields();
80
    }
81
82
    /**
83
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
84
     */
85 1
    public function getSummary()
86
    {
87 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

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