← All changes
|
classes/views/frm-fields/front-end/dropdown-field.php
+35
-12
6.25
→
trunk
View file →
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package Formidable |
| 4 | 4 | * |
| 5 | - * @var array $field | |
| 5 | + * @var array $field | |
| 6 | + * @var array|null $args | |
| 6 | 7 | */ |
| 7 | 8 | |
| 8 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 10 | die( 'You are not allowed to call this page directly.' ); |
| @@ -9,27 +10,30 @@ | ||
| 9 | 10 | die( 'You are not allowed to call this page directly.' ); |
| 10 | 11 | } |
| 11 | 12 | |
| 12 | 13 | if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' && FrmAppHelper::pro_is_installed() ) { |
| 13 | - echo FrmProPost::get_category_dropdown( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 14 | - $field, | |
| 15 | - array( | |
| 16 | - 'location' => 'front', | |
| 17 | - 'name' => $field_name, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 18 | - 'id' => $html_id, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 19 | - ) | |
| 14 | + $category_dropdown_args = array( | |
| 15 | + 'location' => 'front', | |
| 16 | + 'name' => $field_name, | |
| 17 | + 'id' => $html_id, | |
| 20 | 18 | ); |
| 19 | + echo FrmProPost::get_category_dropdown( $field, $category_dropdown_args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 21 | 20 | } else { |
| 21 | + if ( FrmFieldsHelper::should_skip_rendering_choices_for_field( $field ) ) { | |
| 22 | + return; | |
| 23 | + } | |
| 24 | + | |
| 22 | 25 | if ( $read_only ) { |
| 23 | 26 | ?> |
| 24 | 27 | <select <?php do_action( 'frm_field_input_html', $field ); ?>> |
| 25 | - <?php } else { ?> | |
| 28 | + <?php | |
| 29 | + } else { | |
| 30 | + ?> | |
| 26 | 31 | <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id ); ?>" <?php do_action( 'frm_field_input_html', $field ); ?>> |
| 27 | 32 | <?php |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | - $placeholder = FrmFieldsController::add_placeholder_to_select( $field ); | |
| 31 | - | |
| 35 | + $placeholder = FrmFieldsController::add_placeholder_to_select( $field ); | |
| 32 | 36 | $skipped = false; |
| 33 | 37 | $other_opt = false; |
| 34 | 38 | $other_checked = false; |
| 35 | 39 | |
| @@ -46,18 +50,25 @@ | ||
| 46 | 50 | do_action( 'frm_dropdown_field_after_no_placeholder_option', $field ); |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | 53 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 54 | + if ( FrmFieldsHelper::should_hide_field_choice( $opt_key, $field ) ) { | |
| 55 | + continue; | |
| 56 | + } | |
| 57 | + | |
| 50 | 58 | $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field ); |
| 51 | 59 | $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field ); |
| 52 | 60 | $selected = FrmAppHelper::check_selected( $field['value'], $field_val ); |
| 61 | + | |
| 53 | 62 | if ( $other_opt === false ) { |
| 54 | 63 | $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $selected ); |
| 64 | + | |
| 55 | 65 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) && $selected ) { |
| 56 | 66 | $other_checked = true; |
| 57 | 67 | } |
| 58 | 68 | } |
| 59 | 69 | |
| 70 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 60 | 71 | if ( $placeholder && $opt == '' && ! $skipped ) { |
| 61 | 72 | $skipped = true; |
| 62 | 73 | continue; |
| 63 | 74 | } |
| @@ -69,9 +80,21 @@ | ||
| 69 | 80 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 70 | 81 | $option_params['class'] = 'frm_other_trigger'; |
| 71 | 82 | } |
| 72 | 83 | |
| 73 | - FrmHtmlHelper::echo_dropdown_option( $opt, (bool) $selected, $option_params ); | |
| 84 | + if ( FrmFieldsHelper::should_disable_choice( $opt_key, $selected, $field ) ) { | |
| 85 | + $option_params['disabled'] = 'disabled'; | |
| 86 | + } | |
| 87 | + | |
| 88 | + echo '<option '; | |
| 89 | + FrmAppHelper::array_to_html_params( $option_params, true ); | |
| 90 | + selected( (bool) $selected ); | |
| 91 | + echo '>'; | |
| 92 | + echo esc_html( $opt === '' ? ' ' : $opt ); | |
| 93 | + FrmFieldsHelper::after_choice_input( $field, $opt_key ); | |
| 94 | + | |
| 95 | + echo '</option>'; | |
| 96 | + | |
| 74 | 97 | unset( $option_params ); |
| 75 | 98 | }//end foreach |
| 76 | 99 | ?> |
| 77 | 100 | </select> |