Test Failed
Push — develop ( 3d09b8...3eede0 )
by Paul
16:09
created

Module::colorStyleDeclaration()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 9.9666
cc 3
nc 1
nop 1
crap 12
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Divi\Modules\SiteReviewsForm;
4
5
use ET\Builder\FrontEnd\Module\Style;
6
use ET\Builder\Packages\StyleLibrary\Utils\StyleDeclarations;
7
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
8
use GeminiLabs\SiteReviews\Integrations\Divi\Defaults\ModuleClassnamesDefaults;
9
use GeminiLabs\SiteReviews\Integrations\Divi\Defaults\ModuleStylesDefaults;
10
use GeminiLabs\SiteReviews\Integrations\Divi\Modules\DiviModule;
11
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsFormShortcode;
12
13
class Module extends DiviModule
14
{
15
    public static function blockName(): string
16
    {
17
        return 'glsr-divi/form';
18
    }
19
20
    /**
21
     * This method is equivalent to "module-classnames.ts".
22
     */
23
    public static function module_classnames(array $args): void
24
    {
25
        $args = glsr(ModuleClassnamesDefaults::class)->merge($args);
26
        $ratingColor = $args['attrs']['design']['decoration']['ratingColor']['desktop']['value'] ?? '';
27
        $args['classnamesInstance']->add('has-custom-color', !empty($ratingColor));
28
        parent::module_classnames($args);
29
    }
30
31
    /**
32
     * This method is equivalent to "module-styles.tsx".
33
     */
34
    public static function module_styles(array $args): void
35
    {
36
        $args = glsr(ModuleStylesDefaults::class)->merge($args);
37
        $attrs = $args['attrs'];
38
        $baseSelector = '.et-db #page-container .et_pb_section';
39
        $elements = $args['elements'];
40
        $orderClass = $args['orderClass'];
41
        $settings = $args['settings'];
42
        Style::add([
43
            'id' => $args['id'],
44
            'name' => $args['name'],
45
            'orderIndex' => $args['orderIndex'],
46
            'storeInstance' => $args['storeInstance'],
47
            'styles' => [
48
                $elements->style([
49
                    'attrName' => 'module',
50
                    'styleProps' => [
51
                        'advancedStyles' => [
52
                            [
53
                                'componentName' => 'divi/common',
54
                                'props' => [
55
                                    'attr' => $attrs['module']['advanced']['text']['text'] ?? [],
56
                                    'declarationFunction' => static::orientationStyleDeclaration(),
57
                                    'selector' => implode(',', [
58
                                        "{$baseSelector} {$orderClass} .glsr-field:not(.glsr-layout-inline) .glsr-field-subgroup > *",
59
                                        "{$baseSelector} {$orderClass} .glsr-layout-inline .glsr-field-subgroup",
60
                                        "{$baseSelector} {$orderClass} .glsr-range-options input:checked + label",
61
                                        "{$baseSelector} {$orderClass} .glsr-range-options:not(:has(input:checked))::after",
62
                                        "{$baseSelector} {$orderClass} .glsr-star-rating",
63
                                    ]),
64
                                ],
65
                            ],
66
                            [
67
                                'componentName' => 'divi/text',
68
                                'props' => [
69
                                    'attr' => $attrs['module']['advanced']['text'] ?? [],
70
                                    'propertySelectors' => [
71
                                        'textShadow' => [
72
                                            'desktop' => [
73
                                                'value' => [
74
                                                    'text-shadow' => implode(',', [
75
                                                        "{$baseSelector} {$orderClass} .glsr-field",
76
                                                        "{$baseSelector} {$orderClass} .glsr-input",
77
                                                        "{$baseSelector} {$orderClass} .glsr-select",
78
                                                        "{$baseSelector} {$orderClass} .glsr-textarea",
79
                                                    ]),
80
                                                ],
81
                                            ],
82
                                        ],
83
                                    ],
84
                                ],
85
                            ],
86
                        ],
87
                        'border' => [
88
                            'propertySelectors' => [
89
                                'desktop' => [
90
                                    'value' => [
91
                                        'border-radius' => implode(',', [
92
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-dropzone",
93
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input",
94
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input-checkbox",
95
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-select",
96
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-textarea",
97
                                        ]),
98
                                        'border-style' => implode(',', [
99
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-dropzone",
100
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input",
101
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input-checkbox",
102
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input-radio",
103
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-input-range",
104
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-select",
105
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-textarea",
106
                                            "{$baseSelector} {$orderClass} .glsr-form .glsr-toggle-track::before",
107
                                        ]),
108
                                    ],
109
                                ],
110
                            ],
111
                        ],
112
                        'boxShadow' => [
113
                            'selector' => implode(',', [
114
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-dropzone",
115
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-input",
116
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-input-checkbox",
117
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-input-radio",
118
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-input-range",
119
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-select",
120
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-textarea",
121
                                "{$baseSelector} {$orderClass} .glsr-form .glsr-toggle-track::before",
122
                            ]),
123
                        ],
124
                        'disabledOn' => [
125
                            'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null,
126
                        ],
127
                    ],
128
                ]),
129
                $elements->style([
130
                    'attrName' => 'button',
131
                ]),
132
            ],
133
        ]);
134
    }
135
136
    public static function shortcodeInstance(): ShortcodeContract
137
    {
138
        static $shortcode;
139
        if (empty($shortcode)) {
140
            $shortcode = glsr(SiteReviewsFormShortcode::class);
141
        }
142
        return $shortcode;
143
    }
144
145
    protected static function orientationStyleDeclaration(): callable
146
    {
147
        return static function (array $args): string {
148
            $orientation = $args['attrValue']['orientation'] ?? null;
149
            $declarations = new StyleDeclarations([
150
                'important' => true,
151
                'returnType' => 'string',
152
            ]);
153
            if ($orientation) {
154
                $declarations->add('display', 'flex');
155
                $declarations->add('justify-content', $orientation);
156
            }
157
            return $declarations->value();
158
        };
159
    }
160
}
161