Test Failed
Push — develop ( 1707fa...c6b569 )
by Paul
07:52
created

FlatsomeShortcode::uxShortcode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Flatsome;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
8
abstract class FlatsomeShortcode
9
{
10
    abstract public function options(): array;
11
12
    /**
13
     * Override the "add_ux_builder_shortcode" data with
14
     * the "ux_builder_shortcode_data_{$tag}" filter hook.
15
     */
16
    public function register(): void
17
    {
18
        add_action('ux_builder_setup', function () {
19
            add_ux_builder_shortcode($this->shortcode()->shortcode, [
0 ignored issues
show
Bug introduced by
The function add_ux_builder_shortcode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            /** @scrutinizer ignore-call */ 
20
            add_ux_builder_shortcode($this->shortcode()->shortcode, [
Loading history...
20
                'category' => glsr()->name,
21
                // 'inline' => true,
22
                'name' => $this->name(),
23
                'options' => $this->options(),
24
                'thumbnail' => $this->icon(),
25
                'wrap' => false,
26
            ]);
27
        });
28
    }
29
30
    protected function hideOptions(): array
31
    {
32
        return [
33
            'hide' => [
34
                'type' => 'select',
35
                'heading' => esc_html_x('Hide Fields', 'admin-text', 'site-reviews'),
36
                'description' => esc_html_x('Flatsome UX Builder does not support multiple checkboxes here so instead please use the dropdown to select fields that you want to hide.', 'admin-text', 'site-reviews'),
37
                'full_width' => true,
38
                'config' => [
39
                    'multiple' => true,
40
                    'options' => $this->shortcode()->getHideOptions(),
41
                    'placeholder' => esc_html_x('Select...', 'admin-text', 'site-reviews'),
42
                    'sortable' => false,
43
                ],
44
            ],
45
        ];
46
    }
47
48
    abstract protected function icon(): string;
49
50
    protected function name(): string
51
    {
52
        return $this->shortcode()->name;
53
    }
54
55
    abstract protected function shortcode(): ShortcodeContract;
56
57
    protected function typeOptions(): array
58
    {
59
        $types = glsr()->retrieveAs('array', 'review_types', []);
60
        if (2 > count($types)) {
61
            return [];
62
        }
63
        return [
64
            'type' => 'select',
65
            'heading' => esc_html_x('Limit Reviews by Type', 'admin-text', 'site-reviews'),
66
            'full_width' => true,
67
            'default' => 'local',
68
            'options' => $types,
69
        ];
70
    }
71
}
72