date-time.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor date/time control.
  8. *
  9. * A base control for creating date time control. Displays a date/time picker
  10. * based on the Flatpickr library @see https://chmln.github.io/flatpickr/ .
  11. *
  12. * @since 1.0.0
  13. */
  14. class Control_Date_Time extends Base_Data_Control {
  15. /**
  16. * Get date time control type.
  17. *
  18. * Retrieve the control type, in this case `date_time`.
  19. *
  20. * @since 1.0.0
  21. * @access public
  22. *
  23. * @return string Control type.
  24. */
  25. public function get_type() {
  26. return 'date_time';
  27. }
  28. /**
  29. * Get date time control default settings.
  30. *
  31. * Retrieve the default settings of the date time control. Used to return the
  32. * default settings while initializing the date time control.
  33. *
  34. * @since 1.8.0
  35. * @access protected
  36. *
  37. * @return array Control default settings.
  38. */
  39. protected function get_default_settings() {
  40. return [
  41. 'label_block' => true,
  42. 'picker_options' => [],
  43. ];
  44. }
  45. /**
  46. * Render date time control output in the editor.
  47. *
  48. * Used to generate the control HTML in the editor using Underscore JS
  49. * template. The variables for the class are available using `data` JS
  50. * object.
  51. *
  52. * @since 1.0.0
  53. * @access public
  54. */
  55. public function content_template() {
  56. $control_uid = $this->get_control_uid();
  57. ?>
  58. <div class="elementor-control-field">
  59. <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
  60. <div class="elementor-control-input-wrapper">
  61. <input id="<?php echo $control_uid; ?>" class="elementor-date-time-picker flatpickr" type="text" data-setting="{{ data.name }}">
  62. </div>
  63. </div>
  64. <# if ( data.description ) { #>
  65. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  66. <# } #>
  67. <?php
  68. }
  69. }