File: /home/frenchy/refonte2023/wordpress/wp-content/themes/gimont/elementor/widgets/contact-box.php
<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Utils;
use Elementor\Group_Control_Border;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Gimont_Elementor_Contact_Box extends Widget_Base {
public function get_name() {
return 'gimont_elementor_contact_box';
}
public function get_title() {
return esc_html__( 'Contact Box', 'gimont' );
}
public function get_icon() {
return 'eicon-image-rollover';
}
public function get_categories() {
return [ 'gimont' ];
}
public function get_script_depends() {
return [ '' ];
}
// Add Your Controll In This Function
protected function register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => esc_html__( 'Content', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'template',
[
'label' => esc_html__( 'Template', 'gimont' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'template_1',
'options' => [
'template_1' => esc_html__( 'Template 1', 'gimont' ),
'template_2' => esc_html__( 'Template 2', 'gimont' ),
],
]
);
$this->add_control(
'link',
[
'label' => esc_html__( 'Link', 'gimont' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => esc_html__( 'https://your-link.com', 'gimont' ),
'options' => [ 'url', 'is_external', 'nofollow' ],
'default' => [
'url' => '#',
'is_external' => false,
'nofollow' => false,
],
'label_block' => true,
]
);
$this->add_control(
'icon',
[
'label' => esc_html__( 'Icon', 'gimont' ),
'type' => \Elementor\Controls_Manager::ICONS,
]
);
$this->add_control(
'title',
[
'label' => esc_html__( 'Title', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXTAREA,
'default' => esc_html__( 'Get city governement support', 'gimont' ),
'label_block' => true,
]
);
$this->add_control(
'description',
[
'label' => esc_html__( 'Description', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXTAREA,
'label_block' => true,
]
);
$this->add_control(
'text_button',
[
'label' => esc_html__( 'Text Button', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => esc_html__( 'Contact', 'gimont' ),
'label_block' => true,
]
);
$this->add_responsive_control(
'alignment',
[
'label' => esc_html__( 'Alignment', 'gimont' ),
'type' => \Elementor\Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__( 'Left', 'gimont' ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'gimont' ),
'icon' => 'eicon-text-align-center',
],
'right' => [
'title' => esc_html__( 'Right', 'gimont' ),
'icon' => 'eicon-text-align-right',
],
],
'toggle' => true,
'selectors' => [
'{{WRAPPER}} .ova-contact-box' => 'text-align: {{VALUE}};',
],
]
);
$this->add_control(
'show_triangle',
[
'label' => esc_html__( 'Show Triangle', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'gimont' ),
'label_off' => esc_html__( 'No', 'gimont' ),
'default' => 'no',
]
);
$this->end_controls_section();
$this->start_controls_section(
'box_section_style',
[
'label' => esc_html__( 'Background', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
\Elementor\Group_Control_Background::get_type(),
[
'name' => 'background',
'types' => [ 'classic', 'gradient', 'video' ],
'selector' => '{{WRAPPER}} .ova-contact-box',
]
);
$this->add_control(
'box_max_width',
[
'label' => esc_html__( 'Max Width', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 250,
'max' => 1290,
'step' => 1,
],
'%' => [
'min' => 20,
'max' => 100,
'step' => 2,
]
],
'selectors' => [
'{{WRAPPER}} .ova-contact-box' => 'max-width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'box_padding',
[
'label' => esc_html__( 'Padding', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
/* Icon */
$this->start_controls_section(
'icon_style_section',
[
'label' => esc_html__( 'Icon', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'icon_size',
[
'label' => esc_html__( 'Icon Size', 'gimont' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
'step' => 5,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .icon i' => 'font-size: {{SIZE}}{{UNIT}};',
'{{WRAPPER}} .ova-contact-box .icon svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'icon_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .icon i' => 'color: {{VALUE}}',
'{{WRAPPER}} .ova-contact-box .icon svg' => 'fill: {{VALUE}}',
],
]
);
$this->add_responsive_control(
'icon_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .icon' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'title_style_section',
[
'label' => esc_html__( 'Title', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'selector' => '{{WRAPPER}} .ova-contact-box .title',
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .title' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'title_max_width',
[
'label' => esc_html__( 'Max Width', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 200,
'max' => 600,
'step' => 2,
],
'%' => [
'min' => 20,
'max' => 100,
'step' => 2,
]
],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .title' => 'max-width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'title_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'description_style_section',
[
'label' => esc_html__( 'Description', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'description_typography',
'selector' => '{{WRAPPER}} .ova-contact-box .description',
]
);
$this->add_control(
'description_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .description' => 'color: {{VALUE}}',
],
]
);
$this->add_responsive_control(
'description_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
/*Text Button*/
$this->start_controls_section(
'text_button_style_section',
[
'label' => esc_html__( 'Text Button', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'text_button_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'text_button_padding',
[
'label' => esc_html__( 'Padding', 'gimont' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'text_button_typography',
'selector' => '{{WRAPPER}} .ova-contact-box .box-button',
]
);
$this->start_controls_tabs(
'text_button_style_tabs'
);
$this->start_controls_tab(
'text_button_style_normal_tab',
[
'label' => esc_html__( 'Normal', 'gimont' ),
]
);
$this->add_control(
'text_button_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'text_button_background',
[
'label' => esc_html__( 'Background', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button' => 'background: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'text_button_style_hover_tab',
[
'label' => esc_html__( 'Hover', 'gimont' ),
]
);
$this->add_control(
'text_button_hover_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'text_button_hover_background',
[
'label' => esc_html__( 'Background', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box .box-button:hover' => 'background: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->end_controls_section();
$this->start_controls_section(
'triangle_style_section',
[
'label' => esc_html__( 'Triangle', 'gimont' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
'condition' => [
'show_triangle' => 'yes'
]
]
);
$this->add_control(
'triangle_color',
[
'label' => esc_html__( 'Background Color', 'gimont' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-box.triangle:before' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'triangle_left_position',
[
'label' => esc_html__( 'Left Position', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 0,
'max' => 500,
'step' => 1,
],
'%' => [
'min' => 0,
'max' => 100,
'step' => 1,
]
],
'selectors' => [
'{{WRAPPER}} .ova-contact-box.triangle:before' => 'left: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
}
// Render Template Here
protected function render() {
$settings = $this->get_settings();
$template = $settings['template'];
$link = $settings['link']['url'];
$nofollow = $settings['link']['nofollow'] ? 'rel="nofollow"' : '';
$target = $settings['link']['is_external'] ? 'target=_blank' : '';
$icon = $settings['icon'];
$title = $settings['title'];
$description = $settings['description'];
$text_button = $settings['text_button'];
$triangle = $settings['show_triangle'] == 'yes' ? 'triangle' : '';
?>
<div class="ova-contact-box <?php echo esc_attr( $template ); ?> <?php echo esc_attr( $triangle ); ?>">
<?php if( !empty($icon['value']) ) { ?>
<div class="icon">
<?php \Elementor\Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] ); ?>
</div>
<?php } ?>
<a href="<?php echo esc_url( $link ); ?>" <?php printf('%1$s %2$s', $nofollow, $target); ?>>
<h3 class="title"><?php echo esc_html( $title ); ?></h3>
</a>
<?php if( !empty($description) ) { ?>
<p class="description"><?php echo esc_html( $description ); ?></p>
<?php } ?>
<?php if( !empty($text_button) ) { ?>
<a href="<?php echo esc_url( $link ); ?>" class="box-button" <?php printf('%1$s %2$s', $nofollow, $target); ?>>
<?php echo esc_html( $text_button ); ?>
</a>
<?php } ?>
</div>
<?php
}
}
$widgets_manager->register( new Gimont_Elementor_Contact_Box() );