| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Utils; |
| 4 |
|
| 5 |
use Elementor\Modules\GlobalClasses\Utils\Atomic_Elements_Utils; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class Element_Structure_Title { |
| 12 |
|
| 13 |
public static function resolve( array $element ): ?string { |
| 14 |
$editor_title = $element['editor_settings']['title'] ?? null; |
| 15 |
|
| 16 |
if ( is_string( $editor_title ) && '' !== $editor_title ) { |
| 17 |
return $editor_title; |
| 18 |
} |
| 19 |
|
| 20 |
$settings = $element['settings'] ?? []; |
| 21 |
|
| 22 |
if ( is_array( $settings ) ) { |
| 23 |
foreach ( [ '_title', 'presetTitle' ] as $key ) { |
| 24 |
$plain = self::extract_plain_string( $settings[ $key ] ?? null ); |
| 25 |
|
| 26 |
if ( null !== $plain ) { |
| 27 |
return $plain; |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
$type = $element['widgetType'] ?? $element['elType'] ?? null; |
| 33 |
|
| 34 |
if ( ! $type ) { |
| 35 |
return null; |
| 36 |
} |
| 37 |
|
| 38 |
$instance = Atomic_Elements_Utils::get_element_instance( (string) $type ); |
| 39 |
|
| 40 |
if ( ! $instance ) { |
| 41 |
return null; |
| 42 |
} |
| 43 |
|
| 44 |
$label = $instance->get_title(); |
| 45 |
|
| 46 |
if ( ! is_string( $label ) || '' === $label ) { |
| 47 |
return null; |
| 48 |
} |
| 49 |
|
| 50 |
return $label; |
| 51 |
} |
| 52 |
|
| 53 |
private static function extract_plain_string( $value ): ?string { |
| 54 |
if ( is_string( $value ) && '' !== $value ) { |
| 55 |
return $value; |
| 56 |
} |
| 57 |
|
| 58 |
if ( |
| 59 |
is_array( $value ) |
| 60 |
&& isset( $value['value'] ) |
| 61 |
&& is_string( $value['value'] ) |
| 62 |
&& '' !== $value['value'] |
| 63 |
) { |
| 64 |
return $value['value']; |
| 65 |
} |
| 66 |
|
| 67 |
return null; |
| 68 |
} |
| 69 |
} |
| 70 |
|