Passed
Push — master ( a1de92...1a465b )
by Robbie
03:52
created

ElementContent::getSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\Elemental\Models;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\ORM\FieldType\DBField;
7
8
class ElementContent extends BaseElement
9
{
10
    private static $icon = 'font-icon-block-content';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
11
12
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
13
        'HTML' => 'HTMLText'
14
    ];
15
16
    private static $table_name = 'ElementContent';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
17
18
    private static $singular_name = 'content block';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
19
20
    private static $plural_name = 'content blocks';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
21
22
    private static $description = 'HTML text block';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
23
24
    /**
25
     * Re-title the HTML field to Content
26
     *
27
     * {@inheritDoc}
28
     */
29
    public function getCMSFields()
30
    {
31
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
32
            $fields
33
                ->fieldByName('Root.Main.HTML')
34
                ->setTitle(_t(__CLASS__ . '.ContentLabel', 'Content'));
35
        });
36
        return parent::getCMSFields();
37
    }
38
39
    public function getSummary()
40
    {
41
        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...
42
    }
43
44
    protected function provideBlockSchema()
45
    {
46
        $blockSchema = parent::provideBlockSchema();
47
        $blockSchema['content'] = $this->getSummary();
48
        return $blockSchema;
49
    }
50
51
    public function getType()
52
    {
53
        return _t(__CLASS__ . '.BlockType', 'Content');
54
    }
55
}
56