← All changes
|
modules/atomic-widgets/elements/atomic-heading/atomic-heading.php
+14
-50
4.1.2
→
3.32.0-dev3
View file →
| @@ -1,23 +1,21 @@ | ||
| 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; | |
| 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; | |
| 10 | +use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; | |
| 11 | 11 | use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 12 | -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; | |
| 13 | -use Elementor\Modules\AtomicWidgets\PropTypes\Html_V3_Prop_Type; | |
| 14 | 12 | use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 15 | 13 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 16 | 14 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 17 | 15 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 18 | 16 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 19 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 17 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; | |
| 20 | 18 | |
| 21 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 22 | 20 | exit; // Exit if accessed directly. |
| 23 | 21 | } |
| @@ -26,10 +24,8 @@ | ||
| 26 | 24 | use Has_Template; |
| 27 | 25 | |
| 28 | 26 | const LINK_BASE_STYLE_KEY = 'link-base'; |
| 29 | 27 | |
| 30 | - public static $widget_description = 'Display a heading with customizable tag, styles, and link options.'; | |
| 31 | - | |
| 32 | 28 | public static function get_element_type(): string { |
| 33 | 29 | return 'e-heading'; |
| 34 | 30 | } |
| 35 | 31 | |
| @@ -45,28 +41,25 @@ | ||
| 45 | 41 | return 'eicon-e-heading'; |
| 46 | 42 | } |
| 47 | 43 | |
| 48 | 44 | protected static function define_props_schema(): array { |
| 49 | - return [ | |
| 45 | + $props = [ | |
| 50 | 46 | 'classes' => Classes_Prop_Type::make() |
| 51 | 47 | ->default( [] ), |
| 52 | 48 | |
| 53 | 49 | 'tag' => String_Prop_Type::make() |
| 54 | 50 | ->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] ) |
| 55 | - ->default( 'h2' ) | |
| 56 | - ->description( 'The HTML tag for the heading element. Could be h1, h2, up to h6' ), | |
| 51 | + ->default( 'h2' ), | |
| 57 | 52 | |
| 58 | - 'title' => Html_V3_Prop_Type::make() | |
| 59 | - ->default( [ | |
| 60 | - 'content' => String_Prop_Type::generate( __( 'This is a title', 'elementor' ) ), | |
| 61 | - 'children' => [], | |
| 62 | - ] ) | |
| 63 | - ->description( 'The text content of the heading.' ), | |
| 53 | + 'title' => String_Prop_Type::make() | |
| 54 | + ->default( __( 'This is a title', 'elementor' ) ), | |
| 64 | 55 | |
| 65 | 56 | 'link' => Link_Prop_Type::make(), |
| 66 | 57 | |
| 67 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 58 | + 'attributes' => Attributes_Prop_Type::make(), | |
| 68 | 59 | ]; |
| 60 | + | |
| 61 | + return $props; | |
| 69 | 62 | } |
| 70 | 63 | |
| 71 | 64 | protected function define_atomic_controls(): array { |
| 72 | 65 | $content_section = Section::make() |
| @@ -71,10 +64,10 @@ | ||
| 71 | 64 | protected function define_atomic_controls(): array { |
| 72 | 65 | $content_section = Section::make() |
| 73 | 66 | ->set_label( __( 'Content', 'elementor' ) ) |
| 74 | 67 | ->set_items( [ |
| 75 | - Inline_Editing_Control::bind_to( 'title' ) | |
| 76 | - ->set_placeholder( __( 'Type your title here', 'elementor' ) ) | |
| 68 | + Textarea_Control::bind_to( 'title' ) | |
| 69 | + ->set_placeholder( __( 'Type your title here', 'elementor' ) ) | |
| 77 | 70 | ->set_label( __( 'Title', 'elementor' ) ), |
| 78 | 71 | ] ); |
| 79 | 72 | |
| 80 | 73 | return [ |
| @@ -116,9 +109,8 @@ | ||
| 116 | 109 | ], |
| 117 | 110 | ]) |
| 118 | 111 | ->set_label( __( 'Tag', 'elementor' ) ), |
| 119 | 112 | Link_Control::bind_to( 'link' ) |
| 120 | - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) | |
| 121 | 113 | ->set_label( __( 'Link', 'elementor' ) ) |
| 122 | 114 | ->set_meta( [ |
| 123 | 115 | 'topDivider' => true, |
| 124 | 116 | ] ), |
| @@ -152,34 +144,6 @@ | ||
| 152 | 144 | protected function get_templates(): array { |
| 153 | 145 | return [ |
| 154 | 146 | 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 155 | 147 | ]; |
| 156 | - } | |
| 157 | - | |
| 158 | - public function render_markdown(): string { | |
| 159 | - $settings = $this->get_atomic_settings(); | |
| 160 | - $title = wp_strip_all_tags( $settings['title'] ?? '' ); | |
| 161 | - | |
| 162 | - if ( empty( $title ) ) { | |
| 163 | - return ''; | |
| 164 | - } | |
| 165 | - | |
| 166 | - $tag = $settings['tag'] ?? 'h2'; | |
| 167 | - $level_map = [ | |
| 168 | - 'h1' => 1, | |
| 169 | - 'h2' => 2, | |
| 170 | - 'h3' => 3, | |
| 171 | - 'h4' => 4, | |
| 172 | - 'h5' => 5, | |
| 173 | - 'h6' => 6, | |
| 174 | - ]; | |
| 175 | - $level = $level_map[ $tag ] ?? 2; | |
| 176 | - | |
| 177 | - $md = str_repeat( '#', $level ) . ' ' . $title; | |
| 178 | - | |
| 179 | - if ( ! empty( $settings['link']['href'] ) ) { | |
| 180 | - $md = str_repeat( '#', $level ) . ' [' . $title . '](' . esc_url( $settings['link']['href'] ) . ')'; | |
| 181 | - } | |
| 182 | - | |
| 183 | - return $md; | |
| 184 | 148 | } |
| 185 | 149 | } |