MP_Addon_Payoff_ElementorWidget
Contents
Description Description
See also See also
Source Source
File: calculator-mortgage-payoff-add-on/inc/extensions/MP_Addon_Payoff_ElementorWidget.php
class MP_Addon_Payoff_ElementorWidget extends \Elementor\Widget_Base {
/**
* Get widget name.
*
* Retrieve oEmbed widget name.
*
* @since 1.0.0
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'mortgage_payoff_calculator';
}
/**
* Get widget title.
*
* Retrieve oEmbed widget title.
*
* @since 1.0.0
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return __('Mortgage Payoff Calculator','CalculatorsMortgagePayoffAddon');
}
/**
* Get widget icon.
*
* Retrieve oEmbed widget icon.
*
* @since 1.0.0
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'fa fa-calculator';
}
/**
* Get widget categories.
*
* Retrieve the list of categories the oEmbed widget belongs to.
*
* @since 1.0.0
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return [ MortgagePlatform::$domain ];
}
/**
* Whether the reload preview is required or not.
*
* Used to determine whether the reload preview is required.
*
* @since 1.0.0
* @access public
*
* @return bool Whether the reload preview is required.
*/
public function is_reload_preview_required() {
return true;
}
/**
* Register oEmbed widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
* @access protected
*/
protected function _register_controls() {
$settings = new MP_Addon_Payoff_Settings();
$fonts = $settings->get_google_fonts();
$calculator_settings = get_option(MortgagePlatform::$prefix.'style');
$this->start_controls_section(
'section_shortcode',
[
'label' => __( 'Settings', 'CalculatorsMortgagePayoffAddon' ),
]
);
$this->add_control(
'type_style',
[
'label' => __( 'Type Style', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => [
'lighttheme' => __( 'Light theme', 'CalculatorsMortgagePayoffAddon' ),
'darktheme' => __( 'Dark theme', 'CalculatorsMortgagePayoffAddon' ),
],
'description' => __( 'Choose type style of calculator', 'CalculatorsMortgagePayoffAddon' ),
'default' => $calculator_settings['type_style'],
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'primary_color',
[
'label' => __( 'Primary Color', 'CalculatorsMortgagePayoffAddon' ),
'type' => Controls_Manager::COLOR,
'description' => __( 'This sets the primary color for the Calculator', 'CalculatorsMortgagePayoffAddon' ),
'default' => $calculator_settings['primary_color'],
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'fonts',
[
'label' => __( 'Fonts', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => $fonts,
'default' => $calculator_settings['fonts'],
'description' => __( 'Choose the font to use.', 'CalculatorsMortgagePayoffAddon' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'type_inputs',
[
'label' => __( 'Type inputs', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => [
'bottom_line' => __('Bottom line', 'CalculatorsMortgagePayoffAddon'),
'squared_input' => __('Squared', 'CalculatorsMortgagePayoffAddon') ,
'rounded_input' => __('Rounded', 'CalculatorsMortgagePayoffAddon'),
],
'default' => $calculator_settings['type_inputs'],
'description' => __( 'Type inputs', 'CalculatorsMortgagePayoffAddon' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'rounded_elements',
[
'label' => __( 'Rounded Buttons', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => [
0 => __( 'Disable', 'CalculatorsMortgagePayoffAddon' ),
1 => __( 'Enable', 'CalculatorsMortgagePayoffAddon' ),
],
'default' => isset($calculator_settings['rounded_elements'])? $calculator_settings['rounded_elements'] : NULL,
'description' => __( 'Rounded Buttons', 'CalculatorsMortgagePayoffAddon' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'slider_for_input',
[
'label' => __( 'Enable Slider for Input', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => [
0 => __( 'Disable', 'CalculatorsMortgagePayoffAddon' ),
1 => __( 'Enable', 'CalculatorsMortgagePayoffAddon' ),
],
'default' => isset($calculator_settings['slider_for_input']) ? $calculator_settings['slider_for_input'] : NULL,
'description' => __( 'Enable Slider for Input', 'CalculatorsMortgagePayoffAddon' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'type_slyder',
[
'label' => __( 'Type Slider for input', 'CalculatorsMortgagePayoffAddon'),
'type' => Controls_Manager::SELECT,
'options' => [
'round' => __('Round', 'CalculatorsMortgagePayoffAddon'),
'oval' => __('Oval', 'CalculatorsMortgagePayoffAddon') ,
'triangle' => __('Triangle', 'CalculatorsMortgagePayoffAddon'),
],
'default' => $calculator_settings['type_slyder'],
'description' => __( 'Type Slider for input', 'CalculatorsMortgagePayoffAddon' ),
'dynamic' => [
'active' => true,
],
]
);
$this->end_controls_section();
}
/**
* Render oEmbed widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render() {
$settings = $this->get_settings();
$args = array(
"type_style" => $settings['type_style'],
"primary_color" => $settings['primary_color'],
"fonts" => $settings['fonts'],
"type_inputs" => $settings['type_inputs'],
"rounded_elements" => $settings['rounded_elements'],
"slider_for_input" => $settings['slider_for_input'],
"type_slyder" => $settings['type_slyder'],
);
$shortcode = new MP_Addon_Payoff_Shortcode();
echo $shortcode->mortgage_payoff_calculator($args);
}
/**
* Render shortcode widget as plain content.
*
* Override the default behavior by printing the shortcode instead of rendering it.
*
* @since 1.0.0
* @access public
*/
public function render_plain_content() {
echo $this->get_settings( );
}
/**
* Render shortcode widget output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 1.0.0
* @access protected
*/
protected function _content_template() {}
}
Methods Methods
- _content_template — Render shortcode widget output in the editor.
- _register_controls — Register oEmbed widget controls.
- get_categories — Get widget categories.
- get_icon — Get widget icon.
- get_name — Get widget name.
- get_title — Get widget title.
- is_reload_preview_required — Whether the reload preview is required or not.
- render — Render oEmbed widget output on the frontend.
- render_plain_content — Render shortcode widget as plain content.
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |