← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+16
-76
4.1.0-beta3
→
4.0.0-dev3
View file →
| @@ -4,10 +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 | 8 | use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver; |
| 11 | 9 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 12 | 10 | use Elementor\Modules\AtomicWidgets\Styles\Style_Schema; |
| 13 | 11 | use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser; |
| @@ -242,31 +240,18 @@ | ||
| 242 | 240 | |
| 243 | 241 | public function get_atomic_settings(): array { |
| 244 | 242 | $schema = static::get_props_schema(); |
| 245 | 243 | $props = $this->get_settings(); |
| 244 | + $initial_attributes = $this->get_initial_attributes(); | |
| 246 | 245 | |
| 247 | - $merged_attribute_values = array_merge( | |
| 248 | - $this->get_initial_attributes()['value'] ?? [], | |
| 246 | + $props['attributes'] = Attributes_Prop_Type::generate( array_merge( | |
| 247 | + $initial_attributes['value'] ?? [], | |
| 249 | 248 | $props['attributes']['value'] ?? [] |
| 250 | - ); | |
| 251 | - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values ); | |
| 249 | + ) ); | |
| 252 | 250 | |
| 253 | - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props ); | |
| 254 | - | |
| 255 | - return $this->transform_link_for_render( $parsed ); | |
| 251 | + return Render_Props_Resolver::for_settings()->resolve( $schema, $props ); | |
| 256 | 252 | } |
| 257 | 253 | |
| 258 | - protected function transform_link_for_render( array $parsed ): array { | |
| 259 | - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : ''; | |
| 260 | - | |
| 261 | - $parsed['link'] = ! empty( $link_attributes ) ? [ | |
| 262 | - 'tag' => $parsed['link']['tag'], | |
| 263 | - 'attributes' => $link_attributes, | |
| 264 | - ] : null; | |
| 265 | - | |
| 266 | - return $parsed; | |
| 267 | - } | |
| 268 | - | |
| 269 | 254 | protected function get_initial_attributes() { |
| 270 | 255 | return Attributes_Prop_Type::generate( [ |
| 271 | 256 | Key_Value_Prop_Type::generate( [ |
| 272 | 257 | 'key' => String_Prop_Type::generate( 'data-e-type' ), |
| @@ -308,13 +293,10 @@ | ||
| 308 | 293 | } |
| 309 | 294 | |
| 310 | 295 | public static function get_props_schema(): array { |
| 311 | 296 | $schema = static::define_props_schema(); |
| 297 | + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ); | |
| 312 | 298 | |
| 313 | - if ( ! isset( $schema['_cssid'] ) ) { | |
| 314 | - $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ); | |
| 315 | - } | |
| 316 | - | |
| 317 | 299 | return apply_filters( |
| 318 | 300 | 'elementor/atomic-widgets/props-schema', |
| 319 | 301 | $schema |
| 320 | 302 | ); |
| @@ -370,66 +352,24 @@ | ||
| 370 | 352 | protected function define_render_context(): array { |
| 371 | 353 | return []; |
| 372 | 354 | } |
| 373 | 355 | |
| 374 | - protected function get_link_attributes( $link_settings ) { | |
| 375 | - if ( empty( $link_settings['href'] ) ) { | |
| 376 | - return []; | |
| 377 | - } | |
| 378 | - | |
| 356 | + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) { | |
| 379 | 357 | $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG; |
| 380 | - $url = $link_settings['href']; | |
| 358 | + $href = $link_settings['href']; | |
| 381 | 359 | $target = $link_settings['target'] ?? '_self'; |
| 382 | - $is_action_link = 'button' === $tag; | |
| 383 | - $url_attr_key = $is_action_link ? 'data-action-link' : 'href'; | |
| 384 | 360 | |
| 385 | - return [ | |
| 386 | - $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, | |
| 387 | 366 | 'target' => $target, |
| 388 | 367 | ]; |
| 389 | - } | |
| 390 | 368 | |
| 391 | - private function get_link_attributes_string( $link_settings ) { | |
| 392 | - $link_attributes = $this->get_link_attributes( $link_settings ); | |
| 393 | - | |
| 394 | - if ( empty( $link_attributes ) ) { | |
| 395 | - return ''; | |
| 369 | + if ( $add_key_to_result ) { | |
| 370 | + $result['key'] = $href_attribute_key; | |
| 396 | 371 | } |
| 397 | 372 | |
| 398 | - $parts = []; | |
| 399 | - | |
| 400 | - foreach ( $link_attributes as $key => $value ) { | |
| 401 | - if ( 'tag' === $key ) { | |
| 402 | - continue; | |
| 403 | - } | |
| 404 | - | |
| 405 | - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) ); | |
| 406 | - } | |
| 407 | - | |
| 408 | - return implode( ' ', $parts ); | |
| 409 | - } | |
| 410 | - | |
| 411 | - public function has_action_link() { | |
| 412 | - if ( ! $this->get_id() ) { | |
| 413 | - return true; | |
| 414 | - } | |
| 415 | - | |
| 416 | - $link_settings = $this->get_atomic_setting( 'link' ) ?? null; | |
| 417 | - $attributes = $this->get_link_attributes( $link_settings ); | |
| 418 | - | |
| 419 | - return isset( $attributes['data-action-link'] ); | |
| 420 | - } | |
| 421 | - | |
| 422 | - public function get_script_depends() { | |
| 423 | - $depends = parent::get_script_depends(); | |
| 424 | - | |
| 425 | - if ( $this->has_action_link() ) { | |
| 426 | - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE; | |
| 427 | - } | |
| 428 | - | |
| 429 | - if ( Atomic_Form::is_instance_form( $this ) ) { | |
| 430 | - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE; | |
| 431 | - } | |
| 432 | - | |
| 433 | - return $depends; | |
| 373 | + return $result; | |
| 434 | 374 | } |
| 435 | 375 | } |