| 1 |
<?php |
| 2 |
namespace ABlocks\Classes; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Helper; |
| 9 |
|
| 10 |
abstract class ControlBaseAbstractTwo { |
| 11 |
abstract public static function get_attribute_default_value( $args ); |
| 12 |
abstract public static function get_attribute( $args ); |
| 13 |
abstract public static function get_css( $args ); |
| 14 |
|
| 15 |
public static function get_unit( $args ) { |
| 16 |
$defaultUnit = $args['unitDefaultValue']; |
| 17 |
$value = $args['attributeValue']; |
| 18 |
$device = $args['device']; |
| 19 |
$keyPrefix = $args['attributeObjectKey'] . 'Unit'; |
| 20 |
|
| 21 |
// Retrieve units with fallback to default |
| 22 |
$unitDesktop = Helper::get_array_value( $value, $keyPrefix, $defaultUnit ); // Desktop |
| 23 |
$unitTablet = Helper::get_array_value( $value, $keyPrefix . 'Tablet', $unitDesktop ); // Tablet inherits from Desktop |
| 24 |
$unitMobile = Helper::get_array_value( $value, $keyPrefix . 'Mobile', $unitTablet ); // Mobile inherits from Tablet |
| 25 |
|
| 26 |
// Return the appropriate unit based on the device |
| 27 |
if ( '' === $device ) { |
| 28 |
return $unitDesktop; // Desktop |
| 29 |
} |
| 30 |
|
| 31 |
if ( 'Tablet' === $device ) { |
| 32 |
return $unitTablet; // Tablet |
| 33 |
} |
| 34 |
|
| 35 |
if ( 'Mobile' === $device ) { |
| 36 |
return $unitMobile; // Mobile |
| 37 |
} |
| 38 |
|
| 39 |
return $defaultUnit; // Default fallback |
| 40 |
} |
| 41 |
} |
| 42 |
|