← All changes
|
classes/views/styles/components/FrmSliderStyleComponent.php
+24
-20
6.25.1
→
trunk
View file →
| @@ -21,10 +21,14 @@ | ||
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | 23 | protected $data; |
| 24 | 24 | |
| 25 | + /** | |
| 26 | + * @param string $field_name | |
| 27 | + * @param mixed $field_value | |
| 28 | + * @param array $data | |
| 29 | + */ | |
| 25 | 30 | public function __construct( $field_name, $field_value, $data ) { |
| 26 | - | |
| 27 | 31 | $this->init_field_data( $data, $field_name, $field_value ); |
| 28 | 32 | |
| 29 | 33 | if ( true === $this->hide_component() ) { |
| 30 | 34 | return; |
| @@ -32,9 +36,9 @@ | ||
| 32 | 36 | |
| 33 | 37 | $this->data['unit_measurement'] = $this->detect_unit_measurement(); |
| 34 | 38 | $this->data['has-multiple-values'] = count( $this->get_values() ) > 1; |
| 35 | 39 | $this->data['units'] = $this->get_units_list( $data ); |
| 36 | - $this->data['value_label'] = empty( $this->detect_unit_measurement() ) ? $field_value : (float) $field_value; | |
| 40 | + $this->data['value_label'] = $this->detect_unit_measurement() ? (float) $field_value : $field_value; | |
| 37 | 41 | |
| 38 | 42 | $this->init_defaults(); |
| 39 | 43 | $this->init_icon(); |
| 40 | 44 | $this->init_multiple_values(); |
| @@ -49,8 +53,9 @@ | ||
| 49 | 53 | * If the units array is empty in the provided data, it returns an array containing the default units: 'px', 'em', and '%'. |
| 50 | 54 | * Otherwise, it merges the units array from the provided data with the default units array and returns the result. |
| 51 | 55 | * |
| 52 | 56 | * @param array $data The data containing the units array. |
| 57 | + * | |
| 53 | 58 | * @return array The list of units for the slider style component. |
| 54 | 59 | */ |
| 55 | 60 | private function get_units_list( $data ) { |
| 56 | 61 | if ( empty( $data['units'] ) ) { |
| @@ -67,9 +72,9 @@ | ||
| 67 | 72 | * |
| 68 | 73 | * @return void |
| 69 | 74 | */ |
| 70 | 75 | private function init_defaults() { |
| 71 | - $this->data['max_value'] = empty( $this->data['max_value'] ) ? 100 : $this->data['max_value']; | |
| 76 | + $this->data['max_value'] = ! empty( $this->data['max_value'] ) ? $this->data['max_value'] : 100; | |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | /** |
| 75 | 80 | * Init the slider multiple values data. It works with sliders which has multiple values only: top&bottom and left&right. |
| @@ -76,9 +81,9 @@ | ||
| 76 | 81 | * This is used for cases when there are 4 sliders in the same field. |
| 77 | 82 | * |
| 78 | 83 | * @since 6.14 |
| 79 | 84 | * |
| 80 | - * @return array | |
| 85 | + * @return void | |
| 81 | 86 | */ |
| 82 | 87 | private function init_multiple_values() { |
| 83 | 88 | if ( ! $this->data['has-multiple-values'] ) { |
| 84 | 89 | return; |
| @@ -85,40 +90,40 @@ | ||
| 85 | 90 | } |
| 86 | 91 | |
| 87 | 92 | $values = $this->get_values(); |
| 88 | 93 | $top = $values[0]; |
| 89 | - $bottom = empty( $values[2] ) ? $values[0] : $values[2]; | |
| 90 | - $left = empty( $values[3] ) ? $values[1] : $values[3]; | |
| 94 | + $bottom = ! empty( $values[2] ) ? $values[2] : $values[0]; | |
| 95 | + $left = ! empty( $values[3] ) ? $values[3] : $values[1]; | |
| 91 | 96 | $right = $values[1]; |
| 92 | 97 | |
| 93 | 98 | $this->data['vertical'] = array( |
| 94 | 99 | 'unit' => $this->detect_unit_measurement( $top ), |
| 95 | - 'value' => empty( $this->detect_unit_measurement( $top ) ) ? $top : (float) $top, | |
| 100 | + 'value' => $this->detect_unit_measurement( $top ) ? (float) $top : $top, | |
| 96 | 101 | ); |
| 97 | 102 | |
| 98 | 103 | $this->data['horizontal'] = array( |
| 99 | 104 | 'unit' => $this->detect_unit_measurement( $right ), |
| 100 | - 'value' => empty( $this->detect_unit_measurement( $right ) ) ? $right : (float) $right, | |
| 105 | + 'value' => $this->detect_unit_measurement( $right ) ? (float) $right : $right, | |
| 101 | 106 | ); |
| 102 | 107 | |
| 103 | 108 | $this->data['top'] = array( |
| 104 | 109 | 'unit' => $this->detect_unit_measurement( $top ), |
| 105 | - 'value' => empty( $this->detect_unit_measurement( $top ) ) ? $top : (float) $top, | |
| 110 | + 'value' => $this->detect_unit_measurement( $top ) ? (float) $top : $top, | |
| 106 | 111 | ); |
| 107 | 112 | |
| 108 | 113 | $this->data['bottom'] = array( |
| 109 | 114 | 'unit' => $this->detect_unit_measurement( $bottom ), |
| 110 | - 'value' => empty( $this->detect_unit_measurement( $bottom ) ) ? $bottom : (float) $bottom, | |
| 115 | + 'value' => $this->detect_unit_measurement( $bottom ) ? (float) $bottom : $bottom, | |
| 111 | 116 | ); |
| 112 | 117 | |
| 113 | 118 | $this->data['left'] = array( |
| 114 | 119 | 'unit' => $this->detect_unit_measurement( $left ), |
| 115 | - 'value' => empty( $this->detect_unit_measurement( $left ) ) ? $left : (float) $left, | |
| 120 | + 'value' => $this->detect_unit_measurement( $left ) ? (float) $left : $left, | |
| 116 | 121 | ); |
| 117 | 122 | |
| 118 | 123 | $this->data['right'] = array( |
| 119 | 124 | 'unit' => $this->detect_unit_measurement( $right ), |
| 120 | - 'value' => empty( $this->detect_unit_measurement( $right ) ) ? $right : (float) $right, | |
| 125 | + 'value' => $this->detect_unit_measurement( $right ) ? (float) $right : $right, | |
| 121 | 126 | ); |
| 122 | 127 | } |
| 123 | 128 | |
| 124 | 129 | /** |
| @@ -138,8 +143,10 @@ | ||
| 138 | 143 | * Possible values are: "px", "%", "em" or empty "" |
| 139 | 144 | * |
| 140 | 145 | * @since 6.14 |
| 141 | 146 | * |
| 147 | + * @param string|null $value | |
| 148 | + * | |
| 142 | 149 | * @return string |
| 143 | 150 | */ |
| 144 | 151 | private function detect_unit_measurement( $value = null ) { |
| 145 | 152 | if ( null === $value ) { |
| @@ -148,16 +155,14 @@ | ||
| 148 | 155 | |
| 149 | 156 | if ( preg_match( '/%$/', $value ) ) { |
| 150 | 157 | return '%'; |
| 151 | 158 | } |
| 159 | + | |
| 152 | 160 | if ( preg_match( '/em$/', $value ) ) { |
| 153 | 161 | return 'em'; |
| 154 | 162 | } |
| 155 | - if ( preg_match( '/px$/', $value ) ) { | |
| 156 | - return 'px'; | |
| 157 | - } | |
| 158 | 163 | |
| 159 | - return ''; | |
| 164 | + return preg_match( '/px$/', $value ) ? 'px' : ''; | |
| 160 | 165 | } |
| 161 | 166 | |
| 162 | 167 | /** |
| 163 | 168 | * Init the field icon |
| @@ -163,12 +168,11 @@ | ||
| 163 | 168 | * Init the field icon |
| 164 | 169 | * |
| 165 | 170 | * @since 6.14 |
| 166 | 171 | * |
| 167 | - * @return array | |
| 172 | + * @return void | |
| 168 | 173 | */ |
| 169 | 174 | private function init_icon() { |
| 170 | - | |
| 171 | 175 | if ( ! empty( $this->data['icon'] ) ) { |
| 172 | 176 | return; |
| 173 | 177 | } |
| 174 | 178 | |
| @@ -178,13 +182,13 @@ | ||
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | switch ( $this->data['type'] ) { |
| 181 | 185 | case 'vertical-margin': |
| 182 | - $this->data['icon'] = 'frm_icon_font frm-margin-top-bottom'; | |
| 186 | + $this->data['icon'] = 'frmfont frm-margin-top-bottom'; | |
| 183 | 187 | return; |
| 184 | 188 | |
| 185 | 189 | case 'horizontal-margin': |
| 186 | - $this->data['icon'] = 'frm_icon_font frm-margin-left-right'; | |
| 190 | + $this->data['icon'] = 'frmfont frm-margin-left-right'; | |
| 187 | 191 | return; |
| 188 | 192 | |
| 189 | 193 | default: |
| 190 | 194 | $this->data['icon'] = ''; |