base.php
3 months ago
border.php
3 months ago
dimensions.php
3 months ago
range.php
3 months ago
typography.php
3 months ago
dimensions.php
53 lines
| 1 | <?php |
| 2 | namespace Crocoblock\Blocks_Style\Field_Handlers; |
| 3 | |
| 4 | class Dimensions extends Base { |
| 5 | |
| 6 | /** |
| 7 | * String with CSS variable macros. |
| 8 | * Should be rewritten in the classes with multiple parameters |
| 9 | * returned by get_parsed_value() method. |
| 10 | */ |
| 11 | public function css_var_value_format() { |
| 12 | return '{{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}}'; |
| 13 | } |
| 14 | |
| 15 | public function get_parsed_value() { |
| 16 | if ( ! $this->raw_value ) { |
| 17 | return [ |
| 18 | 'top' => '', |
| 19 | 'right' => '', |
| 20 | 'bottom' => '', |
| 21 | 'left' => '', |
| 22 | ]; |
| 23 | } |
| 24 | |
| 25 | if ( is_array( $this->raw_value ) ) { |
| 26 | $value = [ |
| 27 | 'top' => isset( $this->raw_value['top'] ) ? $this->raw_value['top'] : '0', |
| 28 | 'right' => isset( $this->raw_value['right'] ) ? $this->raw_value['right'] : '0', |
| 29 | 'bottom' => isset( $this->raw_value['bottom'] ) ? $this->raw_value['bottom'] : '0', |
| 30 | 'left' => isset( $this->raw_value['left'] ) ? $this->raw_value['left'] : '0', |
| 31 | ]; |
| 32 | } else { |
| 33 | $value = [ |
| 34 | 'top' => $this->raw_value, |
| 35 | 'right' => $this->raw_value, |
| 36 | 'bottom' => $this->raw_value, |
| 37 | 'left' => $this->raw_value, |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Check - if values has no other units provided - assume it's pixels |
| 43 | */ |
| 44 | foreach ( $value as $side => $val ) { |
| 45 | if ( ! preg_match( '/\d+[^\d]+/', $val ) ) { |
| 46 | $value[ $side ] = $val . 'px'; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return $value; |
| 51 | } |
| 52 | } |
| 53 |