Issues (216)

src/Models/ElementContent.php (7 issues)

1
<?php
2
3
namespace DNADesign\Elemental\Models;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
7
use SilverStripe\ORM\FieldType\DBField;
8
9
/**
10
 * @property string $HTML
11
 */
12
class ElementContent extends BaseElement
13
{
14
    private static $icon = 'font-icon-block-content';
0 ignored issues
show
The private property $icon is not used, and could be removed.
Loading history...
15
16
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
17
        'HTML' => 'HTMLText'
18
    ];
19
20
    private static $table_name = 'ElementContent';
0 ignored issues
show
The private property $table_name is not used, and could be removed.
Loading history...
21
22
    private static $singular_name = 'content block';
0 ignored issues
show
The private property $singular_name is not used, and could be removed.
Loading history...
23
24
    private static $plural_name = 'content blocks';
0 ignored issues
show
The private property $plural_name is not used, and could be removed.
Loading history...
25
26
    private static $description = 'HTML text block';
0 ignored issues
show
The private property $description is not used, and could be removed.
Loading history...
27
28
    /**
29
     * Re-title the HTML field to Content
30
     *
31
     * {@inheritDoc}
32
     */
33
    public function getCMSFields()
34
    {
35
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
36
            /** @var HTMLEditorField $editorField */
37
            $editorField = $fields->fieldByName('Root.Main.HTML');
0 ignored issues
show
Are you sure the assignment to $editorField is correct as $fields->fieldByName('Root.Main.HTML') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
38
            $editorField->setTitle(_t(__CLASS__ . '.ContentLabel', 'Content'));
39
        });
40
41
        return parent::getCMSFields();
42
    }
43
44
    public function getSummary()
45
    {
46
        return DBField::create_field('HTMLText', $this->HTML)->Summary(20);
47
    }
48
49
    protected function provideBlockSchema()
50
    {
51
        $blockSchema = parent::provideBlockSchema();
52
        $blockSchema['content'] = $this->getSummary();
53
        return $blockSchema;
54
    }
55
56
    public function getType()
57
    {
58
        return _t(__CLASS__ . '.BlockType', 'Content');
59
    }
60
}
61