choose.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor choose control.
  8. *
  9. * A base control for creating choose control. Displays radio buttons styled as
  10. * groups of buttons with icons for each option.
  11. *
  12. * @since 1.0.0
  13. */
  14. class Control_Choose extends Base_Data_Control {
  15. /**
  16. * Get choose control type.
  17. *
  18. * Retrieve the control type, in this case `choose`.
  19. *
  20. * @since 1.0.0
  21. * @access public
  22. *
  23. * @return string Control type.
  24. */
  25. public function get_type() {
  26. return 'choose';
  27. }
  28. /**
  29. * Render choose control output in the editor.
  30. *
  31. * Used to generate the control HTML in the editor using Underscore JS
  32. * template. The variables for the class are available using `data` JS
  33. * object.
  34. *
  35. * @since 1.0.0
  36. * @access public
  37. */
  38. public function content_template() {
  39. $control_uid = $this->get_control_uid( '{{value}}' );
  40. ?>
  41. <div class="elementor-control-field">
  42. <label class="elementor-control-title">{{{ data.label }}}</label>
  43. <div class="elementor-control-input-wrapper">
  44. <div class="elementor-choices">
  45. <# _.each( data.options, function( options, value ) { #>
  46. <input id="<?php echo $control_uid; ?>" type="radio" name="elementor-choose-{{ data.name }}-{{ data._cid }}" value="{{ value }}">
  47. <label class="elementor-choices-label tooltip-target" for="<?php echo $control_uid; ?>" data-tooltip="{{ options.title }}" title="{{ options.title }}">
  48. <i class="{{ options.icon }}" aria-hidden="true"></i>
  49. <span class="elementor-screen-only">{{{ options.title }}}</span>
  50. </label>
  51. <# } ); #>
  52. </div>
  53. </div>
  54. </div>
  55. <# if ( data.description ) { #>
  56. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  57. <# } #>
  58. <?php
  59. }
  60. /**
  61. * Get choose control default settings.
  62. *
  63. * Retrieve the default settings of the choose control. Used to return the
  64. * default settings while initializing the choose control.
  65. *
  66. * @since 1.0.0
  67. * @access protected
  68. *
  69. * @return array Control default settings.
  70. */
  71. protected function get_default_settings() {
  72. return [
  73. 'label_block' => true,
  74. 'options' => [],
  75. 'toggle' => true,
  76. ];
  77. }
  78. }