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

src/Models/ElementContent.php (1 issue)

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';
11
12
    private static $db = [
13
        'HTML' => 'HTMLText'
14
    ];
15
16
    private static $table_name = 'ElementContent';
17
18
    private static $singular_name = 'content block';
19
20
    private static $plural_name = 'content blocks';
21
22
    private static $description = 'HTML text block';
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 Naomi Guyer
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