Passed
Push — develop ( 682124...f6f5f6 )
by Paul
14:18
created

FusionElement::contentConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\FusionBuilder\Elements;
4
5
use GeminiLabs\SiteReviews\Integrations\FusionBuilder\Transformer;
6
use GeminiLabs\SiteReviews\Integrations\IntegrationShortcode;
7
8
abstract class FusionElement extends \Fusion_Element
9
{
10
    use IntegrationShortcode;
11
12
    abstract public function elementIcon(): string;
13
14
    public function elementParameters(array $additional = []): array
15
    {
16
        $controls = array_merge(
17
            $this->styleConfig(),
18
            $this->contentConfig(),
19
            $additional
20
        );
21
        $controls = glsr()->filterArray('fusion-builder/controls', $controls, $this->shortcodeInstance());
22
        $params = [];
23
        foreach ($controls as $name => $control) {
24
            $transformer = new Transformer($name, $control, $this->shortcodeInstance()->tag);
25
            if ($transformedControl = $transformer->control()) {
26
                $params[$name] = $transformedControl;
27
            }
28
        }
29
        return $params;
30
    }
31
32
    public static function registerElement(): void
33
    {
34
        $instance = new static();
35
        add_action('fusion_builder_before_init', function () use ($instance) {
36
            if (!function_exists('fusion_builder_map')) {
37
                return;
38
            }
39
            if (!function_exists('fusion_builder_frontend_data')) {
40
                return;
41
            }
42
            fusion_builder_map(fusion_builder_frontend_data(static::class, [
43
                'icon' => $instance->elementIcon(),
44
                'name' => $instance->shortcodeInstance()->name,
45
                'params' => $instance->elementParameters([
46
                    'from' => [
47
                        'type' => 'hidden',
48
                        'value' => 'avada',
49
                    ],
50
                ]),
51
                'shortcode' => $instance->shortcodeInstance()->tag,
52
            ]));
53
        });
54
    }
55
56
    protected function contentConfig(): array
57
    {
58
        return $this->shortcodeInstance()->settings();
59
    }
60
61
    protected function styleConfig(): array
62
    {
63
        return [];
64
    }
65
}
66