PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0
Elementor Website Builder – more than just a page builder v4.3.0
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / modules / mcp / abilities / appliers / v3 / mapper / responsive-key-resolver.php

responsive-key-resolver.php in Elementor Website Builder – more than just a page builder 4.3.0, at modules/mcp/abilities/appliers/v3/mapper/responsive-key-resolver.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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