PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-beta1
Elementor Website Builder – more than just a page builder v4.0.0-beta1
4.3.2 4.3.1 4.3.0 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 All 455 releases
← All changes | modules/atomic-widgets/elements/base/has-atomic-base.php +20 -137 4.2.3 → 4.0.0-beta1 View file →
@@ -4,11 +4,8 @@
4 4
5 5 use Elementor\Element_Base;
6 6 use Elementor\Modules\AtomicWidgets\Controls\Base\Atomic_Control_Base;
7 7 use Elementor\Modules\AtomicWidgets\Controls\Section;
8 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Atomic_Form;
9 -use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader;
10 -use Elementor\Modules\AtomicWidgets\Logger\Logger;
11 8 use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
12 9 use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
13 10 use Elementor\Modules\AtomicWidgets\Styles\Style_Schema;
14 11 use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser;
@@ -29,9 +26,8 @@
29 26 * @mixin Element_Base
30 27 */
31 28 trait Has_Atomic_Base {
32 29 use Has_Base_Styles;
33 - use Has_Base_Settings;
34 30
35 31 public function has_widget_inner_wrapper(): bool {
36 32 return false;
37 33 }
@@ -89,74 +85,23 @@
89 85
90 86 private function parse_atomic_styles( array $data ): array {
91 87 $styles = $data['styles'] ?? [];
92 88 $style_parser = Style_Parser::make( Style_Schema::get() );
93 - $validated_styles = [];
94 89
95 90 foreach ( $styles as $style_id => $style ) {
96 91 $result = $style_parser->parse( $style );
97 92
98 93 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;
94 + $widget_id = $data['id'] ?? 'unknown';
95 + throw new \Exception( esc_html( "Styles validation failed for style `$style_id`. Widget ID: `$widget_id`. " . $result->errors()->to_string() ) );
108 96 }
109 97
110 - $validated_styles[ $style_id ] = $result->unwrap();
98 + $styles[ $style_id ] = $result->unwrap();
111 99 }
112 100
113 - return $validated_styles;
101 + return $styles;
114 102 }
115 103
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 104 private function parse_atomic_settings( array $settings ): array {
160 105 $schema = static::get_props_schema();
161 106 $props_parser = Props_Parser::make( $schema );
162 107
@@ -295,31 +240,18 @@
295 240
296 241 public function get_atomic_settings(): array {
297 242 $schema = static::get_props_schema();
298 243 $props = $this->get_settings();
244 + $initial_attributes = $this->get_initial_attributes();
299 245
300 - $merged_attribute_values = array_merge(
301 - $this->get_initial_attributes()['value'] ?? [],
246 + $props['attributes'] = Attributes_Prop_Type::generate( array_merge(
247 + $initial_attributes['value'] ?? [],
302 248 $props['attributes']['value'] ?? []
303 - );
304 - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values );
249 + ) );
305 250
306 - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props );
307 -
308 - return $this->transform_link_for_render( $parsed );
251 + return Render_Props_Resolver::for_settings()->resolve( $schema, $props );
309 252 }
310 253
311 - protected function transform_link_for_render( array $parsed ): array {
312 - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : '';
313 -
314 - $parsed['link'] = ! empty( $link_attributes ) ? [
315 - 'tag' => $parsed['link']['tag'],
316 - 'attributes' => $link_attributes,
317 - ] : null;
318 -
319 - return $parsed;
320 - }
321 -
322 254 protected function get_initial_attributes() {
323 255 return Attributes_Prop_Type::generate( [
324 256 Key_Value_Prop_Type::generate( [
325 257 'key' => String_Prop_Type::generate( 'data-e-type' ),
@@ -356,22 +288,15 @@
356 288 if ( isset( $data['title'] ) && is_string( $data['title'] ) ) {
357 289 $editor_data['title'] = sanitize_text_field( $data['title'] );
358 290 }
359 291
360 - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) {
361 - $editor_data['grid_outline'] = $data['grid_outline'];
362 - }
363 -
364 292 return $editor_data;
365 293 }
366 294
367 295 public static function get_props_schema(): array {
368 296 $schema = static::define_props_schema();
297 + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
369 298
370 - if ( ! isset( $schema['_cssid'] ) ) {
371 - $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
372 - }
373 -
374 299 return apply_filters(
375 300 'elementor/atomic-widgets/props-schema',
376 301 $schema
377 302 );
@@ -427,66 +352,24 @@
427 352 protected function define_render_context(): array {
428 353 return [];
429 354 }
430 355
431 - protected function get_link_attributes( $link_settings ) {
432 - if ( empty( $link_settings['href'] ) ) {
433 - return [];
434 - }
435 -
356 + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) {
436 357 $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG;
437 - $url = $link_settings['href'];
358 + $href = $link_settings['href'];
438 359 $target = $link_settings['target'] ?? '_self';
439 - $is_action_link = 'button' === $tag;
440 - $url_attr_key = $is_action_link ? 'data-action-link' : 'href';
441 360
442 - return [
443 - $url_attr_key => $url,
361 + $is_button = 'button' === $tag;
362 + $href_attribute_key = $is_button ? 'data-action-link' : 'href';
363 +
364 + $result = [
365 + $href_attribute_key => $href,
444 366 'target' => $target,
445 367 ];
446 - }
447 368
448 - private function get_link_attributes_string( $link_settings ) {
449 - $link_attributes = $this->get_link_attributes( $link_settings );
450 -
451 - if ( empty( $link_attributes ) ) {
452 - return '';
369 + if ( $add_key_to_result ) {
370 + $result['key'] = $href_attribute_key;
453 371 }
454 372
455 - $parts = [];
456 -
457 - foreach ( $link_attributes as $key => $value ) {
458 - if ( 'tag' === $key ) {
459 - continue;
460 - }
461 -
462 - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) );
463 - }
464 -
465 - return implode( ' ', $parts );
466 - }
467 -
468 - public function has_action_link() {
469 - if ( ! $this->get_id() ) {
470 - return true;
471 - }
472 -
473 - $link_settings = $this->get_atomic_setting( 'link' ) ?? null;
474 - $attributes = $this->get_link_attributes( $link_settings );
475 -
476 - return isset( $attributes['data-action-link'] );
477 - }
478 -
479 - public function get_script_depends() {
480 - $depends = parent::get_script_depends();
481 -
482 - if ( $this->has_action_link() ) {
483 - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE;
484 - }
485 -
486 - if ( Atomic_Form::is_instance_form( $this ) ) {
487 - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE;
488 - }
489 -
490 - return $depends;
373 + return $result;
491 374 }
492 375 }