← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+2
-51
4.2.0-beta2
→
4.1.4
View file →
| @@ -28,9 +28,8 @@ | ||
| 28 | 28 | * @mixin Element_Base |
| 29 | 29 | */ |
| 30 | 30 | trait Has_Atomic_Base { |
| 31 | 31 | use Has_Base_Styles; |
| 32 | - use Has_Base_Settings; | |
| 33 | 32 | |
| 34 | 33 | public function has_widget_inner_wrapper(): bool { |
| 35 | 34 | return false; |
| 36 | 35 | } |
| @@ -93,11 +92,10 @@ | ||
| 93 | 92 | foreach ( $styles as $style_id => $style ) { |
| 94 | 93 | $result = $style_parser->parse( $style ); |
| 95 | 94 | |
| 96 | 95 | if ( ! $result->is_valid() ) { |
| 97 | - throw new \Exception( | |
| 98 | - esc_html( $this->format_styles_validation_error_message( $style_id, $data, $style, $result->errors()->to_string() ) ) | |
| 99 | - ); | |
| 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() ) ); | |
| 100 | 98 | } |
| 101 | 99 | |
| 102 | 100 | $styles[ $style_id ] = $result->unwrap(); |
| 103 | 101 | } |
| @@ -104,51 +102,8 @@ | ||
| 104 | 102 | |
| 105 | 103 | return $styles; |
| 106 | 104 | } |
| 107 | 105 | |
| 108 | - private function format_styles_validation_error_message( | |
| 109 | - string $style_id, | |
| 110 | - array $data, | |
| 111 | - array $style, | |
| 112 | - string $validation_errors | |
| 113 | - ): string { | |
| 114 | - $widget_id = $data['id'] ?? 'unknown'; | |
| 115 | - $structure_label = $this->get_editor_structure_label( $data ); | |
| 116 | - $style_label = isset( $style['label'] ) && is_string( $style['label'] ) ? $style['label'] : null; | |
| 117 | - | |
| 118 | - $message_parts = [ | |
| 119 | - "Styles validation failed for style `$style_id` (widget `$widget_id`)", | |
| 120 | - ]; | |
| 121 | - | |
| 122 | - if ( $structure_label ) { | |
| 123 | - $message_parts[] = "Structure label: `$structure_label`"; | |
| 124 | - } else { | |
| 125 | - $element_name = $this->get_title(); | |
| 126 | - | |
| 127 | - if ( '' === $element_name ) { | |
| 128 | - $element_name = $this->get_name(); | |
| 129 | - } | |
| 130 | - | |
| 131 | - $message_parts[] = "Element: `$element_name`"; | |
| 132 | - } | |
| 133 | - | |
| 134 | - if ( $style_label ) { | |
| 135 | - $message_parts[] = "Style label: `$style_label`"; | |
| 136 | - } | |
| 137 | - | |
| 138 | - return implode( '. ', $message_parts ) . '. ' . $validation_errors; | |
| 139 | - } | |
| 140 | - | |
| 141 | - private function get_editor_structure_label( array $data ): ?string { | |
| 142 | - $title = $data['editor_settings']['title'] ?? $this->editor_settings['title'] ?? null; | |
| 143 | - | |
| 144 | - if ( ! is_string( $title ) || '' === $title ) { | |
| 145 | - return null; | |
| 146 | - } | |
| 147 | - | |
| 148 | - return $title; | |
| 149 | - } | |
| 150 | - | |
| 151 | 106 | private function parse_atomic_settings( array $settings ): array { |
| 152 | 107 | $schema = static::get_props_schema(); |
| 153 | 108 | $props_parser = Props_Parser::make( $schema ); |
| 154 | 109 | |
| @@ -346,12 +301,8 @@ | ||
| 346 | 301 | $editor_data = []; |
| 347 | 302 | |
| 348 | 303 | if ( isset( $data['title'] ) && is_string( $data['title'] ) ) { |
| 349 | 304 | $editor_data['title'] = sanitize_text_field( $data['title'] ); |
| 350 | - } | |
| 351 | - | |
| 352 | - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) { | |
| 353 | - $editor_data['grid_outline'] = $data['grid_outline']; | |
| 354 | 305 | } |
| 355 | 306 | |
| 356 | 307 | return $editor_data; |
| 357 | 308 | } |