Passed
Pull Request — master (#18)
by Jason
04:25
created

ElementSlideshow::provideBlockSchema()   A

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 SilverStripe\Forms\FieldList;
7
use SilverStripe\ORM\FieldType\DBField;
8
9
/**
10
 * Class ElementSlideshow
11
 * @package Dynamic\Elements\Flexslider\Elements
12
 *
13
 * @property string Content
14
 */
15
class ElementSlideshow extends BaseElement
16
{
17
    /**
18
     * @var string
19
     */
20
    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...
21
22
    /**
23
     * @var string
24
     */
25
    private static $singular_name = 'Flexslider Element';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
26
27
    /**
28
     * @var string
29
     */
30
    private static $plural_name = 'Flexslider Elements';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
31
32
    /**
33
     * @var string
34
     */
35
    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...
36
37
    /**
38
     * @var array
39
     */
40
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
41
        'Content' => 'HTMLText',
42
    ];
43
44
    /**
45
     * Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be
46
     * clickable and a GridFieldDetailForm will be used.
47
     *
48
     * @config
49
     * @var bool
50
     */
51
    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...
52
53
    /**
54
     * @var string
55
     */
56
    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...
57
58
    /**
59
     * @return FieldList
60
     */
61
    public function getCMSFields()
62
    {
63 1
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
64 1
            $fields->dataFieldByName('Content')
65 1
                ->setRows(8)
66 1
                ->setTitle('Description');
67 1
        });
68
69 1
        return parent::getCMSFields();
70
    }
71
72
    /**
73
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
74
     */
75 1
    public function getSummary()
76
    {
77 1
        if ($this->Slides()->count() == 1) {
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

77
        if ($this->/** @scrutinizer ignore-call */ Slides()->count() == 1) {
Loading history...
78 1
            $slide = ' slide';
79
        } else {
80
            $slide = ' slides';
81
        }
82 1
        return DBField::create_field('HTMLText', $this->Slides()->count() . $slide)->Summary(20);
83
    }
84
85
    /**
86
     * @return array
87
     */
88
    protected function provideBlockSchema()
89
    {
90
        $blockSchema = parent::provideBlockSchema();
91
        $blockSchema['content'] = $this->getSummary();
92
        return $blockSchema;
93
    }
94
95
    /**
96
     * @return string
97
     */
98 1
    public function getType()
99
    {
100 1
        return _t(__CLASS__.'.BlockType', 'Slideshow');
101
    }
102
}
103