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