← All changes
|
modules/atomic-widgets/elements/atomic-heading/atomic-heading.php
+42
-84
4.3.0-beta3
→
3.30.1
View file →
| @@ -1,24 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Heading; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 5 | -use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control; | |
| 6 | 5 | use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; |
| 7 | 6 | use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; |
| 8 | 7 | use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 9 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base; | |
| 10 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template; | |
| 11 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer; | |
| 12 | -use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; | |
| 8 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Textarea_Control; | |
| 9 | +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base; | |
| 10 | +use Elementor\Modules\AtomicWidgets\Elements\Has_Template; | |
| 11 | +use Elementor\Modules\AtomicWidgets\Module; | |
| 13 | 12 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 14 | -use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type; | |
| 15 | 13 | use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 16 | 14 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 17 | 15 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 18 | 16 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 19 | 17 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 20 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 18 | +use Elementor\Plugin; | |
| 21 | 19 | |
| 22 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | 21 | exit; // Exit if accessed directly. |
| 24 | 22 | } |
| @@ -27,10 +25,8 @@ | ||
| 27 | 25 | use Has_Template; |
| 28 | 26 | |
| 29 | 27 | const LINK_BASE_STYLE_KEY = 'link-base'; |
| 30 | 28 | |
| 31 | - public static $widget_description = 'Display a heading with customizable tag, styles, and link options.'; | |
| 32 | - | |
| 33 | 29 | public static function get_element_type(): string { |
| 34 | 30 | return 'e-heading'; |
| 35 | 31 | } |
| 36 | 32 | |
| @@ -38,9 +34,9 @@ | ||
| 38 | 34 | return esc_html__( 'Heading', 'elementor' ); |
| 39 | 35 | } |
| 40 | 36 | |
| 41 | 37 | public function get_keywords() { |
| 42 | - return [ 'ato', 'atom', 'atoms', 'atomic', 'heading', 'title', 'text', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]; | |
| 38 | + return [ 'ato', 'atom', 'atoms', 'atomic' ]; | |
| 43 | 39 | } |
| 44 | 40 | |
| 45 | 41 | public function get_icon() { |
| 46 | 42 | return 'eicon-e-heading'; |
| @@ -45,62 +41,43 @@ | ||
| 45 | 41 | public function get_icon() { |
| 46 | 42 | return 'eicon-e-heading'; |
| 47 | 43 | } |
| 48 | 44 | |
| 49 | - public static function html_tag_follows_link(): bool { | |
| 50 | - return false; | |
| 51 | - } | |
| 52 | - | |
| 53 | - public static function get_computed_html_tag( array $settings ): string { | |
| 54 | - return Html_Tag_Computer::compute( $settings, 'h2', [ | |
| 55 | - Html_Tag_Computer::FOLLOW_LINK_OPTION => static::html_tag_follows_link(), | |
| 56 | - ] ); | |
| 57 | - } | |
| 58 | - | |
| 59 | 45 | protected static function define_props_schema(): array { |
| 60 | - return [ | |
| 46 | + $props = [ | |
| 61 | 47 | 'classes' => Classes_Prop_Type::make() |
| 62 | 48 | ->default( [] ), |
| 63 | 49 | |
| 64 | 50 | 'tag' => String_Prop_Type::make() |
| 65 | 51 | ->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] ) |
| 66 | - ->default( 'h2' ) | |
| 67 | - ->description( 'The HTML tag for the heading element. One of: h1, h2, h3, h4, h5, or h6. Do not use p, span, or div.' ), | |
| 52 | + ->default( 'h2' ), | |
| 68 | 53 | |
| 69 | - 'title' => Escaped_Html_Prop_Type::make() | |
| 70 | - ->default( __( 'This is a title', 'elementor' ) ) | |
| 71 | - ->description( 'The text content of the heading.' ) | |
| 72 | - ->alias( 'text', 'content', 'heading' ), | |
| 54 | + 'title' => String_Prop_Type::make() | |
| 55 | + ->default( __( 'This is a title', 'elementor' ) ), | |
| 73 | 56 | |
| 74 | 57 | 'link' => Link_Prop_Type::make(), |
| 58 | + ]; | |
| 75 | 59 | |
| 76 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 77 | - ]; | |
| 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; | |
| 78 | 65 | } |
| 79 | 66 | |
| 80 | 67 | protected function define_atomic_controls(): array { |
| 81 | 68 | $content_section = Section::make() |
| 82 | 69 | ->set_label( __( 'Content', 'elementor' ) ) |
| 83 | - ->set_id( 'content' ) | |
| 84 | 70 | ->set_items( [ |
| 85 | - Inline_Editing_Control::bind_to( 'title' ) | |
| 86 | - ->set_placeholder( __( 'Type your title here', 'elementor' ) ) | |
| 87 | - ->set_label( __( 'Title', 'elementor' ) ), | |
| 71 | + Textarea_Control::bind_to( 'title' ) | |
| 72 | + ->set_label( __( 'Title', 'elementor' ) ) | |
| 73 | + ->set_placeholder( __( 'Type your title here', 'elementor' ) ), | |
| 88 | 74 | ] ); |
| 89 | 75 | |
| 90 | - return [ | |
| 91 | - $content_section, | |
| 92 | - Section::make() | |
| 93 | - ->set_label( __( 'Settings', 'elementor' ) ) | |
| 94 | - ->set_id( 'settings' ) | |
| 95 | - ->set_items( $this->get_settings_controls() ), | |
| 96 | - ]; | |
| 97 | - } | |
| 98 | - | |
| 99 | - protected function get_settings_controls(): array { | |
| 100 | - return [ | |
| 76 | + $settings_section_items = [ | |
| 101 | 77 | Select_Control::bind_to( 'tag' ) |
| 102 | - ->set_options([ | |
| 78 | + ->set_label( esc_html__( 'Tag', 'elementor' ) ) | |
| 79 | + ->set_options( [ | |
| 103 | 80 | [ |
| 104 | 81 | 'value' => 'h1', |
| 105 | 82 | 'label' => 'H1', |
| 106 | 83 | ], |
| @@ -123,20 +100,29 @@ | ||
| 123 | 100 | [ |
| 124 | 101 | 'value' => 'h6', |
| 125 | 102 | 'label' => 'H6', |
| 126 | 103 | ], |
| 127 | - ]) | |
| 128 | - ->set_label( __( 'Tag', 'elementor' ) ), | |
| 129 | - Link_Control::bind_to( 'link' ) | |
| 130 | - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) | |
| 131 | - ->set_label( __( 'Link', 'elementor' ) ) | |
| 132 | - ->set_meta( [ | |
| 133 | - 'topDivider' => true, | |
| 134 | - ] ), | |
| 135 | - Text_Control::bind_to( '_cssid' ) | |
| 136 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 137 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 104 | + ]), | |
| 105 | + Link_Control::bind_to( 'link' )->set_meta( [ | |
| 106 | + 'topDivider' => true, | |
| 107 | + ] ), | |
| 138 | 108 | ]; |
| 109 | + | |
| 110 | + if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) { | |
| 111 | + $settings_section_items[] = Text_Control::bind_to( '_cssid' )->set_label( __( 'ID', 'elementor' ) )->set_meta( [ | |
| 112 | + 'layout' => 'two-columns', | |
| 113 | + 'topDivider' => true, | |
| 114 | + ] ); | |
| 115 | + } | |
| 116 | + | |
| 117 | + $settings_section = Section::make() | |
| 118 | + ->set_label( __( 'Settings', 'elementor' ) ) | |
| 119 | + ->set_items( $settings_section_items ); | |
| 120 | + | |
| 121 | + return [ | |
| 122 | + $content_section, | |
| 123 | + $settings_section, | |
| 124 | + ]; | |
| 139 | 125 | } |
| 140 | 126 | |
| 141 | 127 | protected function define_base_styles(): array { |
| 142 | 128 | $margin_value = Size_Prop_Type::generate( [ |
| @@ -162,34 +148,6 @@ | ||
| 162 | 148 | protected function get_templates(): array { |
| 163 | 149 | return [ |
| 164 | 150 | 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 165 | 151 | ]; |
| 166 | - } | |
| 167 | - | |
| 168 | - public function render_markdown(): string { | |
| 169 | - $settings = $this->get_atomic_settings(); | |
| 170 | - $title = wp_strip_all_tags( $settings['title'] ?? '' ); | |
| 171 | - | |
| 172 | - if ( empty( $title ) ) { | |
| 173 | - return ''; | |
| 174 | - } | |
| 175 | - | |
| 176 | - $tag = $settings['tag'] ?? 'h2'; | |
| 177 | - $level_map = [ | |
| 178 | - 'h1' => 1, | |
| 179 | - 'h2' => 2, | |
| 180 | - 'h3' => 3, | |
| 181 | - 'h4' => 4, | |
| 182 | - 'h5' => 5, | |
| 183 | - 'h6' => 6, | |
| 184 | - ]; | |
| 185 | - $level = $level_map[ $tag ] ?? 2; | |
| 186 | - | |
| 187 | - $md = str_repeat( '#', $level ) . ' ' . $title; | |
| 188 | - | |
| 189 | - if ( ! empty( $settings['link']['href'] ) ) { | |
| 190 | - $md = str_repeat( '#', $level ) . ' [' . $title . '](' . esc_url( $settings['link']['href'] ) . ')'; | |
| 191 | - } | |
| 192 | - | |
| 193 | - return $md; | |
| 194 | 152 | } |
| 195 | 153 | } |