File: /home/frenchy/refonte2023/wordpress/wp-content/themes/gimont/elementor/widgets/contact-info-2.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_Info_2 extends Widget_Base {
public function get_name() {
return 'gimont_elementor_contact_info_2';
}
public function get_title() {
return esc_html__( 'Contact Info 2', 'gimont' );
}
public function get_icon() {
return 'eicon-email-field';
}
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(
'section_content',
[
'label' => esc_html__( 'Content', 'gimont' ),
]
);
$this->add_control(
'icon',
[
'label' => esc_html__( 'Class Icon', 'gimont' ),
'type' => \Elementor\Controls_Manager::ICONS,
'default' => [
'value' => 'ovaicon ovaicon-mail',
'library' => 'ovaicon',
],
]
);
$this->add_control(
'label',
[
'label' => esc_html__( 'Label', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => esc_html__( 'Label', 'gimont' ),
]
);
$repeater = new \Elementor\Repeater();
$repeater->add_control(
'type',
[
'label' => esc_html__( 'Type', 'gimont' ),
'type' => Controls_Manager::SELECT,
'default' => 'email',
'options' => [
'email' => esc_html__('Email', 'gimont'),
'phone' => esc_html__('Phone', 'gimont'),
'link' => esc_html__('Link', 'gimont'),
'text' => esc_html__('Text', 'gimont'),
]
]
);
$repeater->add_control(
'email_label',
[
'label' => esc_html__( 'Email Label', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( 'email@company.com', 'gimont' ),
'condition' => [
'type' => 'email',
]
]
);
$repeater->add_control(
'email_address',
[
'label' => esc_html__( 'Email Adress', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( 'email@company.com', 'gimont' ),
'condition' => [
'type' => 'email',
]
]
);
$repeater->add_control(
'phone_label',
[
'label' => esc_html__( 'Phone Label', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( '+012 (345) 678', 'gimont' ),
'condition' => [
'type' => 'phone',
]
]
);
$repeater->add_control(
'phone_address',
[
'label' => esc_html__( 'Phone Adress', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( '+012345678', 'gimont' ),
'condition' => [
'type' => 'phone',
]
]
);
$repeater->add_control(
'link_label',
[
'label' => esc_html__( 'Link Label', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( 'https://your-domain.com', 'gimont' ),
'condition' => [
'type' => 'link',
]
]
);
$repeater->add_control(
'link_address',
[
'label' => esc_html__( 'Link Adress', 'gimont' ),
'type' => \Elementor\Controls_Manager::URL,
'description' => esc_html__( 'https://your-domain.com', 'gimont' ),
'condition' => [
'type' => 'link',
],
'show_external' => false,
'default' => [
'url' => '#',
'is_external' => true,
'nofollow' => false,
],
]
);
$repeater->add_control(
'text',
[
'label' => esc_html__( 'Text', 'gimont' ),
'type' => \Elementor\Controls_Manager::TEXTAREA,
'description' => esc_html__( 'Your text', 'gimont' ),
'condition' => [
'type' => 'text',
]
]
);
$this->add_responsive_control(
'content_vertical_align',
[
'label' => esc_html__( 'Vertical Align ', 'gimont' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'flex-start' => [
'title' => esc_html__( 'Top', 'gimont' ),
'icon' => 'eicon-v-align-top',
],
'center' => [
'title' => esc_html__( 'Center', 'gimont' ),
'icon' => 'eicon-v-align-middle',
],
'flex-end' => [
'title' => esc_html__( 'Bottom', 'gimont' ),
'icon' => ' eicon-v-align-bottom',
],
],
'default' => '',
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2' => 'align-items: {{VALUE}};',
],
]
);
$this->add_responsive_control(
'content_align',
[
'label' => esc_html__( 'Alignment', 'gimont' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'flex-start' => [
'title' => esc_html__( 'Left', 'gimont' ),
'icon' => 'eicon-h-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'gimont' ),
'icon' => 'eicon-h-align-center',
],
'flex-end' => [
'title' => esc_html__( 'Right', 'gimont' ),
'icon' => ' eicon-h-align-right',
],
],
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2' => 'justify-content: {{VALUE}};',
],
]
);
$this->add_control(
'items_info',
[
'label' => esc_html__( 'Items Info', 'gimont' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'type' => 'email',
'email_label' => esc_html__('email@company.com', 'gimont'),
'email_address' => esc_html__('email@company.com', 'gimont'),
],
],
'title_field' => '{{{ type }}}',
]
);
$this->end_controls_section();
// End Content Tab
/**
* Icon Style Tab
*/
$this->start_controls_section(
'section_icon_style',
[
'label' => esc_html__( 'Icon', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'icon_fontsize',
[
'label' => esc_html__( 'Font Size', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px' ],
'range' => [
'px' => [
'min' => 1,
'max' => 100,
'step' => 1,
]
],
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .icon i' => 'font-size: {{SIZE}}{{UNIT}};',
'{{WRAPPER}} .ova-contact-info-2 .icon svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'icon_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .icon i' => 'color : {{VALUE}};',
'{{WRAPPER}} .ova-contact-info-2 .icon svg path' => 'fill: {{VALUE}}; stroke: {{VALUE}};',
],
]
);
$this->add_responsive_control(
'icon_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .icon'=> 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section(); // End Icon Style Tab
/**
* Label Style Tab
*/
$this->start_controls_section(
'section_label_style',
[
'label' => esc_html__( 'Label', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'label_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .label' => 'color : {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'label_typography',
'selector' => '{{WRAPPER}} .ova-contact-info-2 .contact .label',
]
);
$this->add_responsive_control(
'label_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'label_align',
[
'label' => esc_html__( 'Alignment', 'gimont' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__( 'Left', 'gimont' ),
'icon' => 'eicon-h-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'gimont' ),
'icon' => 'eicon-h-align-center',
],
'right' => [
'title' => esc_html__( 'Right', 'gimont' ),
'icon' => ' eicon-h-align-right',
],
],
'default' => '',
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .label' => 'text-align: {{VALUE}};',
],
]
);
$this->end_controls_section(); // End Label Style Tab
/**
* Info Style Tab
*/
$this->start_controls_section(
'section_info_style',
[
'label' => esc_html__( 'Info', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'info_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item' => 'color : {{VALUE}};',
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item a' => 'color : {{VALUE}};',
],
]
);
$this->add_control(
'info_color_hover',
[
'label' => esc_html__( 'Link Color hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item a:hover' => 'color : {{VALUE}};',
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item a:before' => 'background-color : {{VALUE}};',
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item a:hover:before' => 'background-color : {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'info_typography',
'selector' => '{{WRAPPER}} .ova-contact-info-2 .contact .info .item, {{WRAPPER}} .ova-contact-info-2 .contact .info .item a',
]
);
$this->add_responsive_control(
'info_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .info .item' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'content_info_align',
[
'label' => esc_html__( 'Alignment', 'gimont' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__( 'Left', 'gimont' ),
'icon' => 'eicon-h-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'gimont' ),
'icon' => 'eicon-h-align-center',
],
'right' => [
'title' => esc_html__( 'Right', 'gimont' ),
'icon' => ' eicon-h-align-right',
],
],
'default' => '',
'selectors' => [
'{{WRAPPER}} .ova-contact-info-2 .contact .info' => 'text-align: {{VALUE}};',
],
]
);
$this->end_controls_section();
// End Label Style Tab
}
// Render Template Here
protected function render() {
$settings = $this->get_settings();
$icon = $settings['icon'] ? $settings['icon'] : '';
$label = $settings['label'] ? $settings['label'] : '';
$items_info = $settings['items_info'];
?>
<div class="ova-contact-info-2">
<?php if( $icon['value'] ){ ?>
<div class="icon">
<?php \Elementor\Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] ); ?>
</div>
<?php } ?>
<div class="contact">
<?php if( $label ){ ?>
<div class="label">
<?php echo esc_html( $label ); ?>
</div>
<?php } ?>
<ul class="info">
<?php foreach( $items_info as $item ):
$type = $item['type'];
?>
<li class="item">
<?php switch ( $type ) {
case 'email':
$email_address = $item['email_address'];
$email_label = $item['email_label'];
if( $email_address && $email_label ){
?>
<a href="mailto:<?php echo esc_attr( $email_address ) ?> " title="<?php esc_attr_e( 'email', 'gimont' ); ?>">
<?php echo esc_html( $email_label ); ?>
</a>
<?php
}
break;
case 'phone':
$phone_address = $item['phone_address'];
$phone_label = $item['phone_label'];
if( $phone_address && $phone_label ){
?>
<a href="tel:<?php echo esc_attr( $phone_address ) ?> " title="<?php esc_attr_e( 'phone', 'gimont' ); ?>">
<?php echo esc_html( $phone_label ); ?>
</a>
<?php
}
break;
case 'link':
$this->add_render_attribute( 'title' );
$link_address = $item['link_address']['url'];
$link_label = $item['link_label'];
$title = $item['link_label'] ? $item['link_label'] : '';
if ( ! empty( $item['link_address']['url'] ) ) {
$this->add_link_attributes( 'url', $item['link_address'] );
echo sprintf( '<a %1$s title="%2$s">%3$s</a>', $this->get_render_attribute_string( 'url' ), esc_attr( $title ), esc_html( $title ) );
}else{
echo esc_html( $title );
}
break;
case 'text':
$text = $item['text'];
?>
<?php echo esc_html( $text ); ?>
<?php
break;
default:
break;
} ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php
}
}
$widgets_manager->register( new Gimont_Elementor_Contact_Info_2() );