Passed
Push — develop ( 3846cd...70fb5e )
by Paul
13:44
created

ElementTrait::settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 2
b 0
f 2
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Breakdance;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
use GeminiLabs\SiteReviews\Helpers\Str;
8
9
trait ElementTrait
10
{
11
    /**
12
     * @return array
13
     */
14
    public static function actions()
15
    {
16
        return glsr()->filterArray('breakdance/actions',
17
            static::bdActions(),
18
            static::bdShortcode()
19
        );
20
    }
21
22
    /**
23
     * @return array<array{name: string, template: string}>|false
24
     */
25
    public static function additionalClasses()
26
    {
27
        $classes = glsr()->filterArray('breakdance/additional_classes', [], static::bdShortcode());
28
        return empty($classes) ? false : $classes;
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public static function badge()
35
    {
36
        return [
37
            'backgroundColor' => '',
38
            'label' => ' ', // empty because we use this to display an icon
39
            'textColor' => '',
40
        ];
41
    }
42
43
    public static function bdActions(): array
44
    {
45
        return [
46
            'onMountedElement' => [[
47
                'script' => 'GLSR_init();',
48
            ]],
49
            // 'onPropertyChange' => [[
50
            //     'script' => 'GLSR_init();',
51
            // ]],
52
        ];
53
    }
54
55
    public static function bdDependencies(): array
56
    {
57
        return [
58
            [
59
                'builderCondition' => 'return true;',
60
                'frontendCondition' => 'return false;',
61
                'inlineStyles' => [
62
                    '%%SELECTOR%% a, %%SELECTOR%% button {pointer-events: none}',
63
                ],
64
            ],
65
        ];
66
    }
67
68
    abstract public static function bdShortcode(): ShortcodeContract;
69
70
    abstract public static function bdShortcodeClass(): string;
71
72
    /**
73
     * @return string
74
     */
75
    public static function category()
76
    {
77
        return glsr()->id;
78
    }
79
80
    public static function cssTemplate()
81
    {
82
        return glsr()->filterString('breakdance/css_template',
83
            static::bdFileContents('css.twig'),
84
            static::bdShortcode()
85
        );
86
    }
87
88
    public static function className()
89
    {
90
        return 'breakdance-'.Str::dashCase(static::bdShortcode()->tag);
91
    }
92
93
    public static function defaultCss()
94
    {
95
        return glsr()->filterString('breakdance/default_css',
96
            static::bdFileContents('default.css'),
97
            static::bdShortcode()
98
        );
99
    }
100
101
    public static function dependencies()
102
    {
103
        return glsr()->filterArray('breakdance/dependencies',
104
            static::bdDependencies(),
105
            static::bdShortcode()
106
        );
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public static function name()
113
    {
114
        return static::bdShortcode()->name();
115
    }
116
117
    /**
118
     * @return array
119
     */
120
    public static function nestingRule()
121
    {
122
        return [
123
            'type' => 'final',
124
        ];
125
    }
126
127
    /**
128
     * @return string[]
129
     */
130
    public static function propertyPathsToSsrElementWhenValueChanges()
131
    {
132
        return [
133
            'content',
134
            // 'design',
135
        ];
136
    }
137
138
    /**
139
     * @return array
140
     */
141
    public static function settings()
142
    {
143
        return [
144
            'bypassPointerEvents' => true,
145
            'disableAI' => true,
146
        ];
147
    }
148
149
    /**
150
     * @return array[]
151
     */
152
    public static function settingsControls()
153
    {
154
        return [];
155
    }
156
157
    /**
158
     * @param mixed $propertiesData
159
     * @param mixed $parentPropertiesData
160
     * @param bool  $isBuilder
161
     * @param int   $repeaterItemNodeId
162
     *
163
     * @return string
164
     */
165
    public static function ssr($propertiesData, $parentPropertiesData = [], $isBuilder = false, $repeaterItemNodeId = null)
166
    {
167
        $args = static::ssrArgs(Arr::consolidate($propertiesData));
168
        return static::bdShortcode()->build($args, 'breakdance', false);
169
    }
170
171
    abstract public static function ssrArgs(array $propertiesData): array;
172
173
    /**
174
     * @return string
175
     */
176
    public static function slug()
177
    {
178
        return __CLASS__;
179
    }
180
181
    /**
182
     * @return string
183
     */
184
    public static function template()
185
    {
186
        return '%%SSR%%';
187
    }
188
189
    protected static function bdFileContents(string $file): string
190
    {
191
        $reflector = new \ReflectionClass(static::class);
192
        $dir = dirname($reflector->getFileName());
193
        $file = "{$dir}/$file";
194
        return file_exists($file) ? file_get_contents($file) : '';
195
    }
196
}
197