← All changes
|
modules/atomic-widgets/elements/div-block/div-block.php
+113
-98
4.2.0-beta2
→
3.30.1
View file →
| @@ -1,22 +1,23 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\AtomicWidgets\Elements\Div_Block; |
| 3 | 3 | |
| 4 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; | |
| 5 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; | |
| 4 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; | |
| 5 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; | |
| 6 | +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base; | |
| 7 | +use Elementor\Modules\AtomicWidgets\Controls\Section; | |
| 8 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; | |
| 9 | +use Elementor\Modules\AtomicWidgets\Module; | |
| 10 | +use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; | |
| 11 | +use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; | |
| 12 | +use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type; | |
| 13 | +use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; | |
| 6 | 14 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 7 | 15 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 8 | 16 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 9 | -use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; | |
| 10 | 17 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 11 | -use Elementor\Modules\AtomicWidgets\Controls\Section; | |
| 12 | -use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; | |
| 13 | -use Elementor\Modules\AtomicWidgets\Controls\Types\Html_Tag_Control; | |
| 14 | -use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; | |
| 15 | -use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; | |
| 16 | -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; | |
| 17 | -use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; | |
| 18 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 18 | +use Elementor\Plugin; | |
| 19 | +use Elementor\Utils; | |
| 19 | 20 | |
| 20 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | 22 | exit; // Exit if accessed directly. |
| 22 | 23 | } |
| @@ -21,17 +22,10 @@ | ||
| 21 | 22 | exit; // Exit if accessed directly. |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | class Div_Block extends Atomic_Element_Base { |
| 25 | - use Has_Element_Template; | |
| 26 | - | |
| 27 | 26 | const BASE_STYLE_KEY = 'base'; |
| 28 | 27 | |
| 29 | - public function __construct( $data = [], $args = null ) { | |
| 30 | - parent::__construct( $data, $args ); | |
| 31 | - $this->meta( 'is_container', true ); | |
| 32 | - } | |
| 33 | - | |
| 34 | 28 | public static function get_type() { |
| 35 | 29 | return 'e-div-block'; |
| 36 | 30 | } |
| 37 | 31 | |
| @@ -39,13 +33,13 @@ | ||
| 39 | 33 | return 'e-div-block'; |
| 40 | 34 | } |
| 41 | 35 | |
| 42 | 36 | public function get_title() { |
| 43 | - return esc_html__( 'Div block', 'elementor' ); | |
| 37 | + return esc_html__( 'Div Block', 'elementor' ); | |
| 44 | 38 | } |
| 45 | 39 | |
| 46 | 40 | public function get_keywords() { |
| 47 | - return [ 'ato', 'atom', 'atoms', 'atomic', 'layout' ]; | |
| 41 | + return [ 'ato', 'atom', 'atoms', 'atomic' ]; | |
| 48 | 42 | } |
| 49 | 43 | |
| 50 | 44 | public function get_icon() { |
| 51 | 45 | return 'eicon-div-block'; |
| @@ -51,89 +45,119 @@ | ||
| 51 | 45 | return 'eicon-div-block'; |
| 52 | 46 | } |
| 53 | 47 | |
| 54 | 48 | protected static function define_props_schema(): array { |
| 55 | - $tag_dependencies = Dependency_Manager::make( Dependency_Manager::RELATION_AND ) | |
| 56 | - ->where( [ | |
| 57 | - 'operator' => 'ne', | |
| 58 | - 'path' => [ 'link', 'destination' ], | |
| 59 | - 'nestedPath' => [ 'group' ], | |
| 60 | - 'value' => 'action', | |
| 61 | - 'newValue' => [ | |
| 62 | - '$$type' => 'string', | |
| 63 | - 'value' => 'button', | |
| 64 | - ], | |
| 65 | - ] )->where( [ | |
| 66 | - 'operator' => 'not_exist', | |
| 67 | - 'path' => [ 'link', 'destination' ], | |
| 68 | - 'newValue' => [ | |
| 69 | - '$$type' => 'string', | |
| 70 | - 'value' => 'a', | |
| 71 | - ], | |
| 72 | - ] )->get(); | |
| 73 | - | |
| 74 | - return [ | |
| 49 | + $props = [ | |
| 75 | 50 | 'classes' => Classes_Prop_Type::make() |
| 76 | 51 | ->default( [] ), |
| 52 | + | |
| 77 | 53 | 'tag' => String_Prop_Type::make() |
| 78 | - ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button' ] ) | |
| 79 | - ->default( 'div' ) | |
| 80 | - ->set_dependencies( $tag_dependencies ), | |
| 54 | + ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] ) | |
| 55 | + ->default( 'div' ), | |
| 56 | + | |
| 81 | 57 | 'link' => Link_Prop_Type::make(), |
| 82 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 83 | 58 | ]; |
| 59 | + | |
| 60 | + if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) { | |
| 61 | + $props['_cssid'] = String_Prop_Type::make(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + return $props; | |
| 84 | 65 | } |
| 85 | 66 | |
| 86 | 67 | protected function define_atomic_controls(): array { |
| 68 | + $settings_section_items = [ | |
| 69 | + Select_Control::bind_to( 'tag' ) | |
| 70 | + ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ) | |
| 71 | + ->set_options( [ | |
| 72 | + [ | |
| 73 | + 'value' => 'div', | |
| 74 | + 'label' => 'Div', | |
| 75 | + ], | |
| 76 | + [ | |
| 77 | + 'value' => 'header', | |
| 78 | + 'label' => 'Header', | |
| 79 | + ], | |
| 80 | + [ | |
| 81 | + 'value' => 'section', | |
| 82 | + 'label' => 'Section', | |
| 83 | + ], | |
| 84 | + [ | |
| 85 | + 'value' => 'article', | |
| 86 | + 'label' => 'Article', | |
| 87 | + ], | |
| 88 | + [ | |
| 89 | + 'value' => 'aside', | |
| 90 | + 'label' => 'Aside', | |
| 91 | + ], | |
| 92 | + [ | |
| 93 | + 'value' => 'footer', | |
| 94 | + 'label' => 'Footer', | |
| 95 | + ], | |
| 96 | + ]), | |
| 97 | + | |
| 98 | + Link_Control::bind_to( 'link' )->set_meta( [ | |
| 99 | + 'topDivider' => true, | |
| 100 | + ] ), | |
| 101 | + ]; | |
| 102 | + | |
| 103 | + if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) { | |
| 104 | + $settings_section_items[] = Text_Control::bind_to( '_cssid' )->set_label( __( 'ID', 'elementor' ) )->set_meta( [ | |
| 105 | + 'layout' => 'two-columns', | |
| 106 | + 'topDivider' => true, | |
| 107 | + ] ); | |
| 108 | + } | |
| 109 | + | |
| 87 | 110 | return [ |
| 88 | 111 | Section::make() |
| 89 | 112 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 90 | - ->set_id( 'settings' ) | |
| 91 | - ->set_items( [ | |
| 92 | - Html_Tag_Control::bind_to( 'tag' ) | |
| 93 | - ->set_options( [ | |
| 94 | - [ | |
| 95 | - 'value' => 'div', | |
| 96 | - 'label' => 'Div', | |
| 97 | - ], | |
| 98 | - [ | |
| 99 | - 'value' => 'header', | |
| 100 | - 'label' => 'Header', | |
| 101 | - ], | |
| 102 | - [ | |
| 103 | - 'value' => 'section', | |
| 104 | - 'label' => 'Section', | |
| 105 | - ], | |
| 106 | - [ | |
| 107 | - 'value' => 'article', | |
| 108 | - 'label' => 'Article', | |
| 109 | - ], | |
| 110 | - [ | |
| 111 | - 'value' => 'aside', | |
| 112 | - 'label' => 'Aside', | |
| 113 | - ], | |
| 114 | - [ | |
| 115 | - 'value' => 'footer', | |
| 116 | - 'label' => 'Footer', | |
| 117 | - ], | |
| 118 | - ]) | |
| 119 | - ->set_fallback_labels( [ | |
| 120 | - 'a' => 'a (link)', | |
| 121 | - ] ) | |
| 122 | - ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ), | |
| 123 | - Link_Control::bind_to( 'link' ) | |
| 124 | - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) | |
| 125 | - ->set_label( __( 'Link', 'elementor' ) ) | |
| 126 | - ->set_meta( [ | |
| 127 | - 'topDivider' => true, | |
| 128 | - ] ), | |
| 129 | - Text_Control::bind_to( '_cssid' ) | |
| 130 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 131 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 132 | - ] ), | |
| 113 | + ->set_items( $settings_section_items ), | |
| 133 | 114 | ]; |
| 134 | 115 | } |
| 135 | 116 | |
| 117 | + protected function _get_default_child_type( array $element_data ) { | |
| 118 | + $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() ); | |
| 119 | + | |
| 120 | + if ( in_array( $element_data['elType'], $el_types, true ) ) { | |
| 121 | + return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] ); | |
| 122 | + } | |
| 123 | + | |
| 124 | + return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); | |
| 125 | + } | |
| 126 | + | |
| 127 | + protected function content_template() { | |
| 128 | + ?> | |
| 129 | + <?php | |
| 130 | + } | |
| 131 | + | |
| 132 | + public function before_render() { | |
| 133 | + ?> | |
| 134 | + <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>> | |
| 135 | + <?php | |
| 136 | + } | |
| 137 | + | |
| 138 | + public function after_render() { | |
| 139 | + ?> | |
| 140 | + </<?php $this->print_html_tag(); ?>> | |
| 141 | + <?php | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Print safe HTML tag for the element based on the element settings. | |
| 146 | + * | |
| 147 | + * @return void | |
| 148 | + */ | |
| 149 | + protected function print_html_tag() { | |
| 150 | + $html_tag = $this->get_html_tag(); | |
| 151 | + Utils::print_validated_html_tag( $html_tag ); | |
| 152 | + } | |
| 153 | + | |
| 154 | + protected function get_html_tag(): string { | |
| 155 | + $settings = $this->get_atomic_settings(); | |
| 156 | + | |
| 157 | + return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' ); | |
| 158 | + } | |
| 159 | + | |
| 136 | 160 | protected function define_base_styles(): array { |
| 137 | 161 | $display = String_Prop_Type::generate( 'block' ); |
| 138 | 162 | |
| 139 | 163 | return [ |
| @@ -164,14 +188,12 @@ | ||
| 164 | 188 | protected function add_render_attributes() { |
| 165 | 189 | parent::add_render_attributes(); |
| 166 | 190 | $settings = $this->get_atomic_settings(); |
| 167 | 191 | $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ]; |
| 168 | - $initial_attributes = $this->define_initial_attributes(); | |
| 169 | 192 | |
| 170 | 193 | $attributes = [ |
| 171 | 194 | 'class' => [ |
| 172 | 195 | 'e-con', |
| 173 | - 'e-atomic-element', | |
| 174 | 196 | $base_style_class, |
| 175 | 197 | ...( $settings['classes'] ?? [] ), |
| 176 | 198 | ], |
| 177 | 199 | ]; |
| @@ -180,17 +202,10 @@ | ||
| 180 | 202 | $attributes['id'] = esc_attr( $settings['_cssid'] ); |
| 181 | 203 | } |
| 182 | 204 | |
| 183 | 205 | if ( ! empty( $settings['link']['href'] ) ) { |
| 184 | - $link_attributes = $this->get_link_attributes( $settings['link'] ); | |
| 185 | - $attributes = array_merge( $attributes, $link_attributes ); | |
| 206 | + $attributes = array_merge( $attributes, $settings['link'] ); | |
| 186 | 207 | } |
| 187 | 208 | |
| 188 | - $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) ); | |
| 189 | - } | |
| 190 | - | |
| 191 | - protected function get_templates(): array { | |
| 192 | - return [ | |
| 193 | - 'elementor/elements/div-block' => __DIR__ . '/div-block.html.twig', | |
| 194 | - ]; | |
| 209 | + $this->add_render_attribute( '_wrapper', $attributes ); | |
| 195 | 210 | } |
| 196 | 211 | } |