| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Base\Atomic_Element_Base; |
| 5 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 9 |
use Elementor\Plugin; |
| 10 |
use Elementor\Utils; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Div_Block extends Atomic_Element_Base { |
| 17 |
public static function get_type() { |
| 18 |
return 'div-block'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_name() { |
| 22 |
return 'div-block'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_title() { |
| 26 |
return esc_html__( 'Div Block', 'elementor' ); |
| 27 |
} |
| 28 |
|
| 29 |
public function get_icon() { |
| 30 |
return 'eicon-div-block'; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_style_depends() { |
| 34 |
return [ 'div-block' ]; |
| 35 |
} |
| 36 |
|
| 37 |
protected function define_atomic_controls(): array { |
| 38 |
return [ |
| 39 |
Section::make() |
| 40 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 41 |
->set_items( [ |
| 42 |
Select_Control::bind_to( 'tag' ) |
| 43 |
->set_label( esc_html__( 'HTML Tag', 'elementor' ) ) |
| 44 |
->set_options( [ |
| 45 |
[ |
| 46 |
'value' => 'div', |
| 47 |
'label' => 'Div', |
| 48 |
], |
| 49 |
[ |
| 50 |
'value' => 'header', |
| 51 |
'label' => 'Header', |
| 52 |
], |
| 53 |
[ |
| 54 |
'value' => 'section', |
| 55 |
'label' => 'Section', |
| 56 |
], |
| 57 |
[ |
| 58 |
'value' => 'article', |
| 59 |
'label' => 'Article', |
| 60 |
], |
| 61 |
[ |
| 62 |
'value' => 'aside', |
| 63 |
'label' => 'Aside', |
| 64 |
], |
| 65 |
[ |
| 66 |
'value' => 'footer', |
| 67 |
'label' => 'Footer', |
| 68 |
], |
| 69 |
]), |
| 70 |
]), |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
protected static function define_props_schema(): array { |
| 75 |
return [ |
| 76 |
'classes' => Classes_Prop_Type::make() |
| 77 |
->default( [] ), |
| 78 |
|
| 79 |
'tag' => String_Prop_Type::make() |
| 80 |
->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] ) |
| 81 |
->default( 'div' ), |
| 82 |
]; |
| 83 |
} |
| 84 |
|
| 85 |
protected function _get_default_child_type( array $element_data ) { |
| 86 |
if ( 'div-block' === $element_data['elType'] ) { |
| 87 |
return Plugin::$instance->elements_manager->get_element_types( 'div-block' ); |
| 88 |
} |
| 89 |
|
| 90 |
return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); |
| 91 |
} |
| 92 |
|
| 93 |
protected function content_template() { |
| 94 |
?> |
| 95 |
<?php |
| 96 |
} |
| 97 |
|
| 98 |
protected function add_render_attributes() { |
| 99 |
parent::add_render_attributes(); |
| 100 |
$settings = $this->get_atomic_settings(); |
| 101 |
|
| 102 |
$this->add_render_attribute( '_wrapper', [ |
| 103 |
'class' => [ |
| 104 |
'e-div-block', |
| 105 |
$settings['classes'] ?? '', |
| 106 |
], |
| 107 |
] ); |
| 108 |
} |
| 109 |
|
| 110 |
public function before_render() { |
| 111 |
?> |
| 112 |
<<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>> |
| 113 |
<?php |
| 114 |
} |
| 115 |
|
| 116 |
public function after_render() { |
| 117 |
?> |
| 118 |
</<?php $this->print_html_tag(); ?>> |
| 119 |
<?php |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Print safe HTML tag for the element based on the element settings. |
| 124 |
* |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
protected function print_html_tag() { |
| 128 |
$html_tag = $this->get_atomic_settings()['tag'] ?? 'div'; |
| 129 |
Utils::print_validated_html_tag( $html_tag ); |
| 130 |
} |
| 131 |
} |
| 132 |
|