PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.1
Elementor Website Builder – more than just a page builder v3.34.1
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/variables/services/variables-service.php +3 -51 4.2.33.34.1 View file →
@@ -7,10 +7,8 @@
7 7 use Elementor\Modules\Variables\Storage\Entities\Variable;
8 8 use Elementor\Modules\Variables\Storage\Exceptions\BatchOperationFailed;
9 9 use Elementor\Modules\Variables\Storage\Variables_Repository;
10 10 use Elementor\Modules\Variables\Storage\Exceptions\FatalError;
11 -use Elementor\Modules\Variables\PropTypes\Size_Variable_Prop_Type;
12 -use Elementor\Utils as ElementorUtils;
13 11
14 12 class Variables_Service {
15 13 private Variables_Repository $repo;
16 14 private Batch_Processor $batch_processor;
@@ -23,49 +21,10 @@
23 21 public function get_variables_list(): array {
24 22 return $this->load()['data'];
25 23 }
26 24
27 - public function find_by_label_or_id( string $needle ): ?array {
28 - $needle = trim( $needle );
29 - $needle = ltrim( $needle, '-' );
30 -
31 - if ( '' === $needle ) {
32 - return null;
33 - }
34 -
35 - $variables = $this->get_variables_list();
36 -
37 - if ( isset( $variables[ $needle ] ) ) {
38 - $variable = $variables[ $needle ];
39 -
40 - if ( ! empty( $variable['deleted'] ) ) {
41 - return null;
42 - }
43 -
44 - return array_merge( [ 'id' => $needle ], $variable );
45 - }
46 -
47 - foreach ( $variables as $id => $variable ) {
48 - if ( ! empty( $variable['deleted'] ) ) {
49 - continue;
50 - }
51 -
52 - if ( strcasecmp( $variable['label'] ?? '', $needle ) === 0 ) {
53 - return array_merge( [ 'id' => $id ], $variable );
54 - }
55 - }
56 -
57 - return null;
58 - }
59 -
60 25 public function load() {
61 - $collection = $this->repo->load()->serialize( true );
62 - foreach ( $collection['data'] as $id => $variable ) {
63 - if ( ! ElementorUtils::has_pro() && Size_Variable_Prop_Type::get_key() === $variable['type'] ) {
64 - unset( $collection['data'][ $id ] );
65 - }
66 - }
67 - return $collection;
26 + return $this->repo->load()->serialize( true );
68 27 }
69 28
70 29 /**
71 30 * @throws BatchOperationFailed Thrown when one of the operations fails.
@@ -126,9 +85,8 @@
126 85 $data['order'] = $collection->get_next_order();
127 86 }
128 87
129 88 $variable = Variable::from_array( $data );
130 - $variable->validate();
131 89
132 90 $collection->add_variable( $variable );
133 91
134 92 $watermark = $this->repo->save( $collection );
@@ -154,9 +112,8 @@
154 112 $collection->assert_label_is_unique( $data['label'], $id );
155 113 }
156 114
157 115 $variable->apply_changes( $data );
158 - $variable->validate();
159 116
160 117 $watermark = $this->repo->save( $collection );
161 118
162 119 if ( false === $watermark ) {
@@ -199,20 +156,15 @@
199 156 public function restore( string $id, $overrides = [] ) {
200 157 $collection = $this->repo->load();
201 158 $variable = $collection->find_or_fail( $id );
202 159
203 - $label = $variable->label();
160 + $collection->assert_limit_not_reached();
204 161
205 162 if ( isset( $overrides['label'] ) ) {
206 - $label = $overrides['label'];
163 + $collection->assert_label_is_unique( $overrides['label'], $variable->id() );
207 164 }
208 165
209 - $collection->assert_limit_not_reached();
210 -
211 - $collection->assert_label_is_unique( $label, $variable->id() );
212 -
213 166 $variable->apply_changes( $overrides );
214 - $variable->validate();
215 167
216 168 $variable->restore();
217 169
218 170 $watermark = $this->repo->save( $collection );