| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Widgets; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 5 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Textarea_Control; |
| 7 |
use Elementor\Modules\AtomicWidgets\Base\Atomic_Widget_Base; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 9 |
use Elementor\Modules\AtomicWidgets\PropTypes\String_Prop_Type; |
| 10 |
use Elementor\Utils; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Atomic_Heading extends Atomic_Widget_Base { |
| 17 |
public function get_name() { |
| 18 |
return 'a-heading'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_title() { |
| 22 |
return esc_html__( 'Atomic Heading', 'elementor' ); |
| 23 |
} |
| 24 |
|
| 25 |
public function get_icon() { |
| 26 |
return 'eicon-t-letter'; |
| 27 |
} |
| 28 |
|
| 29 |
protected function render() { |
| 30 |
$settings = $this->get_atomic_settings(); |
| 31 |
|
| 32 |
$tag = $settings['tag']; |
| 33 |
$title = $settings['title']; |
| 34 |
$attrs = array_filter( [ |
| 35 |
'class' => $settings['classes'] ?? '', |
| 36 |
] ); |
| 37 |
|
| 38 |
echo sprintf( |
| 39 |
'<%1$s %2$s>%3$s</%1$s>', |
| 40 |
// TODO: we should avoid using `validate html tag` and use the enum validation instead. |
| 41 |
Utils::validate_html_tag( $tag ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 42 |
Utils::render_html_attributes( $attrs ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 43 |
esc_html( $title ) |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
protected function define_atomic_controls(): array { |
| 48 |
return [ |
| 49 |
Section::make() |
| 50 |
->set_label( __( 'Content', 'elementor' ) ) |
| 51 |
->set_items( [ |
| 52 |
Select_Control::bind_to( 'tag' ) |
| 53 |
->set_label( esc_html__( 'Tag', 'elementor' ) ) |
| 54 |
->set_options( [ |
| 55 |
[ |
| 56 |
'value' => 'h1', |
| 57 |
'label' => 'H1', |
| 58 |
], |
| 59 |
[ |
| 60 |
'value' => 'h2', |
| 61 |
'label' => 'H2', |
| 62 |
], |
| 63 |
[ |
| 64 |
'value' => 'h3', |
| 65 |
'label' => 'H3', |
| 66 |
], |
| 67 |
[ |
| 68 |
'value' => 'h4', |
| 69 |
'label' => 'H4', |
| 70 |
], |
| 71 |
[ |
| 72 |
'value' => 'h5', |
| 73 |
'label' => 'H5', |
| 74 |
], |
| 75 |
[ |
| 76 |
'value' => 'h6', |
| 77 |
'label' => 'H6', |
| 78 |
], |
| 79 |
]), |
| 80 |
|
| 81 |
Textarea_Control::bind_to( 'title' ) |
| 82 |
->set_label( __( 'Title', 'elementor' ) ) |
| 83 |
->set_placeholder( __( 'Type your title here', 'elementor' ) ), |
| 84 |
]), |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
protected static function define_props_schema(): array { |
| 89 |
return [ |
| 90 |
'classes' => Classes_Prop_Type::make() |
| 91 |
->default( [] ), |
| 92 |
|
| 93 |
'tag' => String_Prop_Type::make() |
| 94 |
->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] ) |
| 95 |
->default( 'h2' ), |
| 96 |
|
| 97 |
'title' => String_Prop_Type::make() |
| 98 |
->default( __( 'Your Title Here', 'elementor' ) ), |
| 99 |
]; |
| 100 |
} |
| 101 |
} |
| 102 |
|