Test Failed
Push — develop ( fe7dfd...f4a85b )
by Paul
08:21
created

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