← All changes
|
modules/atomic-widgets/elements/atomic-heading/atomic-heading.php
+17
-71
4.3.0
→
3.31.4
View file →
| @@ -1,24 +1,20 @@ | ||
| 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 | -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; | |
| 7 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Textarea_Control; | |
| 8 | +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base; | |
| 9 | +use Elementor\Modules\AtomicWidgets\Elements\Has_Template; | |
| 13 | 10 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 14 | -use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type; | |
| 11 | +use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Array_Prop_Type; | |
| 15 | 12 | use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 16 | 13 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 17 | 14 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 18 | 15 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 19 | 16 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 20 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 21 | 17 | |
| 22 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | 19 | exit; // Exit if accessed directly. |
| 24 | 20 | } |
| @@ -27,10 +23,8 @@ | ||
| 27 | 23 | use Has_Template; |
| 28 | 24 | |
| 29 | 25 | const LINK_BASE_STYLE_KEY = 'link-base'; |
| 30 | 26 | |
| 31 | - public static $widget_description = 'Display a heading with customizable tag, styles, and link options.'; | |
| 32 | - | |
| 33 | 27 | public static function get_element_type(): string { |
| 34 | 28 | return 'e-heading'; |
| 35 | 29 | } |
| 36 | 30 | |
| @@ -38,9 +32,9 @@ | ||
| 38 | 32 | return esc_html__( 'Heading', 'elementor' ); |
| 39 | 33 | } |
| 40 | 34 | |
| 41 | 35 | public function get_keywords() { |
| 42 | - return [ 'ato', 'atom', 'atoms', 'atomic', 'heading', 'title', 'text', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]; | |
| 36 | + return [ 'ato', 'atom', 'atoms', 'atomic' ]; | |
| 43 | 37 | } |
| 44 | 38 | |
| 45 | 39 | public function get_icon() { |
| 46 | 40 | return 'eicon-e-heading'; |
| @@ -45,55 +39,39 @@ | ||
| 45 | 39 | public function get_icon() { |
| 46 | 40 | return 'eicon-e-heading'; |
| 47 | 41 | } |
| 48 | 42 | |
| 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 | 43 | protected static function define_props_schema(): array { |
| 60 | - return [ | |
| 44 | + $props = [ | |
| 61 | 45 | 'classes' => Classes_Prop_Type::make() |
| 62 | 46 | ->default( [] ), |
| 63 | 47 | |
| 64 | 48 | 'tag' => String_Prop_Type::make() |
| 65 | 49 | ->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.' ), | |
| 50 | + ->default( 'h2' ), | |
| 68 | 51 | |
| 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' ), | |
| 52 | + 'title' => String_Prop_Type::make() | |
| 53 | + ->default( __( 'This is a title', 'elementor' ) ), | |
| 73 | 54 | |
| 74 | 55 | 'link' => Link_Prop_Type::make(), |
| 75 | 56 | |
| 76 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 57 | + 'attributes' => Key_Value_Array_Prop_Type::make(), | |
| 77 | 58 | ]; |
| 59 | + | |
| 60 | + return $props; | |
| 78 | 61 | } |
| 79 | 62 | |
| 80 | 63 | protected function define_atomic_controls(): array { |
| 81 | 64 | $content_section = Section::make() |
| 82 | 65 | ->set_label( __( 'Content', 'elementor' ) ) |
| 83 | - ->set_id( 'content' ) | |
| 84 | 66 | ->set_items( [ |
| 85 | - Inline_Editing_Control::bind_to( 'title' ) | |
| 86 | - ->set_placeholder( __( 'Type your title here', 'elementor' ) ) | |
| 87 | - ->set_label( __( 'Title', 'elementor' ) ), | |
| 67 | + Textarea_Control::bind_to( 'title' ) | |
| 68 | + ->set_label( __( 'Title', 'elementor' ) ) | |
| 69 | + ->set_placeholder( __( 'Type your title here', 'elementor' ) ), | |
| 88 | 70 | ] ); |
| 89 | 71 | |
| 90 | 72 | return [ |
| 91 | 73 | $content_section, |
| 92 | - Section::make() | |
| 93 | - ->set_label( __( 'Settings', 'elementor' ) ) | |
| 94 | - ->set_id( 'settings' ) | |
| 95 | - ->set_items( $this->get_settings_controls() ), | |
| 96 | 74 | ]; |
| 97 | 75 | } |
| 98 | 76 | |
| 99 | 77 | protected function get_settings_controls(): array { |
| @@ -98,8 +76,9 @@ | ||
| 98 | 76 | |
| 99 | 77 | protected function get_settings_controls(): array { |
| 100 | 78 | return [ |
| 101 | 79 | Select_Control::bind_to( 'tag' ) |
| 80 | + ->set_label( esc_html__( 'Tag', 'elementor' ) ) | |
| 102 | 81 | ->set_options([ |
| 103 | 82 | [ |
| 104 | 83 | 'value' => 'h1', |
| 105 | 84 | 'label' => 'H1', |
| @@ -123,19 +102,14 @@ | ||
| 123 | 102 | [ |
| 124 | 103 | 'value' => 'h6', |
| 125 | 104 | 'label' => 'H6', |
| 126 | 105 | ], |
| 127 | - ]) | |
| 128 | - ->set_label( __( 'Tag', 'elementor' ) ), | |
| 106 | + ]), | |
| 129 | 107 | Link_Control::bind_to( 'link' ) |
| 130 | - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) | |
| 131 | 108 | ->set_label( __( 'Link', 'elementor' ) ) |
| 132 | 109 | ->set_meta( [ |
| 133 | 110 | 'topDivider' => true, |
| 134 | 111 | ] ), |
| 135 | - Text_Control::bind_to( '_cssid' ) | |
| 136 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 137 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 138 | 112 | ]; |
| 139 | 113 | } |
| 140 | 114 | |
| 141 | 115 | protected function define_base_styles(): array { |
| @@ -162,34 +136,6 @@ | ||
| 162 | 136 | protected function get_templates(): array { |
| 163 | 137 | return [ |
| 164 | 138 | 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 165 | 139 | ]; |
| 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 | 140 | } |
| 195 | 141 | } |