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