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