Passed
Pull Request — master (#122)
by Robbie
01:58
created

ElementContent::getType()   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
    /**
25
     * @var array
26
     */
27
    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...
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function getCMSFields()
33
    {
34
        $styles = $this->config()->get('styles');
35
36
        if (count($styles) > 0) {
37
            $this->beforeUpdateCMSFields(function ($fields) use ($styles) {
38
                $fields->addFieldsToTab('Root.Main', new HtmlEditorField('HTML', _t(__CLASS__.'.CONTENT', 'Content')));
39
                $fields->addFieldsToTab('Root.Main', $styles = new DropdownField('Style', _t(__CLASS__.'.STYLE', 'Style'), $styles));
40
                $styles->setEmptyString(_t(__CLASS__.'.CUSTOM_STYLES', 'Select a custom style..'));
41
            });
42
        } else {
43
            $this->beforeUpdateCMSFields(function ($fields) {
44
                $fields->removeByName('Style');
45
            });
46
        }
47
48
        $fields = parent::getCMSFields();
49
50
        if ($this->hasExtension('VersionViewerDataObject')) {
51
            $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

51
            $fields = $this->/** @scrutinizer ignore-call */ addVersionViewer($fields, $this);
Loading history...
52
        }
53
54
        return $fields;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getCssStyle()
61
    {
62
        $styles = $this->config()->get('styles');
63
        $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...
64
65
        if (isset($styles[$style])) {
66
            return strtolower($styles[$style]);
67
        }
68
    }
69
70
    /**
71
     * @return HTMLText
0 ignored issues
show
Bug introduced by
The type DNADesign\Elemental\Models\HTMLText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
     */
73
    public function ElementSummary()
74
    {
75
        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...
76
    }
77
78
    public function getType()
79
    {
80
        return _t(__CLASS__ . '.BlockType', 'Content');
81
    }
82
}
83