| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Elementor WPBC_Elementor_Custom_Form_Selection_Control control. |
| 5 |
* |
| 6 |
* A control for displaying a select field with the ability to choose booking_custom_forms. |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
class WPBC_Elementor_Custom_Form_Selection_Control extends \Elementor\Base_Data_Control { |
| 11 |
|
| 12 |
/** |
| 13 |
* Get custom_form control type. |
| 14 |
* |
| 15 |
* Retrieve the control type, in this case `custom_form`. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @access public |
| 19 |
* @return string Control type. |
| 20 |
*/ |
| 21 |
public function get_type(): string { |
| 22 |
return 'wpbc_custom_form_selection'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Get booking_custom_forms. |
| 27 |
* |
| 28 |
* Retrieve all the available booking_custom_forms. |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @access public |
| 32 |
* @static |
| 33 |
* @return array Available booking_custom_forms. |
| 34 |
*/ |
| 35 |
public static function get_booking_custom_forms(): array { |
| 36 |
|
| 37 |
$custom_forms_arr_sorted = WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html__for_elementor(); |
| 38 |
|
| 39 |
$sorted_options_list = array(); |
| 40 |
|
| 41 |
foreach ( $custom_forms_arr_sorted as $slug => $form_item ) { |
| 42 |
if ( is_array( $form_item ) ) { |
| 43 |
if ( isset( $form_item['optgroup'] ) ) { |
| 44 |
$sorted_options_list[] = $form_item; |
| 45 |
} else { |
| 46 |
// Legacy skins with attributes: 'style=>'color:#ccc;' . |
| 47 |
$form_item['slug'] = $slug; |
| 48 |
$sorted_options_list[] = $form_item; |
| 49 |
} |
| 50 |
} else { |
| 51 |
$sorted_options_list[] = array( |
| 52 |
'slug' => $slug, |
| 53 |
'title' => $form_item, |
| 54 |
); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $sorted_options_list; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Get custom_form control default settings. |
| 63 |
* |
| 64 |
* Retrieve the default settings of the custom_form control. Used to return |
| 65 |
* the default settings while initializing the custom_form control. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* @access protected |
| 69 |
* @return array Currency control default settings. |
| 70 |
*/ |
| 71 |
protected function get_default_settings(): array { |
| 72 |
return [ |
| 73 |
'booking_custom_forms' => self::get_booking_custom_forms() |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get custom_form control default value. |
| 79 |
* |
| 80 |
* Retrieve the default value of the custom_form control. Used to return the |
| 81 |
* default value while initializing the control. |
| 82 |
* |
| 83 |
* @since 1.0.0 |
| 84 |
* @access public |
| 85 |
* @return array Currency control default value. |
| 86 |
*/ |
| 87 |
public function get_default_value(): string { |
| 88 |
|
| 89 |
$booking_custom_forms_arr = self::get_booking_custom_forms(); |
| 90 |
|
| 91 |
foreach ( $booking_custom_forms_arr as $index => $custom_form_arr ) { |
| 92 |
return $custom_form_arr['slug']; |
| 93 |
} |
| 94 |
return 'standard'; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
/** |
| 99 |
* Render custom_form control output in the editor. |
| 100 |
* |
| 101 |
* Used to generate the control HTML in the editor using Underscore JS |
| 102 |
* template. The variables for the class are available using `data` JS |
| 103 |
* object. |
| 104 |
* |
| 105 |
* @since 1.0.0 |
| 106 |
* @access public |
| 107 |
*/ |
| 108 |
public function content_template(): void { |
| 109 |
$control_uid = $this->get_control_uid(); |
| 110 |
?> |
| 111 |
<div class="elementor-control-field elementor-control-type-select"> |
| 112 |
|
| 113 |
<# if ( data.label ) {#> |
| 114 |
<label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 115 |
<# } #> |
| 116 |
|
| 117 |
<div class="elementor-control-input-wrapper"> |
| 118 |
<select id="<?php echo esc_attr( $control_uid ); ?>" data-setting="{{ data.name }}"> |
| 119 |
<# _.each( data.booking_custom_forms, function( custom_form_arr, custom_form_index ) { |
| 120 |
if ( custom_form_arr['optgroup'] ) { // OPTGROUP |
| 121 |
|
| 122 |
if ( ! custom_form_arr['close'] ) { |
| 123 |
#><optgroup label="{{{custom_form_arr['title']}}}"><# |
| 124 |
} else { |
| 125 |
#></optgroup><# |
| 126 |
} |
| 127 |
|
| 128 |
} else { |
| 129 |
#><option value="{{ custom_form_arr['slug'] }}" >{{{ custom_form_arr['title'] }}}</option><# |
| 130 |
} |
| 131 |
} ); #> |
| 132 |
</select> |
| 133 |
</div> |
| 134 |
|
| 135 |
</div> |
| 136 |
<# if ( data.description ) { #> |
| 137 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 138 |
<# } #> |
| 139 |
<?php |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|