| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\GlobalClasses\Utils; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Global_Class_Data_Normalizer { |
| 10 |
public static function normalize_styles( array $raw_items ): array { |
| 11 |
$normalized = []; |
| 12 |
|
| 13 |
foreach ( $raw_items as $class_id => $class_data ) { |
| 14 |
$normalized[ $class_id ] = self::normalize_style( $class_id, $class_data ); |
| 15 |
} |
| 16 |
|
| 17 |
return $normalized; |
| 18 |
} |
| 19 |
|
| 20 |
public static function normalize_style( string $class_id, array $class_data ): array { |
| 21 |
return array_merge( |
| 22 |
[ |
| 23 |
'id' => $class_id, |
| 24 |
'label' => $class_data['label'] ?? $class_id, |
| 25 |
], |
| 26 |
self::normalize_style_fields( $class_data ) |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
public static function normalize_style_fields( array $item ): array { |
| 31 |
$data = [ |
| 32 |
'type' => $item['type'] ?? 'class', |
| 33 |
'variants' => $item['variants'] ?? [], |
| 34 |
]; |
| 35 |
|
| 36 |
if ( array_key_exists( 'sync_to_v3', $item ) ) { |
| 37 |
$data['sync_to_v3'] = (bool) $item['sync_to_v3']; |
| 38 |
} |
| 39 |
|
| 40 |
return $data; |
| 41 |
} |
| 42 |
} |
| 43 |
|