Passed
Pull Request — master (#135)
by Robbie
02:04
created

ElementContent::ElementSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace DNADesign\Elemental\Models;
4
5
use SilverStripe\Forms\HTMLEditor\HtmlEditorField;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\ORM\FieldType\DBField;
8
9
class ElementContent extends BaseElement
10
{
11
    private static $icon = 'dnadesign/silverstripe-elemental:images/content.svg';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
13
    private static $db = [
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
        'HTML' => 'HTMLText',
15
        'Style' => 'Varchar(255)'
16
    ];
17
18
    private static $table_name = 'ElementContent';
0 ignored issues
show
Unused Code introduced by
The property $table_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
20
    private static $singular_name = 'content block';
0 ignored issues
show
Unused Code introduced by
The property $singular_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
22
    private static $plural_name = 'content blocks';
0 ignored issues
show
Unused Code introduced by
The property $plural_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
    private static $description = 'HTML text block';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
25
26
    /**
27
     * @var array
28
     */
29
    private static $styles = [];
0 ignored issues
show
Unused Code introduced by
The property $styles is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function getCMSFields()
35
    {
36
        $styles = $this->config()->get('styles');
37
38
        if (count($styles) > 0) {
39
            $this->beforeUpdateCMSFields(function ($fields) use ($styles) {
40
                $fields->addFieldsToTab('Root.Main', new HtmlEditorField('HTML', _t(__CLASS__.'.CONTENT', 'Content')));
41
                $fields->addFieldsToTab('Root.Main', $styles = new DropdownField('Style', _t(__CLASS__.'.STYLE', 'Style'), $styles));
42
                $styles->setEmptyString(_t(__CLASS__.'.CUSTOM_STYLES', 'Select a custom style..'));
43
            });
44
        } else {
45
            $this->beforeUpdateCMSFields(function ($fields) {
46
                $fields->removeByName('Style');
47
            });
48
        }
49
50
        $fields = parent::getCMSFields();
51
52
        if ($this->hasExtension('VersionViewerDataObject')) {
53
            $fields = $this->addVersionViewer($fields, $this);
0 ignored issues
show
Bug introduced by
The method addVersionViewer() does not exist on DNADesign\Elemental\Models\ElementContent. 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

53
            /** @scrutinizer ignore-call */ 
54
            $fields = $this->addVersionViewer($fields, $this);
Loading history...
54
        }
55
56
        return $fields;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getCssStyle()
63
    {
64
        $styles = $this->config()->get('styles');
65
        $style = $this->Style;
0 ignored issues
show
Bug Best Practice introduced by
The property Style does not exist on DNADesign\Elemental\Models\ElementContent. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
67
        if (isset($styles[$style])) {
68
            return strtolower($styles[$style]);
69
        }
70
    }
71
72
    public function getSummary()
73
    {
74
        return DBField::create_field('HTMLText', $this->HTML)->Summary(20);
0 ignored issues
show
Bug Best Practice introduced by
The property HTML does not exist on DNADesign\Elemental\Models\ElementContent. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
    }
76
77
    public function getType()
78
    {
79
        return _t(__CLASS__ . '.BlockType', 'Content');
80
    }
81
}
82