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

BannerBlock::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 27
rs 8.8571
cc 1
eloc 13
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
use SilverStripe\View\Requirements;
9
10
class BannerBlock extends FileBlock
11
{
12
    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...
13
        'Content' => 'HTMLText',
14
    ];
15
16
    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...
17
        'ImageLink' => Link::class,
18
        'CallToActionLink' => Link::class,
19
    ];
20
21
    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...
22
23
    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...
24
25
    public function getType()
26
    {
27
        return _t(__CLASS__ . '.BlockType', 'Banner');
28
    }
29
30
    public function getCMSFields()
31
    {
32
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
33
            // Remove default scaffolded relationship fields
34
            $fields->removeByName('ImageLinkID');
35
            $fields->removeByName('CallToActionLinkID');
36
37
            // Create hidden inputs for JSON input from the "insert link" modal
38
            $fields->addFieldsToTab('Root.Main', [
39
                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

39
                HiddenField::create(/** @scrutinizer ignore-type */ 'ImageLinkData'),
Loading history...
40
                HiddenField::create('CallToActionLinkData'),
41
            ]);
42
43
            // Move the file upload field to the right place in the UI
44
            $upload = $fields->fieldByName('Root.Main.File');
45
            $fields->insertBefore('Content', $upload);
46
47
            // Set the height of the content fields
48
            $fields->fieldByName('Root.Main.Content')->setRows(5);
49
50
            $fields->addFieldToTab('Root.Main', \SilverStripe\Forms\LiteralField::create('test', '<button class="insert-link__dialog-wrapper--no-tinymce insert-link__dialog-wrapper--internal robbie" type="button">Click me...</button'));
51
        });
52
53
        Requirements::javascript('/assets/_tinymce/tinymce-cms-4a3f7622c2.js');
54
        Requirements::javascript('silverstripe/elemental-blocks:javascript/test.js');
55
56
        return parent::getCMSFields();
57
    }
58
}
59