Test Failed
Push — develop ( 55c79d...550055 )
by Paul
09:38
created

MultiSwitcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A content_template() 0 16 1
A get_default_settings() 0 5 1
A get_type() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Elementor\Controls;
4
5
use Elementor\Base_Data_Control;
6
use GeminiLabs\SiteReviews\Helpers\Str;
7
8
class MultiSwitcher extends Base_Data_Control
9
{
10
    public function content_template(): void
11
    {
12
        $control_uid_input_type = '{{option}}';
13
        ?>
14
        <div class="elementor-control-type-switcher elementor-control-type-multi_switcher" style="display: grid; row-gap: 10px;">
15
            <# if ( data.label ) {#>
16
                <label class="elementor-control-title">{{{ data.label }}}</label>
17
            <# } #>
18
            <input type="hidden" data-setting="{{ data.name }}" value="{{ data.controlValue || '' }}" />
19
            <# var values = data.controlValue ? data.controlValue.split(',').filter(Boolean) : []; #>
20
            <# _.each( data.options, function( label, option ) { #>
21
            <div class="elementor-control-field" style="display: grid; grid-template-columns: 1fr auto;">
22
                <label for="<?php $this->print_control_uid($control_uid_input_type); ?>" class="elementor-control-title">{{{ label }}}</label>
23
                <div class="elementor-control-input-wrapper">
24
                    <label class="elementor-switch elementor-control-unit-2">
25
                        <input id="<?php $this->print_control_uid($control_uid_input_type); ?>"
26
                            type="checkbox"
27
                            class="elementor-switch-input"
28
                            value="{{ option }}"
29
                            <# if ( values.includes(option) ) { #>checked<# } #>
30
                        />
31
                        <span class="elementor-switch-label" data-on="{{ data.label_on }}" data-off="{{ data.label_off }}"></span>
32
                        <span class="elementor-switch-handle"></span>
33
                    </label>
34
                </div>
35
            </div>
36
            <# } ); #>
37
        </div>
38
        <# if ( data.description ) { #>
39
        <div class="elementor-control-field-description">{{{ data.description }}}</div>
40
        <# } #>
41
        <?php
42
    }
43
44
    public function get_type(): string
45
    {
46
        return 'multi_switcher';
47
    }
48
49
    protected function get_default_settings()
50
    {
51
        return [
52
            'label_off' => esc_html_x('No', 'admin-text', 'site-reviews'),
53
            'label_on' => esc_html_x('Yes', 'admin-text', 'site-reviews'),
54
        ];
55
    }
56
}
57