← All changes
|
modules/atomic-widgets/elements/atomic-heading/atomic-heading.php
+42
-111
4.3.0
→
3.29.0-beta4
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\Color_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,18 +39,8 @@ | ||
| 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 | 44 | return [ |
| 61 | 45 | 'classes' => Classes_Prop_Type::make() |
| 62 | 46 | ->default( [] ), |
| @@ -62,80 +46,55 @@ | ||
| 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 | - | |
| 76 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 77 | 56 | ]; |
| 78 | 57 | } |
| 79 | 58 | |
| 80 | 59 | protected function define_atomic_controls(): array { |
| 81 | - $content_section = Section::make() | |
| 82 | - ->set_label( __( 'Content', 'elementor' ) ) | |
| 83 | - ->set_id( 'content' ) | |
| 84 | - ->set_items( [ | |
| 85 | - Inline_Editing_Control::bind_to( 'title' ) | |
| 86 | - ->set_placeholder( __( 'Type your title here', 'elementor' ) ) | |
| 87 | - ->set_label( __( 'Title', 'elementor' ) ), | |
| 88 | - ] ); | |
| 89 | - | |
| 90 | 60 | return [ |
| 91 | - $content_section, | |
| 92 | 61 | 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 [ | |
| 101 | - Select_Control::bind_to( 'tag' ) | |
| 102 | - ->set_options([ | |
| 103 | - [ | |
| 104 | - 'value' => 'h1', | |
| 105 | - 'label' => 'H1', | |
| 106 | - ], | |
| 107 | - [ | |
| 108 | - 'value' => 'h2', | |
| 109 | - 'label' => 'H2', | |
| 110 | - ], | |
| 111 | - [ | |
| 112 | - 'value' => 'h3', | |
| 113 | - 'label' => 'H3', | |
| 114 | - ], | |
| 115 | - [ | |
| 116 | - 'value' => 'h4', | |
| 117 | - 'label' => 'H4', | |
| 118 | - ], | |
| 119 | - [ | |
| 120 | - 'value' => 'h5', | |
| 121 | - 'label' => 'H5', | |
| 122 | - ], | |
| 123 | - [ | |
| 124 | - 'value' => 'h6', | |
| 125 | - 'label' => 'H6', | |
| 126 | - ], | |
| 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, | |
| 62 | + ->set_label( __( 'Content', 'elementor' ) ) | |
| 63 | + ->set_items( [ | |
| 64 | + Textarea_Control::bind_to( 'title' ) | |
| 65 | + ->set_label( __( 'Title', 'elementor' ) ) | |
| 66 | + ->set_placeholder( __( 'Type your title here', 'elementor' ) ), | |
| 67 | + Select_Control::bind_to( 'tag' ) | |
| 68 | + ->set_label( esc_html__( 'Tag', 'elementor' ) ) | |
| 69 | + ->set_options( [ | |
| 70 | + [ | |
| 71 | + 'value' => 'h1', | |
| 72 | + 'label' => 'H1', | |
| 73 | + ], | |
| 74 | + [ | |
| 75 | + 'value' => 'h2', | |
| 76 | + 'label' => 'H2', | |
| 77 | + ], | |
| 78 | + [ | |
| 79 | + 'value' => 'h3', | |
| 80 | + 'label' => 'H3', | |
| 81 | + ], | |
| 82 | + [ | |
| 83 | + 'value' => 'h4', | |
| 84 | + 'label' => 'H4', | |
| 85 | + ], | |
| 86 | + [ | |
| 87 | + 'value' => 'h5', | |
| 88 | + 'label' => 'H5', | |
| 89 | + ], | |
| 90 | + [ | |
| 91 | + 'value' => 'h6', | |
| 92 | + 'label' => 'H6', | |
| 93 | + ], | |
| 94 | + ]), | |
| 95 | + Link_Control::bind_to( 'link' ), | |
| 134 | 96 | ] ), |
| 135 | - Text_Control::bind_to( '_cssid' ) | |
| 136 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 137 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 138 | 97 | ]; |
| 139 | 98 | } |
| 140 | 99 | |
| 141 | 100 | protected function define_base_styles(): array { |
| @@ -162,34 +121,6 @@ | ||
| 162 | 121 | protected function get_templates(): array { |
| 163 | 122 | return [ |
| 164 | 123 | 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 165 | 124 | ]; |
| 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 | 125 | } |
| 195 | 126 | } |