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

ElementSlideshow::fieldLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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(
71 1
                    __CLASS__ . '.ContentDescription',
72 1
                    'optional. Add introductory copy to your slideshow.'
73
                ));
74 1
        });
75
76 1
        return parent::getCMSFields();
77
    }
78
79
    /**
80
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
81
     */
82 1
    public function getSummary()
83
    {
84 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

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