| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Mapper; |
| 4 |
|
| 5 |
use Elementor\Modules\Mcp\Abilities\Appliers\V3\Converter\V3_Context_Meta; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Decides which V3 setting key to write for a given (setting, breakpoint, is_responsive) |
| 13 |
* tuple. Encapsulates the "silent drop when responsive variant is absent" rule so it can |
| 14 |
* be shared between converters. |
| 15 |
*/ |
| 16 |
class Responsive_Key_Resolver { |
| 17 |
|
| 18 |
const BASE_BREAKPOINT = 'desktop'; |
| 19 |
|
| 20 |
/** |
| 21 |
* @return string|null Suffixed key, base key, or null when the write should be dropped. |
| 22 |
*/ |
| 23 |
public function resolve( string $setting, string $breakpoint, bool $is_responsive, V3_Context_Meta $meta ): ?string { |
| 24 |
if ( ! $is_responsive || self::BASE_BREAKPOINT === $breakpoint ) { |
| 25 |
return $setting; |
| 26 |
} |
| 27 |
|
| 28 |
$suffixed = $setting . '_' . $breakpoint; |
| 29 |
if ( ! $meta->has_control( $suffixed ) ) { |
| 30 |
return null; |
| 31 |
} |
| 32 |
|
| 33 |
return $suffixed; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Applies the responsive-suffix rule across an entire patch (typography group case). |
| 38 |
* |
| 39 |
* @param array<string, mixed> $patch |
| 40 |
* @return array<string, mixed> |
| 41 |
*/ |
| 42 |
public function suffix_patch( array $patch, string $breakpoint, V3_Context_Meta $meta ): array { |
| 43 |
$suffixed = []; |
| 44 |
|
| 45 |
foreach ( $patch as $key => $value ) { |
| 46 |
if ( str_ends_with( (string) $key, '_typography' ) ) { |
| 47 |
$suffixed[ $key ] = $value; |
| 48 |
continue; |
| 49 |
} |
| 50 |
|
| 51 |
$candidate = $key . '_' . $breakpoint; |
| 52 |
if ( $meta->has_control( $candidate ) ) { |
| 53 |
$suffixed[ $candidate ] = $value; |
| 54 |
continue; |
| 55 |
} |
| 56 |
|
| 57 |
$suffixed[ $key ] = $value; |
| 58 |
} |
| 59 |
|
| 60 |
return $suffixed; |
| 61 |
} |
| 62 |
} |
| 63 |
|