← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+13
-59
4.3.0-beta3
→
4.2.1
View file →
| @@ -6,9 +6,8 @@ | ||
| 6 | 6 | use Elementor\Modules\AtomicWidgets\Controls\Base\Atomic_Control_Base; |
| 7 | 7 | use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 8 | 8 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Atomic_Form; |
| 9 | 9 | use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader; |
| 10 | -use Elementor\Modules\AtomicWidgets\Logger\Logger; | |
| 11 | 10 | use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver; |
| 12 | 11 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 13 | 12 | use Elementor\Modules\AtomicWidgets\Styles\Style_Schema; |
| 14 | 13 | use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser; |
| @@ -16,9 +15,8 @@ | ||
| 16 | 15 | use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 17 | 16 | use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type; |
| 18 | 17 | use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 19 | 18 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 20 | -use Elementor\Modules\AtomicWidgets\PropTypes\Prop_Duplication_Behavior; | |
| 21 | 19 | use Elementor\Utils; |
| 22 | 20 | use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 23 | 21 | use Elementor\Modules\AtomicWidgets\Styles\Atomic_Widget_Styles; |
| 24 | 22 | |
| @@ -32,18 +30,8 @@ | ||
| 32 | 30 | trait Has_Atomic_Base { |
| 33 | 31 | use Has_Base_Styles; |
| 34 | 32 | use Has_Base_Settings; |
| 35 | 33 | |
| 36 | - public static function html_tag_follows_link(): bool { | |
| 37 | - return true; | |
| 38 | - } | |
| 39 | - | |
| 40 | - public static function get_computed_html_tag( array $settings ): string { | |
| 41 | - return Html_Tag_Computer::compute( $settings, 'div', [ | |
| 42 | - Html_Tag_Computer::FOLLOW_LINK_OPTION => static::html_tag_follows_link(), | |
| 43 | - ] ); | |
| 44 | - } | |
| 45 | - | |
| 46 | 34 | public function has_widget_inner_wrapper(): bool { |
| 47 | 35 | return false; |
| 48 | 36 | } |
| 49 | 37 | |
| @@ -100,29 +88,22 @@ | ||
| 100 | 88 | |
| 101 | 89 | private function parse_atomic_styles( array $data ): array { |
| 102 | 90 | $styles = $data['styles'] ?? []; |
| 103 | 91 | $style_parser = Style_Parser::make( Style_Schema::get() ); |
| 104 | - $validated_styles = []; | |
| 105 | 92 | |
| 106 | 93 | foreach ( $styles as $style_id => $style ) { |
| 107 | 94 | $result = $style_parser->parse( $style ); |
| 108 | 95 | |
| 109 | 96 | if ( ! $result->is_valid() ) { |
| 110 | - Logger::warning( | |
| 111 | - $this->format_styles_validation_error_message( | |
| 112 | - $style_id, | |
| 113 | - $data, | |
| 114 | - $style, | |
| 115 | - $result->errors()->to_string() | |
| 116 | - ) | |
| 97 | + throw new \Exception( | |
| 98 | + esc_html( $this->format_styles_validation_error_message( $style_id, $data, $style, $result->errors()->to_string() ) ) | |
| 117 | 99 | ); |
| 118 | - continue; | |
| 119 | 100 | } |
| 120 | 101 | |
| 121 | - $validated_styles[ $style_id ] = $result->unwrap(); | |
| 102 | + $styles[ $style_id ] = $result->unwrap(); | |
| 122 | 103 | } |
| 123 | 104 | |
| 124 | - return $validated_styles; | |
| 105 | + return $styles; | |
| 125 | 106 | } |
| 126 | 107 | |
| 127 | 108 | private function format_styles_validation_error_message( |
| 128 | 109 | string $style_id, |
| @@ -247,45 +228,20 @@ | ||
| 247 | 228 | final public function get_data_for_save() { |
| 248 | 229 | $data = parent::get_data_for_save(); |
| 249 | 230 | |
| 250 | 231 | $data['version'] = $this->version; |
| 232 | + $data['settings'] = $this->parse_atomic_settings( $data['settings'] ); | |
| 233 | + $data['styles'] = $this->parse_atomic_styles( $data ); | |
| 234 | + $data['editor_settings'] = $this->parse_editor_settings( $data['editor_settings'] ); | |
| 251 | 235 | |
| 252 | - $this->set_data_field_for_save( | |
| 253 | - $data, | |
| 254 | - 'settings', | |
| 255 | - $this->parse_atomic_settings( $data['settings'] ?? [] ) | |
| 256 | - ); | |
| 257 | - | |
| 258 | - $this->set_data_field_for_save( | |
| 259 | - $data, | |
| 260 | - 'styles', | |
| 261 | - $this->parse_atomic_styles( $data ) | |
| 262 | - ); | |
| 263 | - | |
| 264 | - $this->set_data_field_for_save( | |
| 265 | - $data, | |
| 266 | - 'editor_settings', | |
| 267 | - $this->parse_editor_settings( $data['editor_settings'] ?? [] ) | |
| 268 | - ); | |
| 269 | - | |
| 270 | - $this->set_data_field_for_save( | |
| 271 | - $data, | |
| 272 | - 'interactions', | |
| 273 | - $this->transform_interactions_for_save( $data['interactions'] ?? [] ) | |
| 274 | - ); | |
| 275 | - | |
| 236 | + if ( isset( $data['interactions'] ) && ! empty( $data['interactions'] ) ) { | |
| 237 | + $data['interactions'] = $this->transform_interactions_for_save( $data['interactions'] ); | |
| 238 | + } else { | |
| 239 | + $data['interactions'] = []; | |
| 240 | + } | |
| 276 | 241 | return $data; |
| 277 | 242 | } |
| 278 | 243 | |
| 279 | - private function set_data_field_for_save( array &$data, string $key, $value ): void { | |
| 280 | - if ( ! empty( $value ) ) { | |
| 281 | - $data[ $key ] = $value; | |
| 282 | - return; | |
| 283 | - } | |
| 284 | - | |
| 285 | - unset( $data[ $key ] ); | |
| 286 | - } | |
| 287 | - | |
| 288 | 244 | private function transform_interactions_for_save( $interactions ) { |
| 289 | 245 | $decoded = $this->decode_interactions_data( $interactions ); |
| 290 | 246 | |
| 291 | 247 | if ( empty( $decoded['items'] ) ) { |
| @@ -403,11 +359,9 @@ | ||
| 403 | 359 | public static function get_props_schema(): array { |
| 404 | 360 | $schema = static::define_props_schema(); |
| 405 | 361 | |
| 406 | 362 | if ( ! isset( $schema['_cssid'] ) ) { |
| 407 | - $schema['_cssid'] = String_Prop_Type::make() | |
| 408 | - ->meta( Overridable_Prop_Type::ignore() ) | |
| 409 | - ->meta( Prop_Duplication_Behavior::clear() ); | |
| 363 | + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ); | |
| 410 | 364 | } |
| 411 | 365 | |
| 412 | 366 | return apply_filters( |
| 413 | 367 | 'elementor/atomic-widgets/props-schema', |