code.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor code control.
  8. *
  9. * A base control for creating code control. Displays a code editor textarea.
  10. * Based on Ace editor (@see https://ace.c9.io/).
  11. *
  12. * @since 1.0.0
  13. */
  14. class Control_Code extends Base_Data_Control {
  15. /**
  16. * Get code control type.
  17. *
  18. * Retrieve the control type, in this case `code`.
  19. *
  20. * @since 1.0.0
  21. * @access public
  22. *
  23. * @return string Control type.
  24. */
  25. public function get_type() {
  26. return 'code';
  27. }
  28. /**
  29. * Get code control default settings.
  30. *
  31. * Retrieve the default settings of the code control. Used to return the default
  32. * settings while initializing the code control.
  33. *
  34. * @since 1.0.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. 'language' => 'html', // html/css
  43. 'rows' => 10,
  44. ];
  45. }
  46. /**
  47. * Render code control output in the editor.
  48. *
  49. * Used to generate the control HTML in the editor using Underscore JS
  50. * template. The variables for the class are available using `data` JS
  51. * object.
  52. *
  53. * @since 1.0.0
  54. * @access public
  55. */
  56. public function content_template() {
  57. $control_uid = $this->get_control_uid();
  58. ?>
  59. <div class="elementor-control-field">
  60. <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
  61. <div class="elementor-control-input-wrapper">
  62. <textarea id="<?php echo $control_uid; ?>" rows="{{ data.rows }}" class="elementor-input-style elementor-code-editor" data-setting="{{ data.name }}"></textarea>
  63. </div>
  64. </div>
  65. <# if ( data.description ) { #>
  66. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  67. <# } #>
  68. <?php
  69. }
  70. }