select.php (2512B)
1 <?php 2 namespace Elementor; 3 4 if ( ! defined( 'ABSPATH' ) ) { 5 exit; // Exit if accessed directly. 6 } 7 8 /** 9 * Elementor select control. 10 * 11 * A base control for creating select control. Displays a simple select box. 12 * It accepts an array in which the `key` is the option value and the `value` is 13 * the option name. 14 * 15 * @since 1.0.0 16 */ 17 class Control_Select extends Base_Data_Control { 18 19 /** 20 * Get select control type. 21 * 22 * Retrieve the control type, in this case `select`. 23 * 24 * @since 1.0.0 25 * @access public 26 * 27 * @return string Control type. 28 */ 29 public function get_type() { 30 return 'select'; 31 } 32 33 /** 34 * Get select control default settings. 35 * 36 * Retrieve the default settings of the select control. Used to return the 37 * default settings while initializing the select control. 38 * 39 * @since 2.0.0 40 * @access protected 41 * 42 * @return array Control default settings. 43 */ 44 protected function get_default_settings() { 45 return [ 46 'options' => [], 47 ]; 48 } 49 50 /** 51 * Render select control output in the editor. 52 * 53 * Used to generate the control HTML in the editor using Underscore JS 54 * template. The variables for the class are available using `data` JS 55 * object. 56 * 57 * @since 1.0.0 58 * @access public 59 */ 60 public function content_template() { 61 ?> 62 <div class="elementor-control-field"> 63 <# if ( data.label ) {#> 64 <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> 65 <# } #> 66 <div class="elementor-control-input-wrapper elementor-control-unit-5"> 67 <select id="<?php $this->print_control_uid(); ?>" data-setting="{{ data.name }}"> 68 <# 69 var printOptions = function( options ) { 70 _.each( options, function( option_title, option_value ) { #> 71 <option value="{{ option_value }}">{{{ option_title }}}</option> 72 <# } ); 73 }; 74 75 if ( data.groups ) { 76 for ( var groupIndex in data.groups ) { 77 var groupArgs = data.groups[ groupIndex ]; 78 if ( groupArgs.options ) { #> 79 <optgroup label="{{ groupArgs.label }}"> 80 <# printOptions( groupArgs.options ) #> 81 </optgroup> 82 <# } else if ( _.isString( groupArgs ) ) { #> 83 <option value="{{ groupIndex }}">{{{ groupArgs }}}</option> 84 <# } 85 } 86 } else { 87 printOptions( data.options ); 88 } 89 #> 90 </select> 91 </div> 92 </div> 93 <# if ( data.description ) { #> 94 <div class="elementor-control-field-description">{{{ data.description }}}</div> 95 <# } #> 96 <?php 97 } 98 }