Current File : /home/n742ef5/royalanteam.com/wp-content/plugins/myhome-core/src/Widgets/General/HeadingWidget.php |
<?php
namespace Tangibledesign\MyHome\Widgets\General;
use Elementor\Controls_Manager;
use Tangibledesign\Framework\Widgets\Helpers\BaseGeneralWidget;
use Tangibledesign\Framework\Widgets\Helpers\SelectRemoteControl;
use Tangibledesign\MyHome\Widgets\Helpers\Controls\HeadingControls;
class HeadingWidget extends BaseGeneralWidget
{
use HeadingControls;
public function getKey(): string
{
return 'heading';
}
public function getName(): string
{
return esc_html__('Section Heading', 'myhome-core');
}
protected function register_controls(): void
{
$this->startContentControlsSection();
$this->addSmallHeadingControl();
$this->addSmallHeadingTagControl();
$this->addHeadingControl();
$this->addHeadingTagControl();
$this->addAlignmentControl();
$this->addButtonControls();
$this->endControlsSection();
$this->addHeadingStyleSection();
}
private function addHeadingTagControl(): void
{
$this->add_control(
'heading_tag',
[
'label' => esc_html__('Heading Tag', 'myhome-core'),
'type' => Controls_Manager::SELECT,
'options' => [
'h1' => esc_html__('H1', 'myhome-core'),
'h2' => esc_html__('H2', 'myhome-core'),
'h3' => esc_html__('H3', 'myhome-core'),
'h4' => esc_html__('H4', 'myhome-core'),
'h5' => esc_html__('H5', 'myhome-core'),
'h6' => esc_html__('H6', 'myhome-core'),
],
'default' => 'h2',
]
);
}
public function getHeadingTag(): string
{
return (string)$this->get_settings_for_display('heading_tag');
}
private function addSmallHeadingTagControl(): void
{
$this->add_control(
'small_heading_tag',
[
'label' => esc_html__('Small Heading Tag', 'myhome-core'),
'type' => Controls_Manager::SELECT,
'options' => [
'h1' => esc_html__('H1', 'myhome-core'),
'h2' => esc_html__('H2', 'myhome-core'),
'h3' => esc_html__('H3', 'myhome-core'),
'h4' => esc_html__('H4', 'myhome-core'),
'h5' => esc_html__('H5', 'myhome-core'),
'h6' => esc_html__('H6', 'myhome-core'),
],
'default' => 'h3',
]
);
}
public function getSmallHeadingTag(): string
{
return (string)$this->get_settings_for_display('small_heading_tag');
}
private function addButtonControls(): void
{
$this->add_control(
'custom_button_heading',
[
'label' => esc_html__('Button', 'myhome-core'),
'type' => Controls_Manager::HEADING,
'condition' => [
'alignment' => 'left',
],
]
);
$this->add_control(
'custom_url_switch',
[
'label' => esc_html__('Use Custom URL', 'myhome-core'),
'type' => Controls_Manager::SWITCHER,
'default' => '0',
'return_value' => '1',
'condition' => [
'alignment' => 'left',
],
]
);
$this->add_control(
'button_destination',
[
'label' => esc_html__('Destination', 'myhome-core'),
'type' => SelectRemoteControl::TYPE,
'source' => tdf_action_url(tdf_prefix() . '/button/destinations'),
'condition' => [
'custom_url_switch' => '0',
'alignment' => 'left',
],
]
);
$this->add_control(
'button_destination_custom',
[
'label' => esc_html__('Custom URL', 'myhome-core'),
'type' => Controls_Manager::TEXT,
'condition' => [
'custom_url_switch' => '1',
'alignment' => 'left',
],
]
);
$this->add_control(
'button_text',
[
'label' => esc_html__('Text', 'myhome-core'),
'type' => Controls_Manager::TEXT,
'condition' => [
'alignment' => 'left',
],
]
);
}
public function showButton(): bool
{
return $this->get_settings_for_display('alignment') === 'left' && !empty($this->getButtonText());
}
public function getButtonText(): string
{
return (string)$this->get_settings_for_display('button_text');
}
public function getButtonUrl(): string
{
if ($this->get_settings_for_display('custom_url_switch') === '1') {
return $this->get_settings_for_display('button_destination_custom');
}
return apply_filters(
tdf_prefix() . '/button/destination',
false,
(string)$this->get_settings_for_display('button_destination')
);
}
}