PlayerAttrs.php
37 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Maps Divi D5 module attributes for the Presto Player video module. |
| 4 | * |
| 5 | * @package presto-player |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer\Integrations\Divi\D5; |
| 9 | |
| 10 | /** |
| 11 | * Maps raw D5 module attribute arrays to player options. |
| 12 | */ |
| 13 | class PlayerAttrs { |
| 14 | |
| 15 | /** |
| 16 | * Converts raw D5 attrs into a normalized player options array. |
| 17 | * |
| 18 | * @param array<string, mixed> $attrs Raw D5 module attribute array. |
| 19 | * @return array<string, mixed> |
| 20 | */ |
| 21 | public static function map( array $attrs ): array { |
| 22 | // Desktop breakpoint only; responsive per-device video/override values aren't supported. |
| 23 | $video_id = (int) ( $attrs['videoId']['innerContent']['desktop']['value'] ?? 0 ); |
| 24 | $url_override = (string) ( $attrs['urlOverride']['innerContent']['desktop']['value'] ?? '' ); |
| 25 | |
| 26 | $overrides = array(); |
| 27 | if ( '' !== $url_override ) { |
| 28 | $overrides['src'] = esc_url_raw( $url_override ); |
| 29 | } |
| 30 | |
| 31 | return array( |
| 32 | 'video_id' => $video_id, |
| 33 | 'overrides' => $overrides, |
| 34 | ); |
| 35 | } |
| 36 | } |
| 37 |