← All changes
|
modules/atomic-widgets/elements/base/has-atomic-base.php
+15
-40
4.0.9
→
4.0.0-beta1
View file →
| @@ -240,24 +240,16 @@ | ||
| 240 | 240 | |
| 241 | 241 | public function get_atomic_settings(): array { |
| 242 | 242 | $schema = static::get_props_schema(); |
| 243 | 243 | $props = $this->get_settings(); |
| 244 | + $initial_attributes = $this->get_initial_attributes(); | |
| 244 | 245 | |
| 245 | - $merged_attribute_values = array_merge( | |
| 246 | - $this->get_initial_attributes()['value'] ?? [], | |
| 246 | + $props['attributes'] = Attributes_Prop_Type::generate( array_merge( | |
| 247 | + $initial_attributes['value'] ?? [], | |
| 247 | 248 | $props['attributes']['value'] ?? [] |
| 248 | - ); | |
| 249 | - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values ); | |
| 249 | + ) ); | |
| 250 | 250 | |
| 251 | - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props ); | |
| 252 | - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : ''; | |
| 253 | - | |
| 254 | - $parsed['link'] = ! empty( $link_attributes ) ? [ | |
| 255 | - 'tag' => $parsed['link']['tag'], | |
| 256 | - 'attributes' => $link_attributes, | |
| 257 | - ] : null; | |
| 258 | - | |
| 259 | - return $parsed; | |
| 251 | + return Render_Props_Resolver::for_settings()->resolve( $schema, $props ); | |
| 260 | 252 | } |
| 261 | 253 | |
| 262 | 254 | protected function get_initial_attributes() { |
| 263 | 255 | return Attributes_Prop_Type::generate( [ |
| @@ -360,41 +352,24 @@ | ||
| 360 | 352 | protected function define_render_context(): array { |
| 361 | 353 | return []; |
| 362 | 354 | } |
| 363 | 355 | |
| 364 | - protected function get_link_attributes( $link_settings ) { | |
| 365 | - if ( empty( $link_settings['href'] ) ) { | |
| 366 | - return []; | |
| 367 | - } | |
| 368 | - | |
| 356 | + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) { | |
| 369 | 357 | $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG; |
| 370 | - $url = $link_settings['href']; | |
| 358 | + $href = $link_settings['href']; | |
| 371 | 359 | $target = $link_settings['target'] ?? '_self'; |
| 372 | - $is_action_link = 'button' === $tag; | |
| 373 | - $url_attr_key = $is_action_link ? 'data-action-link' : 'href'; | |
| 374 | 360 | |
| 375 | - return [ | |
| 376 | - $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, | |
| 377 | 366 | 'target' => $target, |
| 378 | 367 | ]; |
| 379 | - } | |
| 380 | 368 | |
| 381 | - private function get_link_attributes_string( $link_settings ) { | |
| 382 | - $link_attributes = $this->get_link_attributes( $link_settings ); | |
| 383 | - | |
| 384 | - if ( empty( $link_attributes ) ) { | |
| 385 | - return ''; | |
| 369 | + if ( $add_key_to_result ) { | |
| 370 | + $result['key'] = $href_attribute_key; | |
| 386 | 371 | } |
| 387 | 372 | |
| 388 | - $parts = []; | |
| 389 | - | |
| 390 | - foreach ( $link_attributes as $key => $value ) { | |
| 391 | - if ( 'tag' === $key ) { | |
| 392 | - continue; | |
| 393 | - } | |
| 394 | - | |
| 395 | - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) ); | |
| 396 | - } | |
| 397 | - | |
| 398 | - return implode( ' ', $parts ); | |
| 373 | + return $result; | |
| 399 | 374 | } |
| 400 | 375 | } |