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

ElementorReviewWidget::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\Review;
7
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewShortcode;
8
9
class ElementorReviewWidget extends ElementorWidget
10
{
11
    /**
12
     * @return string
13
     */
14
    public function get_icon()
15
    {
16
        return 'eicon-glsr-review';
17
    }
18
19
    /**
20
     * @return string
21
     */
22
    public function get_shortcode()
23
    {
24
        return SiteReviewShortcode::class;
25
    }
26
27
    protected function hide_if_all_fields_hidden(): bool
28
    {
29
        return true;
30
    }
31
32
    protected function print_content()
33
    {
34
        if (Review::isReview($this->get_settings_for_display('post_id'))) {
35
            parent::print_content();
36
        }
37
    }
38
39
    protected function settings_basic(): array
40
    {
41
        $options = [
42
            'post_id' => [
43
                'default' => '',
44
                'label' => _x('Review Post ID', 'admin-text', 'site-reviews'),
45
                'type' => Controls_Manager::TEXT,
46
            ],
47
        ];
48
        $hideOptions = $this->get_shortcode_instance()->getHideOptions();
49
        foreach ($hideOptions as $key => $label) {
50
            $separator = $key === key(array_slice($hideOptions, 0, 1)) ? 'before' : 'default';
51
            $options["hide-{$key}"] = [
52
                'label' => $label,
53
                'separator' => $separator,
54
                'return_value' => '1',
55
                'type' => Controls_Manager::SWITCHER,
56
            ];
57
        }
58
        return $options;
59
    }
60
61
    protected function settings_layout(): array
62
    {
63
        return [
64
            'alignment' => [
65
                'default' => 'start',
66
                'is_responsive' => true,
67
                'label' => esc_html_x('Alignment', 'admin-text', 'site-reviews'),
68
                'options' => [
69
                    'start' => [
70
                        'title' => esc_html_x('Start', 'admin-text', 'site-reviews'),
71
                        'icon' => 'eicon-flex eicon-align-start-h',
72
                    ],
73
                    'center' => [
74
                        'title' => esc_html_x('Center', 'admin-text', 'site-reviews'),
75
                        'icon' => 'eicon-flex eicon-align-center-h',
76
                    ],
77
                    'end' => [
78
                        'title' => esc_html_x('End', 'admin-text', 'site-reviews'),
79
                        'icon' => 'eicon-flex eicon-align-end-h',
80
                    ],
81
                ],
82
                'selectors' => [
83
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review' => 'text-align: {{VALUE}}; justify-content: {{VALUE}};',
84
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-review-actions' => 'justify-content: {{VALUE}};',
85
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-review-date' => 'flex: inherit;',
86
                ],
87
                'type' => Controls_Manager::CHOOSE,
88
            ],
89
        ];
90
    }
91
92
    protected function settings_rating(): array
93
    {
94
        return [
95
            'rating_color' => [
96
                'global' => [
97
                    'default' => '',
98
                ],
99
                'label' => esc_html_x('Color', 'admin-text', 'site-reviews'),
100
                'selectors' => [
101
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-star-empty' => 'background: {{VALUE}} !important;',
102
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-star-full' => 'background: {{VALUE}} !important;',
103
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-star-half' => 'background: {{VALUE}} !important;',
104
                ],
105
                'type' => Controls_Manager::COLOR,
106
            ],
107
            'rating_size' => [
108
                'default' => [
109
                    'unit' => 'em',
110
                    'size' => 1.25,
111
                ],
112
                'is_responsive' => true,
113
                'label' => esc_html_x('Star Size', 'admin-text', 'site-reviews'),
114
                'range' => [
115
                    'em' => [
116
                        'min' => 0.25,
117
                        'max' => 2.25,
118
                        'step' => 0.125,
119
                    ],
120
                ],
121
                'selectors' => [
122
                    '{{WRAPPER}} .glsr:not([data-theme]) .glsr-review .glsr-star' => '--glsr-review-star: {{SIZE}}{{UNIT}};',
123
                ],
124
                'size_units' => $this->set_custom_size_unit(['em']),
125
                'type' => Controls_Manager::SLIDER,
126
            ],
127
        ];
128
    }
129
}
130