base-data.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor base data control.
  8. *
  9. * An abstract class for creating new data controls in the panel.
  10. *
  11. * @since 1.5.0
  12. * @abstract
  13. */
  14. abstract class Base_Data_Control extends Base_Control {
  15. /**
  16. * Get data control default value.
  17. *
  18. * Retrieve the default value of the data control. Used to return the default
  19. * values while initializing the data control.
  20. *
  21. * @since 1.5.0
  22. * @access public
  23. *
  24. * @return string Control default value.
  25. */
  26. public function get_default_value() {
  27. return '';
  28. }
  29. /**
  30. * Retrieve default control settings.
  31. *
  32. * Get the default settings of the control. Used to return the default
  33. * settings while initializing the control.
  34. *
  35. * @since 2.0.0
  36. * @access protected
  37. *
  38. * @return array Control default settings.
  39. */
  40. protected function get_default_settings() {
  41. $default_settings = parent::get_default_settings();
  42. $default_settings['dynamic'] = false;
  43. return $default_settings;
  44. }
  45. /**
  46. * Get data control value.
  47. *
  48. * Retrieve the value of the data control from a specific Controls_Stack settings.
  49. *
  50. * @since 1.5.0
  51. * @access public
  52. *
  53. * @param array $control Control
  54. * @param array $settings Element settings
  55. *
  56. * @return mixed Control values.
  57. */
  58. public function get_value( $control, $settings ) {
  59. if ( ! isset( $control['default'] ) ) {
  60. $control['default'] = $this->get_default_value();
  61. }
  62. if ( isset( $settings[ $control['name'] ] ) ) {
  63. $value = $settings[ $control['name'] ];
  64. } else {
  65. $value = $control['default'];
  66. }
  67. return $value;
  68. }
  69. /**
  70. * Parse dynamic tags.
  71. *
  72. * Iterates through all the controls and renders all the dynamic tags.
  73. *
  74. * @since 2.0.0
  75. * @access public
  76. *
  77. * @param string $dynamic_value The dynamic tag text.
  78. * @param array $dynamic_settings The dynamic tag settings.
  79. *
  80. * @return string|string[]|mixed A string or an array of strings with the
  81. * return value from each tag callback function.
  82. */
  83. public function parse_tags( $dynamic_value, $dynamic_settings ) {
  84. $current_dynamic_settings = $this->get_settings( 'dynamic' );
  85. if ( is_array( $current_dynamic_settings ) ) {
  86. $dynamic_settings = array_merge( $current_dynamic_settings, $dynamic_settings );
  87. }
  88. return Plugin::$instance->dynamic_tags->parse_tags_text( $dynamic_value, $dynamic_settings, [ Plugin::$instance->dynamic_tags, 'get_tag_data_content' ] );
  89. }
  90. /**
  91. * Get data control style value.
  92. *
  93. * Retrieve the style of the control. Used when adding CSS rules to the control
  94. * while extracting CSS from the `selectors` data argument.
  95. *
  96. * @since 1.5.0
  97. * @access public
  98. *
  99. * @param string $css_property CSS property.
  100. * @param string $control_value Control value.
  101. *
  102. * @return string Control style value.
  103. */
  104. public function get_style_value( $css_property, $control_value ) {
  105. return $control_value;
  106. }
  107. /**
  108. * Get data control unique ID.
  109. *
  110. * Retrieve the unique ID of the control. Used to set a uniq CSS ID for the
  111. * element.
  112. *
  113. * @since 1.5.0
  114. * @access protected
  115. *
  116. * @param string $input_type Input type. Default is 'default'.
  117. *
  118. * @return string Unique ID.
  119. */
  120. protected function get_control_uid( $input_type = 'default' ) {
  121. return 'elementor-control-' . $input_type . '-{{{ data._cid }}}';
  122. }
  123. }