1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Bricks; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Helper; |
7
|
|
|
|
8
|
|
|
abstract class BricksElement extends \Bricks\Element |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
public $nestable = false; |
11
|
|
|
public $scripts = ['GLSR_init']; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var ShortcodeContract |
15
|
|
|
*/ |
16
|
|
|
protected $elShortcode; |
17
|
|
|
|
18
|
|
|
public function __construct($element = null) |
19
|
|
|
{ |
20
|
|
|
$this->category = glsr()->id; |
|
|
|
|
21
|
|
|
$this->elShortcode = static::shortcode(); |
22
|
|
|
$this->icon = "ti-{$this->elShortcode->tag}"; |
|
|
|
|
23
|
|
|
$this->name = $this->elShortcode->tag; |
|
|
|
|
24
|
|
|
parent::__construct($element); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function elementConfig(): array |
28
|
|
|
{ |
29
|
|
|
return $this->elShortcode->settings(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function get_keywords() |
33
|
|
|
{ |
34
|
|
|
return ['review', 'reviews', 'site reviews']; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function get_label() |
38
|
|
|
{ |
39
|
|
|
return $this->elShortcode->name; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function load() |
43
|
|
|
{ |
44
|
|
|
parent::load(); |
45
|
|
|
$groups = array_map(fn ($args) => $args['group'] ?? '', $this->controls); |
46
|
|
|
$groups = array_filter($groups, fn ($value) => !str_starts_with($value, '_')); |
47
|
|
|
$groups = array_values(array_filter(array_unique($groups))); |
48
|
|
|
foreach ($this->control_groups as $key => $value) { |
49
|
|
|
if (str_starts_with($key, '_')) { |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
if (in_array($key, $groups)) { |
53
|
|
|
continue; |
54
|
|
|
} |
55
|
|
|
unset($this->control_groups[$key]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public static function registerElement(): void |
60
|
|
|
{ |
61
|
|
|
$reflection = new \ReflectionClass(static::class); |
62
|
|
|
$file = $reflection->getFileName(); |
63
|
|
|
$name = static::shortcode()->tag; |
|
|
|
|
64
|
|
|
$className = $reflection->getName(); |
65
|
|
|
\Bricks\Elements::register_element($file, $name, $className); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function render() |
69
|
|
|
{ |
70
|
|
|
echo "<{$this->get_tag()} {$this->render_attributes('_root')}>"; |
71
|
|
|
echo $this->elShortcode->build($this->settings, 'bricks'); |
72
|
|
|
echo "</{$this->get_tag()}>"; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @see https://academy.bricksbuilder.io/article/filter-bricks-elements-element_name-control_groups/ |
77
|
|
|
*/ |
78
|
|
|
public function set_control_groups() |
79
|
|
|
{ |
80
|
|
|
$groups = [ // order is intentional |
81
|
|
|
'display' => esc_html_x('Display', 'admin-text', 'site-reviews'), |
82
|
|
|
'hide' => esc_html_x('Hide', 'admin-text', 'site-reviews'), |
83
|
|
|
'schema' => esc_html_x('Schema', 'admin-text', 'site-reviews'), |
84
|
|
|
'advanced' => esc_html_x('Advanced', 'admin-text', 'site-reviews'), |
85
|
|
|
]; |
86
|
|
|
foreach ($groups as $key => $title) { |
87
|
|
|
$this->control_groups[$key] = [ |
|
|
|
|
88
|
|
|
'tab' => 'content', |
89
|
|
|
'title' => $title, |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @see https://academy.bricksbuilder.io/article/filter-bricks-elements-element_name-controls |
96
|
|
|
*/ |
97
|
|
|
public function set_controls() |
98
|
|
|
{ |
99
|
|
|
foreach ($this->elementConfig() as $key => $args) { |
100
|
|
|
$args = wp_parse_args($args, [ |
101
|
|
|
'group' => '', |
102
|
|
|
// 'hasDynamicData' => false, |
103
|
|
|
// 'hasVariables' => true, |
104
|
|
|
'tab' => 'content', |
105
|
|
|
'type' => 'text', |
106
|
|
|
]); |
107
|
|
|
if (!array_key_exists($args['group'], $this->control_groups)) { |
108
|
|
|
$args['group'] = ''; |
109
|
|
|
} |
110
|
|
|
$method = Helper::buildMethodName('set', $args['type'], 'control'); |
111
|
|
|
if (!method_exists($this, $method)) { |
112
|
|
|
$this->controls[$key] = $args; |
|
|
|
|
113
|
|
|
continue; |
114
|
|
|
} |
115
|
|
|
call_user_func([$this, $method], $key, $args); |
116
|
|
|
} |
117
|
|
|
if (count(glsr()->retrieveAs('array', 'review_types', [])) < 2) { |
118
|
|
|
unset($this->controls['type']); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
abstract public static function shortcode(): ShortcodeContract; |
123
|
|
|
|
124
|
|
|
protected function setCheckboxControl(string $key, array $args): void |
125
|
|
|
{ |
126
|
|
|
if (empty($args['options'])) { |
127
|
|
|
$this->controls[$key] = $args; |
|
|
|
|
128
|
|
|
return; |
129
|
|
|
} |
130
|
|
|
foreach ($args['options'] as $value => $label) { |
131
|
|
|
$this->controls["{$key}_{$value}"] = [ |
132
|
|
|
'default' => false, |
133
|
|
|
'group' => $args['group'], |
134
|
|
|
'label' => $label, |
135
|
|
|
'tab' => 'content', |
136
|
|
|
'type' => 'checkbox', |
137
|
|
|
]; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
protected function setNumberControl(string $key, array $args): void |
142
|
|
|
{ |
143
|
|
|
$control = [ |
144
|
|
|
// 'small' => true, |
145
|
|
|
'type' => 'slider', |
146
|
|
|
'units' => false, |
147
|
|
|
]; |
148
|
|
|
$this->controls[$key] = wp_parse_args($control, $args); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
protected function setSelectControl(string $key, array $args): void |
152
|
|
|
{ |
153
|
|
|
if (!in_array($key, ['assigned_posts', 'assigned_terms', 'assigned_users', 'post_id'])) { |
154
|
|
|
$this->controls[$key] = $args; |
|
|
|
|
155
|
|
|
return; |
156
|
|
|
} |
157
|
|
|
$control = [ |
158
|
|
|
'type' => 'select', |
159
|
|
|
'searchable' => true, |
160
|
|
|
'optionsAjax' => ['action' => "bricks_glsr_{$key}"], |
161
|
|
|
]; |
162
|
|
|
if ('post_id' !== $key) { |
163
|
|
|
$control['multiple'] = true; |
164
|
|
|
} |
165
|
|
|
$this->controls[$key] = wp_parse_args($control, $args); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths