Passed
Push — develop ( 619418...263289 )
by Paul
15:51
created

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