| 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\Schema\Atomic_Prop; |
| 9 |
use Elementor\Utils; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
class Atomic_Heading extends Atomic_Widget_Base { |
| 16 |
public function get_icon() { |
| 17 |
return 'eicon-t-letter'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_title() { |
| 21 |
return esc_html__( 'Atomic Heading', 'elementor' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_name() { |
| 25 |
return 'a-heading'; |
| 26 |
} |
| 27 |
|
| 28 |
protected function render() { |
| 29 |
$settings = $this->get_atomic_settings(); |
| 30 |
|
| 31 |
// TODO: Move the validation/sanitization to the props schema constraints. |
| 32 |
$escaped_tag = Utils::validate_html_tag( $settings['tag'] ); |
| 33 |
$escaped_title = esc_html( $settings['title'] ); |
| 34 |
|
| 35 |
$class = ''; |
| 36 |
if ( ! empty( $settings['classes'] ) ) { |
| 37 |
$class = "class='" . esc_attr( $settings['classes'] ) . "'"; |
| 38 |
} |
| 39 |
|
| 40 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 41 |
echo "<$escaped_tag $class>$escaped_title</$escaped_tag>"; |
| 42 |
} |
| 43 |
|
| 44 |
protected function define_atomic_controls(): array { |
| 45 |
$tag_control = Select_Control::bind_to( 'tag' ) |
| 46 |
->set_label( esc_html__( 'Tag', 'elementor' ) ) |
| 47 |
->set_options( [ |
| 48 |
[ |
| 49 |
'value' => 'h1', |
| 50 |
'label' => 'H1', |
| 51 |
], |
| 52 |
[ |
| 53 |
'value' => 'h2', |
| 54 |
'label' => 'H2', |
| 55 |
], |
| 56 |
[ |
| 57 |
'value' => 'h3', |
| 58 |
'label' => 'H3', |
| 59 |
], |
| 60 |
[ |
| 61 |
'value' => 'h4', |
| 62 |
'label' => 'H4', |
| 63 |
], |
| 64 |
[ |
| 65 |
'value' => 'h5', |
| 66 |
'label' => 'H5', |
| 67 |
], |
| 68 |
[ |
| 69 |
'value' => 'h6', |
| 70 |
'label' => 'H6', |
| 71 |
], |
| 72 |
]); |
| 73 |
|
| 74 |
$title_control = Textarea_Control::bind_to( 'title' ) |
| 75 |
->set_label( __( 'Title', 'elementor' ) ) |
| 76 |
->set_placeholder( __( 'Type your title here', 'elementor' ) ); |
| 77 |
|
| 78 |
$tag_and_title_section = Section::make() |
| 79 |
->set_label( __( 'Content', 'elementor' ) ) |
| 80 |
->set_items( [ |
| 81 |
$tag_control, |
| 82 |
$title_control, |
| 83 |
]); |
| 84 |
|
| 85 |
return [ |
| 86 |
$tag_and_title_section, |
| 87 |
]; |
| 88 |
} |
| 89 |
|
| 90 |
protected static function define_props_schema(): array { |
| 91 |
return [ |
| 92 |
'classes' => Atomic_Prop::make(), |
| 93 |
|
| 94 |
'tag' => Atomic_Prop::make() |
| 95 |
->default( 'h2' ), |
| 96 |
|
| 97 |
'title' => Atomic_Prop::make() |
| 98 |
->default( __( 'Your Title Here', 'elementor' ) ), |
| 99 |
]; |
| 100 |
} |
| 101 |
} |
| 102 |
|