| 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\Color_Prop_Type; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 15 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 16 |
use Elementor\Plugin; |
| 17 |
use Elementor\Utils; |
| 18 |
|
| 19 |
if ( ! defined( 'ABSPATH' ) ) { |
| 20 |
exit; // Exit if accessed directly. |
| 21 |
} |
| 22 |
|
| 23 |
class Div_Block extends Atomic_Element_Base { |
| 24 |
const BASE_STYLE_KEY = 'base'; |
| 25 |
|
| 26 |
public static function get_type() { |
| 27 |
return 'e-div-block'; |
| 28 |
} |
| 29 |
|
| 30 |
public static function get_element_type(): string { |
| 31 |
return 'e-div-block'; |
| 32 |
} |
| 33 |
|
| 34 |
public function get_title() { |
| 35 |
return esc_html__( 'Div Block', 'elementor' ); |
| 36 |
} |
| 37 |
|
| 38 |
public function get_keywords() { |
| 39 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 40 |
} |
| 41 |
|
| 42 |
public function get_icon() { |
| 43 |
return 'eicon-div-block'; |
| 44 |
} |
| 45 |
|
| 46 |
protected static function define_props_schema(): array { |
| 47 |
return [ |
| 48 |
'classes' => Classes_Prop_Type::make() |
| 49 |
->default( [] ), |
| 50 |
|
| 51 |
'tag' => String_Prop_Type::make() |
| 52 |
->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] ) |
| 53 |
->default( 'div' ), |
| 54 |
|
| 55 |
'link' => Link_Prop_Type::make(), |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
protected function define_atomic_controls(): array { |
| 60 |
return [ |
| 61 |
Section::make() |
| 62 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 63 |
->set_items( [ |
| 64 |
Select_Control::bind_to( 'tag' ) |
| 65 |
->set_label( esc_html__( 'HTML Tag', 'elementor' ) ) |
| 66 |
->set_options( [ |
| 67 |
[ |
| 68 |
'value' => 'div', |
| 69 |
'label' => 'Div', |
| 70 |
], |
| 71 |
[ |
| 72 |
'value' => 'header', |
| 73 |
'label' => 'Header', |
| 74 |
], |
| 75 |
[ |
| 76 |
'value' => 'section', |
| 77 |
'label' => 'Section', |
| 78 |
], |
| 79 |
[ |
| 80 |
'value' => 'article', |
| 81 |
'label' => 'Article', |
| 82 |
], |
| 83 |
[ |
| 84 |
'value' => 'aside', |
| 85 |
'label' => 'Aside', |
| 86 |
], |
| 87 |
[ |
| 88 |
'value' => 'footer', |
| 89 |
'label' => 'Footer', |
| 90 |
], |
| 91 |
]), |
| 92 |
|
| 93 |
Link_Control::bind_to( 'link' ), |
| 94 |
|
| 95 |
]), |
| 96 |
]; |
| 97 |
} |
| 98 |
|
| 99 |
protected function _get_default_child_type( array $element_data ) { |
| 100 |
$el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() ); |
| 101 |
|
| 102 |
if ( in_array( $element_data['elType'], $el_types, true ) ) { |
| 103 |
return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] ); |
| 104 |
} |
| 105 |
|
| 106 |
return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); |
| 107 |
} |
| 108 |
|
| 109 |
protected function content_template() { |
| 110 |
?> |
| 111 |
<?php |
| 112 |
} |
| 113 |
|
| 114 |
protected function add_render_attributes() { |
| 115 |
parent::add_render_attributes(); |
| 116 |
$settings = $this->get_atomic_settings(); |
| 117 |
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ]; |
| 118 |
|
| 119 |
$attributes = [ |
| 120 |
'class' => [ |
| 121 |
'e-con', |
| 122 |
$base_style_class, |
| 123 |
...( $settings['classes'] ?? [] ), |
| 124 |
], |
| 125 |
]; |
| 126 |
|
| 127 |
if ( ! empty( $settings['link']['href'] ) ) { |
| 128 |
$attributes = array_merge( $attributes, $settings['link'] ); |
| 129 |
} |
| 130 |
|
| 131 |
$this->add_render_attribute( '_wrapper', $attributes ); |
| 132 |
} |
| 133 |
|
| 134 |
public function before_render() { |
| 135 |
?> |
| 136 |
<<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>> |
| 137 |
<?php |
| 138 |
} |
| 139 |
|
| 140 |
public function after_render() { |
| 141 |
?> |
| 142 |
</<?php $this->print_html_tag(); ?>> |
| 143 |
<?php |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Print safe HTML tag for the element based on the element settings. |
| 148 |
* |
| 149 |
* @return void |
| 150 |
*/ |
| 151 |
protected function print_html_tag() { |
| 152 |
$html_tag = $this->get_html_tag(); |
| 153 |
Utils::print_validated_html_tag( $html_tag ); |
| 154 |
} |
| 155 |
|
| 156 |
protected function get_html_tag(): string { |
| 157 |
$settings = $this->get_atomic_settings(); |
| 158 |
|
| 159 |
return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' ); |
| 160 |
} |
| 161 |
|
| 162 |
protected function define_base_styles(): array { |
| 163 |
$display = String_Prop_Type::generate( 'block' ); |
| 164 |
|
| 165 |
return [ |
| 166 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 167 |
->add_variant( |
| 168 |
Style_Variant::make() |
| 169 |
->add_prop( 'display', $display ) |
| 170 |
->add_prop( 'padding', $this->get_base_padding() ) |
| 171 |
->add_prop( 'min-width', $this->get_base_min_width() ) |
| 172 |
), |
| 173 |
]; |
| 174 |
} |
| 175 |
|
| 176 |
protected function get_base_padding(): array { |
| 177 |
return Size_Prop_Type::generate( [ |
| 178 |
'size' => 10, |
| 179 |
'unit' => 'px', |
| 180 |
] ); |
| 181 |
} |
| 182 |
|
| 183 |
protected function get_base_min_width(): array { |
| 184 |
return Size_Prop_Type::generate( [ |
| 185 |
'size' => 30, |
| 186 |
'unit' => 'px', |
| 187 |
] ); |
| 188 |
} |
| 189 |
} |
| 190 |
|