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/storage/entities/variable.php +2 -72 4.2.33.34.1 View file →
@@ -1,12 +1,8 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\Variables\Storage\Entities;
4 4
5 -use Elementor\Modules\Variables\Adapters\Prop_Type_Adapter;
6 -use Elementor\Modules\Variables\PropTypes\Size_Variable_Prop_Type;
7 -use Elementor\Modules\Variables\Storage\Exceptions\Type_Mismatch;
8 -use Elementor\Modules\Variables\Storage\Exceptions\InvalidVariable;
9 5 use InvalidArgumentException;
10 6
11 7 class Variable {
12 8 private array $data;
@@ -81,24 +77,12 @@
81 77 public function set_value( $value ) {
82 78 $this->data['value'] = $value;
83 79 }
84 80
85 - public function sync_to_v3(): bool {
86 - return ! empty( $this->data['sync_to_v3'] );
87 - }
88 -
89 - public function set_sync_to_v3( bool $sync_to_v3 ) {
90 - $this->data['sync_to_v3'] = $sync_to_v3;
91 - }
92 -
93 81 public function type() {
94 82 return $this->data['type'];
95 83 }
96 84
97 - public function set_type( $type ) {
98 - $this->data['type'] = $type;
99 - }
100 -
101 85 public function has_order(): int {
102 86 return isset( $this->data['order'] );
103 87 }
104 88
@@ -105,50 +89,12 @@
105 89 public function is_deleted(): bool {
106 90 return isset( $this->data['deleted_at'] );
107 91 }
108 92
109 - /**
110 - * @throws Type_Mismatch If a type that is not allowed to be changed is passed.
111 - */
112 - private function maybe_apply_type( array $data ) {
113 - if ( ! array_key_exists( 'type', $data ) ) {
114 - return false;
115 - }
116 -
117 - $current_type = $this->type();
118 - $target_type = $data['type'];
119 -
120 - if ( $current_type === $target_type ) {
121 - return false;
122 - }
123 -
124 - $custom_size_prop_type = Prop_Type_Adapter::GLOBAL_CUSTOM_SIZE_VARIABLE_KEY;
125 - $size_prop_type = Size_Variable_Prop_Type::get_key();
126 -
127 - $allowed_types = [ $custom_size_prop_type, $size_prop_type ];
128 -
129 - $is_valid_transition =
130 - in_array( $current_type, $allowed_types, true ) &&
131 - in_array( $target_type, $allowed_types, true );
132 -
133 - if ( ! $is_valid_transition ) {
134 - throw new Type_Mismatch( 'Type change is forbidden' );
135 - }
136 -
137 - $this->set_type( $data['type'] );
138 -
139 - return true;
140 - }
141 -
142 - /**
143 - * @throws InvalidVariable If the variable is not valid.
144 - */
145 93 public function apply_changes( array $data ): void {
146 - $this->validate();
94 + $allowed_fields = [ 'label', 'value', 'order' ];
95 + $has_changes = false;
147 96
148 - $allowed_fields = [ 'label', 'value', 'order', 'type', 'sync_to_v3' ];
149 - $has_changes = $this->maybe_apply_type( $data );
150 -
151 97 foreach ( $allowed_fields as $field ) {
152 98 if ( isset( $data[ $field ] ) ) {
153 99 $this->data[ $field ] = $data[ $field ];
154 100
@@ -158,22 +104,6 @@
158 104
159 105 if ( $has_changes ) {
160 106 $this->data['updated_at'] = $this->now();
161 107 }
162 - }
163 -
164 - /**
165 - * @return bool True if the variable is valid, throws an exception otherwise.
166 - * @throws InvalidVariable If the variable is not valid.
167 - */
168 - public function validate(): bool {
169 - if ( strpos( $this->label(), ' ' ) !== false ) {
170 - throw new InvalidVariable( 'Label cannot contain spaces' );
171 - }
172 -
173 - if ( strlen( $this->label() ) > 50 ) {
174 - throw new InvalidVariable( 'Label cannot be longer than 50 characters' );
175 - }
176 -
177 - return true;
178 108 }
179 109 }