Completed
Pull Request — master (#13)
by Jason
04:27
created

ElementSlideshow::ElementSummary()   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 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 = 'slideshow-icon';
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
     * @return FieldList
55
     */
56
    public function getCMSFields()
57
    {
58 1
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
59 1
            $fields->dataFieldByName('Content')
60 1
                ->setRows(8);
61 1
        });
62
63 1
        return parent::getCMSFields();
64
    }
65
66
    /**
67
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
68
     */
69 1
    public function getSummary()
70
    {
71 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

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