Passed
Pull Request — master (#6)
by Robbie
01:23
created

BannerBlock::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 9.2
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\ElementalBlocks\Block;
4
5
use SilverStripe\ElementalBlocks\Model\Link;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\HiddenField;
8
9
class BannerBlock extends FileBlock
10
{
11
    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...
12
        'Content' => 'HTMLText',
13
    ];
14
15
    private static $has_one = [
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
16
        'ImageLink' => Link::class,
17
        'CallToActionLink' => Link::class,
18
    ];
19
20
    private static $singular_name = 'banner';
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 = 'banners';
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
    public function getType()
25
    {
26
        return _t(__CLASS__ . '.BlockType', 'Banner');
27
    }
28
29
    public function getCMSFields()
30
    {
31
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
32
            // Remove default scaffolded relationship fields
33
            $fields->removeByName('ImageLinkID');
34
            $fields->removeByName('CallToActionLinkID');
35
36
            // Create hidden inputs for JSON input from the "insert link" modal
37
            $fields->addFieldsToTab('Root.Main', [
38
                HiddenField::create('ImageLinkData'),
0 ignored issues
show
Bug introduced by
'ImageLinkData' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
                HiddenField::create(/** @scrutinizer ignore-type */ 'ImageLinkData'),
Loading history...
39
                HiddenField::create('CallToActionLinkData'),
40
            ]);
41
42
            // Move the file upload field to the right place in the UI
43
            $upload = $fields->fieldByName('Root.Main.File');
44
            $fields->insertBefore('Content', $upload);
45
46
            // Set the height of the content fields
47
            $fields->fieldByName('Root.Main.Content')->setRows(5);
48
        });
49
50
        return parent::getCMSFields();
51
    }
52
}
53