← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+4
-61
4.2.3
→
4.1.0-beta1
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; |
| @@ -29,9 +28,8 @@ | ||
| 29 | 28 | * @mixin Element_Base |
| 30 | 29 | */ |
| 31 | 30 | trait Has_Atomic_Base { |
| 32 | 31 | use Has_Base_Styles; |
| 33 | - use Has_Base_Settings; | |
| 34 | 32 | |
| 35 | 33 | public function has_widget_inner_wrapper(): bool { |
| 36 | 34 | return false; |
| 37 | 35 | } |
| @@ -89,74 +87,23 @@ | ||
| 89 | 87 | |
| 90 | 88 | private function parse_atomic_styles( array $data ): array { |
| 91 | 89 | $styles = $data['styles'] ?? []; |
| 92 | 90 | $style_parser = Style_Parser::make( Style_Schema::get() ); |
| 93 | - $validated_styles = []; | |
| 94 | 91 | |
| 95 | 92 | foreach ( $styles as $style_id => $style ) { |
| 96 | 93 | $result = $style_parser->parse( $style ); |
| 97 | 94 | |
| 98 | 95 | if ( ! $result->is_valid() ) { |
| 99 | - Logger::warning( | |
| 100 | - $this->format_styles_validation_error_message( | |
| 101 | - $style_id, | |
| 102 | - $data, | |
| 103 | - $style, | |
| 104 | - $result->errors()->to_string() | |
| 105 | - ) | |
| 106 | - ); | |
| 107 | - continue; | |
| 96 | + $widget_id = $data['id'] ?? 'unknown'; | |
| 97 | + throw new \Exception( esc_html( "Styles validation failed for style `$style_id`. Widget ID: `$widget_id`. " . $result->errors()->to_string() ) ); | |
| 108 | 98 | } |
| 109 | 99 | |
| 110 | - $validated_styles[ $style_id ] = $result->unwrap(); | |
| 100 | + $styles[ $style_id ] = $result->unwrap(); | |
| 111 | 101 | } |
| 112 | 102 | |
| 113 | - return $validated_styles; | |
| 103 | + return $styles; | |
| 114 | 104 | } |
| 115 | 105 | |
| 116 | - private function format_styles_validation_error_message( | |
| 117 | - string $style_id, | |
| 118 | - array $data, | |
| 119 | - array $style, | |
| 120 | - string $validation_errors | |
| 121 | - ): string { | |
| 122 | - $widget_id = $data['id'] ?? 'unknown'; | |
| 123 | - $structure_label = $this->get_editor_structure_label( $data ); | |
| 124 | - $style_label = isset( $style['label'] ) && is_string( $style['label'] ) ? $style['label'] : null; | |
| 125 | - | |
| 126 | - $message_parts = [ | |
| 127 | - "Styles validation failed for style `$style_id` (widget `$widget_id`)", | |
| 128 | - ]; | |
| 129 | - | |
| 130 | - if ( $structure_label ) { | |
| 131 | - $message_parts[] = "Structure label: `$structure_label`"; | |
| 132 | - } else { | |
| 133 | - $element_name = $this->get_title(); | |
| 134 | - | |
| 135 | - if ( '' === $element_name ) { | |
| 136 | - $element_name = $this->get_name(); | |
| 137 | - } | |
| 138 | - | |
| 139 | - $message_parts[] = "Element: `$element_name`"; | |
| 140 | - } | |
| 141 | - | |
| 142 | - if ( $style_label ) { | |
| 143 | - $message_parts[] = "Style label: `$style_label`"; | |
| 144 | - } | |
| 145 | - | |
| 146 | - return implode( '. ', $message_parts ) . '. ' . $validation_errors; | |
| 147 | - } | |
| 148 | - | |
| 149 | - private function get_editor_structure_label( array $data ): ?string { | |
| 150 | - $title = $data['editor_settings']['title'] ?? $this->editor_settings['title'] ?? null; | |
| 151 | - | |
| 152 | - if ( ! is_string( $title ) || '' === $title ) { | |
| 153 | - return null; | |
| 154 | - } | |
| 155 | - | |
| 156 | - return $title; | |
| 157 | - } | |
| 158 | - | |
| 159 | 106 | private function parse_atomic_settings( array $settings ): array { |
| 160 | 107 | $schema = static::get_props_schema(); |
| 161 | 108 | $props_parser = Props_Parser::make( $schema ); |
| 162 | 109 | |
| @@ -354,12 +301,8 @@ | ||
| 354 | 301 | $editor_data = []; |
| 355 | 302 | |
| 356 | 303 | if ( isset( $data['title'] ) && is_string( $data['title'] ) ) { |
| 357 | 304 | $editor_data['title'] = sanitize_text_field( $data['title'] ); |
| 358 | - } | |
| 359 | - | |
| 360 | - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) { | |
| 361 | - $editor_data['grid_outline'] = $data['grid_outline']; | |
| 362 | 305 | } |
| 363 | 306 | |
| 364 | 307 | return $editor_data; |
| 365 | 308 | } |