| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor alert control. |
| 10 |
* |
| 11 |
* A base control for creating alerts in the Editor panels. |
| 12 |
* |
| 13 |
* @since 3.19.0 |
| 14 |
*/ |
| 15 |
class Control_Alert extends Base_UI_Control { |
| 16 |
|
| 17 |
/** |
| 18 |
* Get alert control type. |
| 19 |
* |
| 20 |
* Retrieve the control type, in this case `alert`. |
| 21 |
* |
| 22 |
* @since 3.19.0 |
| 23 |
* @access public |
| 24 |
* |
| 25 |
* @return string Control type. |
| 26 |
*/ |
| 27 |
public function get_type() { |
| 28 |
return 'alert'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Render alert control output in the editor. |
| 33 |
* |
| 34 |
* Used to generate the control HTML in the editor using Underscore JS |
| 35 |
* template. The variables for the class are available using `data` JS |
| 36 |
* object. |
| 37 |
* |
| 38 |
* @since 3.19.0 |
| 39 |
* @access public |
| 40 |
*/ |
| 41 |
public function content_template() { |
| 42 |
?> |
| 43 |
<# |
| 44 |
const validAlertTypes = [ 'info', 'success', 'warning', 'danger' ]; |
| 45 |
if ( ! validAlertTypes.includes( data.alert_type ) ) { |
| 46 |
data.alert_type = 'info'; |
| 47 |
} |
| 48 |
data.content = elementor.compileTemplate( data.content, { view } ); |
| 49 |
#> |
| 50 |
<div class="elementor-control-alert elementor-panel-alert elementor-panel-alert-{{ data.alert_type }}"> |
| 51 |
<# if ( data.heading ) { #> |
| 52 |
<div class="elementor-control-alert-heading">{{{ data.heading }}}</div> |
| 53 |
<# } #> |
| 54 |
<# if ( data.content ) { #> |
| 55 |
<div class="elementor-control-alert-content ">{{{ data.content }}}</div> |
| 56 |
<# } #> |
| 57 |
</div> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Get alert control default settings. |
| 63 |
* |
| 64 |
* Retrieve the default settings of the alert control. Used to return the |
| 65 |
* default settings while initializing the alert control. |
| 66 |
* |
| 67 |
* @since 3.19.0 |
| 68 |
* @access protected |
| 69 |
* |
| 70 |
* @return array Control default settings. |
| 71 |
*/ |
| 72 |
protected function get_default_settings() { |
| 73 |
return [ |
| 74 |
'alert_type' => '', // info, success, warning, danger. |
| 75 |
'heading' => '', |
| 76 |
'content' => '', |
| 77 |
]; |
| 78 |
} |
| 79 |
} |
| 80 |
|