← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+61
-4
4.1.0-beta1
→
4.2.4
View file →
| @@ -6,8 +6,9 @@ | ||
| 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; | |
| 10 | 11 | use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver; |
| 11 | 12 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 12 | 13 | use Elementor\Modules\AtomicWidgets\Styles\Style_Schema; |
| 13 | 14 | use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser; |
| @@ -28,8 +29,9 @@ | ||
| 28 | 29 | * @mixin Element_Base |
| 29 | 30 | */ |
| 30 | 31 | trait Has_Atomic_Base { |
| 31 | 32 | use Has_Base_Styles; |
| 33 | + use Has_Base_Settings; | |
| 32 | 34 | |
| 33 | 35 | public function has_widget_inner_wrapper(): bool { |
| 34 | 36 | return false; |
| 35 | 37 | } |
| @@ -87,23 +89,74 @@ | ||
| 87 | 89 | |
| 88 | 90 | private function parse_atomic_styles( array $data ): array { |
| 89 | 91 | $styles = $data['styles'] ?? []; |
| 90 | 92 | $style_parser = Style_Parser::make( Style_Schema::get() ); |
| 93 | + $validated_styles = []; | |
| 91 | 94 | |
| 92 | 95 | foreach ( $styles as $style_id => $style ) { |
| 93 | 96 | $result = $style_parser->parse( $style ); |
| 94 | 97 | |
| 95 | 98 | if ( ! $result->is_valid() ) { |
| 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() ) ); | |
| 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; | |
| 98 | 108 | } |
| 99 | 109 | |
| 100 | - $styles[ $style_id ] = $result->unwrap(); | |
| 110 | + $validated_styles[ $style_id ] = $result->unwrap(); | |
| 101 | 111 | } |
| 102 | 112 | |
| 103 | - return $styles; | |
| 113 | + return $validated_styles; | |
| 104 | 114 | } |
| 105 | 115 | |
| 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 | + | |
| 106 | 159 | private function parse_atomic_settings( array $settings ): array { |
| 107 | 160 | $schema = static::get_props_schema(); |
| 108 | 161 | $props_parser = Props_Parser::make( $schema ); |
| 109 | 162 | |
| @@ -301,8 +354,12 @@ | ||
| 301 | 354 | $editor_data = []; |
| 302 | 355 | |
| 303 | 356 | if ( isset( $data['title'] ) && is_string( $data['title'] ) ) { |
| 304 | 357 | $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']; | |
| 305 | 362 | } |
| 306 | 363 | |
| 307 | 364 | return $editor_data; |
| 308 | 365 | } |