File: /mnt/data/dreamstour-wp/wp-content/plugins/dreamstour-widgets/widgets/class-faq-advanced.php
<?php
namespace Dreamstourelementor\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class DTS_faq_advanced extends Widget_Base {
public function get_name() {
return 'dreamstour_elementor_faq_advanced';
}
public function get_title() {
return \__( 'Dreams Tour FAQ + CTA', 'dreamstour_elementor' );
}
public function get_icon() {
return 'eicon-accordion';
}
public function get_categories() {
return [ 'dreamstourelemetortheme' ];
}
public function get_script_depends() {
return [ 'dreamstourelementor-elementor' ];
}
protected function register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => \__( 'FAQ Items', 'dreamstour_elementor' ),
]
);
$repeater = new Repeater();
$repeater->add_control(
'question',
[
'label' => \__( 'Question', 'dreamstour_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => \__( 'What types of tours do you offer?', 'dreamstour_elementor' ),
'label_block' => true,
]
);
$repeater->add_control(
'answer',
[
'label' => \__( 'Answer', 'dreamstour_elementor' ),
'type' => Controls_Manager::TEXTAREA,
'default' => \__( 'We offer a wide range of tours, including cultural, adventure, luxury, and customized itineraries.', 'dreamstour_elementor' ),
]
);
$this->add_control(
'faq_items',
[
'label' => \__( 'Items', 'dreamstour_elementor' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[ 'question' => \__( 'What types of tours do you offer?', 'dreamstour_elementor' ), 'answer' => \__( 'We offer a wide range of tours, including cultural, adventure, luxury, and customized itineraries.', 'dreamstour_elementor' ) ],
[ 'question' => \__( 'Are the tours customizable?', 'dreamstour_elementor' ), 'answer' => \__( 'Yes, most tours are customizable to match your preferences and schedule.', 'dreamstour_elementor' ) ],
],
'title_field' => '{{{ question }}}',
]
);
$this->add_control(
'open_first',
[
'label' => \__( 'Open first item by default', 'dreamstour_elementor' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => \__( 'Yes', 'dreamstour_elementor' ),
'label_off' => \__( 'No', 'dreamstour_elementor' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->end_controls_section();
$this->start_controls_section(
'cta_section',
[
'label' => \__( 'Other Questions CTA', 'dreamstour_elementor' ),
]
);
$this->add_control(
'cta_show',
[
'label' => \__( 'Show CTA', 'dreamstour_elementor' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => \__( 'Show', 'dreamstour_elementor' ),
'label_off' => \__( 'Hide', 'dreamstour_elementor' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'cta_title',
[
'label' => \__( 'CTA Title', 'dreamstour_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => \__( 'Have Any Other Questions?', 'dreamstour_elementor' ),
'label_block' => true,
]
);
$this->add_control(
'cta_desc',
[
'label' => \__( 'CTA Description', 'dreamstour_elementor' ),
'type' => Controls_Manager::TEXTAREA,
'default' => \__( 'If you cannot find answer to your question in our FAQ, you can always contact us. We will answer you shortly!', 'dreamstour_elementor' ),
]
);
$this->add_control(
'cta_btn_text',
[
'label' => \__( 'CTA Button Text', 'dreamstour_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => \__( 'Contact Us', 'dreamstour_elementor' ),
]
);
$this->add_control(
'cta_btn_link',
[
'label' => \__( 'CTA Button Link', 'dreamstour_elementor' ),
'type' => Controls_Manager::URL,
'default' => [ 'url' => '#', 'is_external' => false, 'nofollow' => false ],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$accordion_id = 'accordionFaq-' . $this->get_id();
$open_first = ! empty( $settings['open_first'] ) && $settings['open_first'] === 'yes';
?>
<div class="faq">
<div class="container">
<div class="faq-sec p-0">
<div class="row">
<div class="col-lg-10 mx-auto">
<div class="accordion" id="<?php echo \esc_attr( $accordion_id ); ?>">
<?php if ( ! empty( $settings['faq_items'] ) ) : ?>
<?php foreach ( $settings['faq_items'] as $index => $item ) :
$item_id = $accordion_id . '-' . ( $index + 1 );
$is_open = $open_first && $index === 0;
?>
<div class="accordion-item mb-3">
<h2 class="accordion-header">
<button class="accordion-button<?php echo $is_open ? '' : ' collapsed'; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#<?php echo \esc_attr( $item_id ); ?>" aria-expanded="<?php echo $is_open ? 'true' : 'false'; ?>" aria-controls="<?php echo \esc_attr( $item_id ); ?>">
<?php echo \esc_html( $item['question'] ); ?>
</button>
</h2>
<div id="<?php echo \esc_attr( $item_id ); ?>" class="accordion-collapse collapse<?php echo $is_open ? ' show' : ''; ?>" data-bs-parent="#<?php echo \esc_attr( $accordion_id ); ?>">
<div class="accordion-body">
<p class="mb-0"><?php echo \wp_kses_post( $item['answer'] ); ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php if ( ! empty( $settings['cta_show'] ) && $settings['cta_show'] === 'yes' ) :
$cta_url = isset( $settings['cta_btn_link']['url'] ) ? $settings['cta_btn_link']['url'] : '#';
$cta_target = ! empty( $settings['cta_btn_link']['is_external'] ) ? ' target="_blank"' : '';
$cta_rel = ! empty( $settings['cta_btn_link']['nofollow'] ) ? ' rel="nofollow"' : '';
?>
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="que-sec text-center">
<h4 class="mb-3"><?php echo \esc_html( $settings['cta_title'] ); ?></h4>
<p class="mb-3"><?php echo \esc_html( $settings['cta_desc'] ); ?></p>
<div class="d-flex justify-content-center">
<a href="<?php echo \esc_url( $cta_url ); ?>" class="btn btn-primary d-flex align-items-center justify-content-center"<?php echo $cta_target . $cta_rel; ?>><?php echo \esc_html( $settings['cta_btn_text'] ); ?><i class="isax isax-arrow-right-3 ms-1"></i></a>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<?php
}
protected function content_template() {}
}