Test Failed
Push — develop ( c07ba6...801573 )
by Paul
08:42
created

ElementorFormWidget::shortcodeClass()   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 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Elementor;
4
5
use Elementor\Controls_Manager;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsFormShortcode;
8
9
class ElementorFormWidget extends ElementorWidget
10
{
11
    /**
12
     * @return string
13
     */
14
    public function get_icon()
15
    {
16
        return 'eicon-glsr-form';
17
    }
18
19
    public static function shortcodeClass(): string
20
    {
21
        return SiteReviewsFormShortcode::class;
22
    }
23
24
    protected function hide_if_all_fields_hidden(): bool
25
    {
26
        return true;
27
    }
28
29
    protected function settings_advanced(): array
30
    {
31
        $settings = parent::settings_advanced();
32
        $settings = Arr::insertAfter('shortcode_id', $settings, [
33
            'reviews_id' => [
34
                'description' => _x('Enter the Custom ID of a reviews block, shortcode, or widget where the review should be displayed after submission.', 'admin-text', 'site-reviews'),
35
                'label_block' => true,
36
                'label' => _x('Custom Reviews ID', 'admin-text', 'site-reviews'),
37
                'type' => Controls_Manager::TEXT,
38
            ],
39
        ]);
40
        return $settings;
41
    }
42
43
    protected function settings_basic(): array
44
    {
45
        $options = [
46
            'assigned_posts' => [
47
                'default' => '',
48
                'label' => _x('Assign Reviews to a Page', 'admin-text', 'site-reviews'),
49
                'label_block' => true,
50
                'options' => $this->assigned_posts_options(),
51
                'type' => Controls_Manager::SELECT2,
52
            ],
53
            'assigned_posts_custom' => [
54
                'condition' => ['assigned_posts' => 'custom'],
55
                'description' => _x('Separate values with a comma.', 'admin-text', 'site-reviews'),
56
                'label_block' => true,
57
                'placeholder' => _x('Enter the Post IDs', 'admin-text', 'site-reviews'),
58
                'show_label' => false,
59
                'type' => Controls_Manager::TEXT,
60
            ],
61
            // 'assigned_terms' => [
62
            //     'default' => '',
63
            //     'label' => _x('Assign Reviews to a Category', 'admin-text', 'site-reviews'),
64
            //     'label_block' => true,
65
            //     'multiple' => true,
66
            //     'options' => $this->assigned_terms_options(),
67
            //     'type' => Controls_Manager::SELECT2,
68
            // ],
69
            'assigned_terms' => [
70
                'default' => '',
71
                'label' => _x('Assign Reviews to a Category', 'admin-text', 'site-reviews'),
72
                'label_block' => true,
73
                'multiple' => true,
74
                'options' => [],
75
                'type' => Controls_Manager::SELECT2,
76
            ],
77
            'assigned_users' => [
78
                'default' => '',
79
                'label' => _x('Assign Reviews to a User', 'admin-text', 'site-reviews'),
80
                'label_block' => true,
81
                'options' => $this->assigned_users_options(),
82
                'type' => Controls_Manager::SELECT2,
83
            ],
84
            'assigned_users_custom' => [
85
                'condition' => ['assigned_users' => 'custom'],
86
                'description' => _x('Separate values with a comma.', 'admin-text', 'site-reviews'),
87
                'label_block' => true,
88
                'placeholder' => _x('Enter the User IDs', 'admin-text', 'site-reviews'),
89
                'show_label' => false,
90
                'type' => Controls_Manager::TEXT,
91
            ],
92
        ];
93
        $options = $this->insert_hide_controls($options);
94
        return $options;
95
    }
96
97
    protected function settings_layout(): array
98
    {
99
        return [
100
            'spacing' => [
101
                'default' => [
102
                    'unit' => 'em',
103
                    'size' => 0.75,
104
                ],
105
                'is_responsive' => true,
106
                'label' => esc_html_x('Field Spacing', 'admin-text', 'site-reviews'),
107
                'range' => [
108
                    'em' => [
109
                        'min' => 0,
110
                        'max' => 2,
111
                        'step' => 0.125,
112
                    ],
113
                ],
114
                'selectors' => [
115
                    '{{WRAPPER}} .glsr-review-form' => '--glsr-gap-md: {{SIZE}}{{UNIT}};',
116
                    '{{WRAPPER}} .elementor-form .elementor-form-fields-wrapper .glsr-field' => 'margin-bottom: {{SIZE}}{{UNIT}};',
117
                ],
118
                'size_units' => $this->set_custom_size_unit(['em']),
119
                'type' => Controls_Manager::SLIDER,
120
            ],
121
        ];
122
    }
123
124
    protected function settings_rating(): array
125
    {
126
        return [
127
            'rating_color' => [
128
                'global' => [
129
                    'default' => '',
130
                ],
131
                'label' => esc_html_x('Color', 'admin-text', 'site-reviews'),
132
                'selectors' => [
133
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-field:not(.glsr-field-is-invalid) .glsr-star-rating--stars > span' => 'background: {{VALUE}} !important;',
134
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-field-is-invalid .glsr-star-rating--stars > span.gl-active' => 'background: {{VALUE}} !important;',
135
                ],
136
                'type' => Controls_Manager::COLOR,
137
            ],
138
            'rating_size' => [
139
                'default' => [
140
                    'unit' => 'em',
141
                    'size' => 2,
142
                ],
143
                'is_responsive' => true,
144
                'label' => esc_html_x('Star Size', 'admin-text', 'site-reviews'),
145
                'range' => [
146
                    'em' => [
147
                        'min' => 1,
148
                        'max' => 3,
149
                        'step' => 0.125,
150
                    ],
151
                ],
152
                'selectors' => [
153
                    '{{WRAPPER}} form.glsr-form .glsr-field-rating' => '--glsr-form-star: {{SIZE}}{{UNIT}};',
154
                    '{{WRAPPER}} .glsr[data-theme] .glsr-field-rating [data-stars]' => 'font-size: initial;',
155
                    '{{WRAPPER}} .glsr[data-theme] .glsr-field-rating [data-stars] > span' => 'font-size: initial; height: var(--glsr-form-star); width: var(--glsr-form-star);',
156
                ],
157
                'size_units' => $this->set_custom_size_unit(['em']),
158
                'type' => Controls_Manager::SLIDER,
159
            ],
160
            'rating_spacing' => [
161
                'default' => [
162
                    'unit' => 'px',
163
                    'size' => 2,
164
                ],
165
                'is_responsive' => true,
166
                'label' => esc_html_x('Star Spacing', 'admin-text', 'site-reviews'),
167
                'range' => [
168
                    'px' => [
169
                        'min' => 0,
170
                        'max' => 10,
171
                    ],
172
                ],
173
                'selectors' => [
174
                    '{{WRAPPER}} form.glsr-form .glsr-field-rating span[data-rating]' => 'column-gap: {{SIZE}}{{UNIT}};',
175
                ],
176
                'size_units' => ['px'],
177
                'type' => Controls_Manager::SLIDER,
178
            ],
179
        ];
180
    }
181
}
182