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

BlockEditor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 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
        $trigger = null,
21
        $title = null,
22
        $blocks = [],
23
        $groups = [],
24
        $group = null,
25
        $withoutSeparator = false
26
    ) {
27
        parent::__construct($name, $label);
28
        $this->trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content');
29
        $this->blocks = $blocks;
30
        $this->groups = $groups;
31
        $this->group = $group;
32
        $this->allowedBlocks = generate_list_of_available_blocks(
33
            $this->blocks ?? null,
34
            $this->group ?? $this->groups ?? null
35
        );
36
        $this->title = $title ?? Str::title($name);
37
        $this->withoutSeparator = $withoutSeparator;
38
    }
39
40
    public function render()
41
    {
42
        return view('twill::partials.form._block_editor', [
43
            'editorName' => [
44
                'label' => $this->title,
45
                'value' => $this->name,
46
            ],
47
        ]);
48
    }
49
}
50