PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev3
Elementor Website Builder – more than just a page builder v4.0.0-dev3
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 4.0.8 All 454 releases
← All changes | modules/atomic-widgets/elements/base/has-atomic-base.php +28 -183 4.3.0-beta1 → 4.0.0-dev3 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;
@@ -16,9 +13,8 @@
16 13 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
17 14 use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type;
18 15 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
19 16 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
20 -use Elementor\Modules\AtomicWidgets\PropTypes\Prop_Duplication_Behavior;
21 17 use Elementor\Utils;
22 18 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
23 19 use Elementor\Modules\AtomicWidgets\Styles\Atomic_Widget_Styles;
24 20
@@ -30,20 +26,9 @@
30 26 * @mixin Element_Base
31 27 */
32 28 trait Has_Atomic_Base {
33 29 use Has_Base_Styles;
34 - use Has_Base_Settings;
35 30
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 31 public function has_widget_inner_wrapper(): bool {
47 32 return false;
48 33 }
49 34
@@ -100,74 +85,23 @@
100 85
101 86 private function parse_atomic_styles( array $data ): array {
102 87 $styles = $data['styles'] ?? [];
103 88 $style_parser = Style_Parser::make( Style_Schema::get() );
104 - $validated_styles = [];
105 89
106 90 foreach ( $styles as $style_id => $style ) {
107 91 $result = $style_parser->parse( $style );
108 92
109 93 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 - )
117 - );
118 - 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() ) );
119 96 }
120 97
121 - $validated_styles[ $style_id ] = $result->unwrap();
98 + $styles[ $style_id ] = $result->unwrap();
122 99 }
123 100
124 - return $validated_styles;
101 + return $styles;
125 102 }
126 103
127 - private function format_styles_validation_error_message(
128 - string $style_id,
129 - array $data,
130 - array $style,
131 - string $validation_errors
132 - ): string {
133 - $widget_id = $data['id'] ?? 'unknown';
134 - $structure_label = $this->get_editor_structure_label( $data );
135 - $style_label = isset( $style['label'] ) && is_string( $style['label'] ) ? $style['label'] : null;
136 -
137 - $message_parts = [
138 - "Styles validation failed for style `$style_id` (widget `$widget_id`)",
139 - ];
140 -
141 - if ( $structure_label ) {
142 - $message_parts[] = "Structure label: `$structure_label`";
143 - } else {
144 - $element_name = $this->get_title();
145 -
146 - if ( '' === $element_name ) {
147 - $element_name = $this->get_name();
148 - }
149 -
150 - $message_parts[] = "Element: `$element_name`";
151 - }
152 -
153 - if ( $style_label ) {
154 - $message_parts[] = "Style label: `$style_label`";
155 - }
156 -
157 - return implode( '. ', $message_parts ) . '. ' . $validation_errors;
158 - }
159 -
160 - private function get_editor_structure_label( array $data ): ?string {
161 - $title = $data['editor_settings']['title'] ?? $this->editor_settings['title'] ?? null;
162 -
163 - if ( ! is_string( $title ) || '' === $title ) {
164 - return null;
165 - }
166 -
167 - return $title;
168 - }
169 -
170 104 private function parse_atomic_settings( array $settings ): array {
171 105 $schema = static::get_props_schema();
172 106 $props_parser = Props_Parser::make( $schema );
173 107
@@ -247,45 +181,20 @@
247 181 final public function get_data_for_save() {
248 182 $data = parent::get_data_for_save();
249 183
250 184 $data['version'] = $this->version;
185 + $data['settings'] = $this->parse_atomic_settings( $data['settings'] );
186 + $data['styles'] = $this->parse_atomic_styles( $data );
187 + $data['editor_settings'] = $this->parse_editor_settings( $data['editor_settings'] );
251 188
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 -
189 + if ( isset( $data['interactions'] ) && ! empty( $data['interactions'] ) ) {
190 + $data['interactions'] = $this->transform_interactions_for_save( $data['interactions'] );
191 + } else {
192 + $data['interactions'] = [];
193 + }
276 194 return $data;
277 195 }
278 196
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 197 private function transform_interactions_for_save( $interactions ) {
289 198 $decoded = $this->decode_interactions_data( $interactions );
290 199
291 200 if ( empty( $decoded['items'] ) ) {
@@ -331,31 +240,18 @@
331 240
332 241 public function get_atomic_settings(): array {
333 242 $schema = static::get_props_schema();
334 243 $props = $this->get_settings();
244 + $initial_attributes = $this->get_initial_attributes();
335 245
336 - $merged_attribute_values = array_merge(
337 - $this->get_initial_attributes()['value'] ?? [],
246 + $props['attributes'] = Attributes_Prop_Type::generate( array_merge(
247 + $initial_attributes['value'] ?? [],
338 248 $props['attributes']['value'] ?? []
339 - );
340 - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values );
249 + ) );
341 250
342 - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props );
343 -
344 - return $this->transform_link_for_render( $parsed );
251 + return Render_Props_Resolver::for_settings()->resolve( $schema, $props );
345 252 }
346 253
347 - protected function transform_link_for_render( array $parsed ): array {
348 - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : '';
349 -
350 - $parsed['link'] = ! empty( $link_attributes ) ? [
351 - 'tag' => $parsed['link']['tag'],
352 - 'attributes' => $link_attributes,
353 - ] : null;
354 -
355 - return $parsed;
356 - }
357 -
358 254 protected function get_initial_attributes() {
359 255 return Attributes_Prop_Type::generate( [
360 256 Key_Value_Prop_Type::generate( [
361 257 'key' => String_Prop_Type::generate( 'data-e-type' ),
@@ -392,24 +288,15 @@
392 288 if ( isset( $data['title'] ) && is_string( $data['title'] ) ) {
393 289 $editor_data['title'] = sanitize_text_field( $data['title'] );
394 290 }
395 291
396 - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) {
397 - $editor_data['grid_outline'] = $data['grid_outline'];
398 - }
399 -
400 292 return $editor_data;
401 293 }
402 294
403 295 public static function get_props_schema(): array {
404 296 $schema = static::define_props_schema();
297 + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
405 298
406 - if ( ! isset( $schema['_cssid'] ) ) {
407 - $schema['_cssid'] = String_Prop_Type::make()
408 - ->meta( Overridable_Prop_Type::ignore() )
409 - ->meta( Prop_Duplication_Behavior::clear() );
410 - }
411 -
412 299 return apply_filters(
413 300 'elementor/atomic-widgets/props-schema',
414 301 $schema
415 302 );
@@ -465,66 +352,24 @@
465 352 protected function define_render_context(): array {
466 353 return [];
467 354 }
468 355
469 - protected function get_link_attributes( $link_settings ) {
470 - if ( empty( $link_settings['href'] ) ) {
471 - return [];
472 - }
473 -
356 + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) {
474 357 $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG;
475 - $url = $link_settings['href'];
358 + $href = $link_settings['href'];
476 359 $target = $link_settings['target'] ?? '_self';
477 - $is_action_link = 'button' === $tag;
478 - $url_attr_key = $is_action_link ? 'data-action-link' : 'href';
479 360
480 - return [
481 - $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,
482 366 'target' => $target,
483 367 ];
484 - }
485 368
486 - private function get_link_attributes_string( $link_settings ) {
487 - $link_attributes = $this->get_link_attributes( $link_settings );
488 -
489 - if ( empty( $link_attributes ) ) {
490 - return '';
369 + if ( $add_key_to_result ) {
370 + $result['key'] = $href_attribute_key;
491 371 }
492 372
493 - $parts = [];
494 -
495 - foreach ( $link_attributes as $key => $value ) {
496 - if ( 'tag' === $key ) {
497 - continue;
498 - }
499 -
500 - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) );
501 - }
502 -
503 - return implode( ' ', $parts );
504 - }
505 -
506 - public function has_action_link() {
507 - if ( ! $this->get_id() ) {
508 - return true;
509 - }
510 -
511 - $link_settings = $this->get_atomic_setting( 'link' ) ?? null;
512 - $attributes = $this->get_link_attributes( $link_settings );
513 -
514 - return isset( $attributes['data-action-link'] );
515 - }
516 -
517 - public function get_script_depends() {
518 - $depends = parent::get_script_depends();
519 -
520 - if ( $this->has_action_link() ) {
521 - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE;
522 - }
523 -
524 - if ( Atomic_Form::is_instance_form( $this ) ) {
525 - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE;
526 - }
527 -
528 - return $depends;
373 + return $result;
529 374 }
530 375 }