| @@ -60,12 +60,11 @@ | ||
| 60 | 60 | * |
| 61 | 61 | * @return array |
| 62 | 62 | */ |
| 63 | 63 | protected function get_processed_sub_fields() { |
| 64 | - $name_layout = $this->get_name_layout(); | |
| 65 | - $names = explode( '_', $name_layout ); | |
| 66 | - $col_class = 'frm' . intval( 12 / count( $names ) ); | |
| 67 | - $result = array(); | |
| 64 | + $names = explode( '_', $this->get_name_layout() ); | |
| 65 | + $col_class = 'frm' . intval( 12 / count( $names ) ); | |
| 66 | + $result = array(); | |
| 68 | 67 | |
| 69 | 68 | foreach ( $names as $name ) { |
| 70 | 69 | if ( empty( $this->sub_fields[ $name ] ) ) { |
| 71 | 70 | continue; |
| @@ -91,14 +90,9 @@ | ||
| 91 | 90 | * @return string |
| 92 | 91 | */ |
| 93 | 92 | protected function get_name_layout() { |
| 94 | 93 | $name_layout = FrmField::get_option( $this->field, 'name_layout' ); |
| 95 | - | |
| 96 | - if ( ! $name_layout ) { | |
| 97 | - $name_layout = 'first_last'; | |
| 98 | - } | |
| 99 | - | |
| 100 | - return $name_layout; | |
| 94 | + return $name_layout ? $name_layout : 'first_last'; | |
| 101 | 95 | } |
| 102 | 96 | |
| 103 | 97 | /** |
| 104 | 98 | * Gets extra field options. |
| @@ -147,10 +141,8 @@ | ||
| 147 | 141 | if ( ! is_array( $value ) ) { |
| 148 | 142 | return $value; |
| 149 | 143 | } |
| 150 | 144 | |
| 151 | - $name_layout = $this->get_name_layout(); | |
| 152 | - | |
| 153 | 145 | if ( ! empty( $atts['show'] ) ) { |
| 154 | 146 | return $value[ $atts['show'] ] ?? ''; |
| 155 | 147 | } |
| 156 | 148 | |
| @@ -162,9 +154,9 @@ | ||
| 162 | 154 | 'last' => '', |
| 163 | 155 | ) |
| 164 | 156 | ); |
| 165 | 157 | |
| 166 | - switch ( $name_layout ) { | |
| 158 | + switch ( $this->get_name_layout() ) { | |
| 167 | 159 | case 'last_first': |
| 168 | 160 | $value = $value['last'] . ' ' . $value['first']; |
| 169 | 161 | break; |
| 170 | 162 | |
| @@ -225,15 +217,17 @@ | ||
| 225 | 217 | protected function process_args_for_field_output( &$args ) { |
| 226 | 218 | parent::process_args_for_field_output( $args ); |
| 227 | 219 | |
| 228 | 220 | // Show all subfields in form builder then use JS to show or hide them. |
| 229 | - if ( $this->should_print_hidden_sub_fields() && count( $args['sub_fields'] ) !== count( $this->sub_fields ) ) { | |
| 230 | - $hidden_fields = array_diff_key( $this->sub_fields, $args['sub_fields'] ); | |
| 231 | - $args['sub_fields'] = $this->sub_fields; | |
| 221 | + if ( ! $this->should_print_hidden_sub_fields() || count( $args['sub_fields'] ) === count( $this->sub_fields ) ) { | |
| 222 | + return; | |
| 223 | + } | |
| 232 | 224 | |
| 233 | - foreach ( $hidden_fields as $name => $hidden_field ) { | |
| 234 | - $args['sub_fields'][ $name ]['wrapper_classes'] .= ' frm_hidden'; | |
| 235 | - } | |
| 225 | + $hidden_fields = array_diff_key( $this->sub_fields, $args['sub_fields'] ); | |
| 226 | + $args['sub_fields'] = $this->sub_fields; | |
| 227 | + | |
| 228 | + foreach ( $hidden_fields as $name => $hidden_field ) { | |
| 229 | + $args['sub_fields'][ $name ]['wrapper_classes'] .= ' frm_hidden'; | |
| 236 | 230 | } |
| 237 | 231 | } |
| 238 | 232 | |
| 239 | 233 | /** |
| @@ -250,9 +244,9 @@ | ||
| 250 | 244 | * Gets inputs container attributes. |
| 251 | 245 | * |
| 252 | 246 | * @return array |
| 253 | 247 | */ |
| 254 | - protected function get_inputs_container_attrs() { | |
| 248 | + public function get_inputs_container_attrs() { | |
| 255 | 249 | $attrs = parent::get_inputs_container_attrs(); |
| 256 | 250 | |
| 257 | 251 | $attrs['data-name-layout'] = $this->get_name_layout(); |
| 258 | 252 | return $attrs; |
| @@ -292,8 +286,9 @@ | ||
| 292 | 286 | |
| 293 | 287 | if ( ! $show_warning ) { |
| 294 | 288 | return; |
| 295 | 289 | } |
| 290 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 296 | 291 | ?> |
| 297 | 292 | <div class="frm_warning_style"> |
| 298 | 293 | <?php |
| 299 | 294 | FrmAppHelper::icon_by_class( 'frmfont frm_alert_icon', array( 'style' => 'width:24px' ) ); |
| @@ -301,8 +296,9 @@ | ||
| 301 | 296 | esc_html_e( 'Subfield descriptions are read by screen readers. Enhance accessibility by using complete labels, like "First Name" instead of "First".', 'formidable' ); |
| 302 | 297 | ?> |
| 303 | 298 | </div> |
| 304 | 299 | <?php |
| 300 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 305 | 301 | } |
| 306 | 302 | |
| 307 | 303 | /** |
| 308 | 304 | * Tracks the first name field ID in a form. |