MP_Calculator_ElementorWidget

Class MP_Calculator_ElementorWidget


Description Description

See also See also


Top ↑

Source Source

File: mortgage-platform/Inc/Calculators/MortgageCalculator/Extensions/MP_Calculator_ElementorWidget.php

class MP_Calculator_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 MortgagePlatform::$domain;
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve oEmbed widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return MortgagePlatform::$plugin_name;
	}

	/**
	 * 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 array( 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_Settings();
		$fonts               = $settings->get_google_fonts();
		$calculator_settings = get_option( MortgagePlatform::$prefix . 'style' );

		$this->start_controls_section(
			'section_shortcode',
			array(
				'label' => __( 'Settings', 'mortgage_platform' ),
			)
		);

		$this->add_control(
			'type_style',
			array(
				'label'       => __( 'Type Style', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => array(
					'lighttheme' => __( 'Light theme', 'mortgage_platform' ),
					'darktheme'  => __( 'Dark theme', 'mortgage_platform' ),
				),
				'description' => __( 'Choose type style of calculator', 'mortgage_platform' ),
				'default'     => $calculator_settings['type_style'],
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'primary_color',
			array(
				'label'       => __( 'Primary Color', 'mortgage_platform' ),
				'type'        => Controls_Manager::COLOR,
				'description' => __( 'This sets the primary color for the Calculator', 'mortgage_platform' ),
				'default'     => $calculator_settings['primary_color'],
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'fonts',
			array(
				'label'       => __( 'Fonts', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => $fonts,
				'default'     => $calculator_settings['fonts'],
				'description' => __( 'Choose the font to use.', 'mortgage_platform' ),
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'type_inputs',
			array(
				'label'       => __( 'Type inputs', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => array(
					'bottom_line'   => __( 'Bottom line', 'mortgage_platform' ),
					'squared_input' => __( 'Squared', 'mortgage_platform' ),
					'rounded_input' => __( 'Rounded', 'mortgage_platform' ),
				),
				'default'     => $calculator_settings['type_inputs'],
				'description' => __( 'Type inputs', 'mortgage_platform' ),
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'rounded_elements',
			array(
				'label'       => __( 'Rounded Buttons', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => array(
					0 => __( 'Disable', 'mortgage_platform' ),
					1 => __( 'Enable', 'mortgage_platform' ),
				),
				'default'     => isset( $calculator_settings['rounded_elements'] ) ? $calculator_settings['rounded_elements'] : null,
				'description' => __( 'Rounded Buttons', 'mortgage_platform' ),
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'slider_for_input',
			array(
				'label'       => __( 'Enable Slider for Input', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => array(
					0 => __( 'Disable', 'mortgage_platform' ),
					1 => __( 'Enable', 'mortgage_platform' ),
				),
				'default'     => isset( $calculator_settings['slider_for_input'] ) ? $calculator_settings['slider_for_input'] : null,
				'description' => __( 'Enable Slider for Input', 'mortgage_platform' ),
				'dynamic'     => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'type_slyder',
			array(
				'label'       => __( 'Type Slider for input', 'mortgage_platform' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => array(
					'round'    => __( 'Round', 'mortgage_platform' ),
					'oval'     => __( 'Oval', 'mortgage_platform' ),
					'triangle' => __( 'Triangle', 'mortgage_platform' ),
				),
				'default'     => $calculator_settings['type_slyder'],
				'description' => __( 'Type Slider for input', 'mortgage_platform' ),
				'dynamic'     => array(
					'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_Calculator_Shortcode();
		echo $shortcode->mortgage_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() {}




}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.