Passed
Pull Request — 2.x (#1360)
by Harings
11:37
created

BlockEditor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
A render() 0 6 1
1
<?php
2
3
namespace A17\Twill\View\Components;
4
5
use Illuminate\Support\Str;
6
7
class BlockEditor extends TwillFormComponent
8
{
9
    public $blocks = [];
10
    public $groups = [];
11
    public $group;
12
    public $allowedBlocks;
13
    public $title;
14
    public $trigger;
15
    public $withoutSeparator;
16
17
    public function __construct(
18
        $label = null,
19
        $name = 'default',
20
        $renderForBlocks = false,
21
        $renderForModal = false,
22
        $trigger = null,
23
        $title = null,
24
        $blocks = [],
25
        $groups = [],
26
        $group = null,
27
        $withoutSeparator = false
28
    ) {
29
        parent::__construct($name, $label, $renderForBlocks, $renderForModal);
30
        $this->trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content');
31
        $this->blocks = $blocks;
32
        $this->groups = $groups;
33
        $this->group = $group;
34
        $this->allowedBlocks = generate_list_of_available_blocks(
35
            $this->blocks ?? null,
36
            $this->group ?? $this->groups ?? null
37
        );
38
        $this->title = $title ?? Str::title($name);
39
        $this->withoutSeparator = $withoutSeparator;
40
    }
41
42
    public function render()
43
    {
44
        return view('twill::partials.form._block_editor', [
45
            'editorName' => [
46
                'label' => $this->title,
47
                'value' => $this->name,
48
            ],
49
        ]);
50
    }
51
}
52