← All changes
|
modules/atomic-widgets/elements/atomic-heading/atomic-heading.php
+56
-128
4.3.0
→
3.28.0-dev2
View file →
| @@ -1,24 +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; | |
| 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; | |
| 17 | +use Elementor\Modules\WpRest\Classes\WP_Post; | |
| 21 | 18 | |
| 22 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | 20 | exit; // Exit if accessed directly. |
| 24 | 21 | } |
| @@ -25,38 +22,20 @@ | ||
| 25 | 22 | |
| 26 | 23 | class Atomic_Heading extends Atomic_Widget_Base { |
| 27 | 24 | use Has_Template; |
| 28 | 25 | |
| 29 | - const LINK_BASE_STYLE_KEY = 'link-base'; | |
| 30 | - | |
| 31 | - public static $widget_description = 'Display a heading with customizable tag, styles, and link options.'; | |
| 32 | - | |
| 33 | 26 | public static function get_element_type(): string { |
| 34 | - return 'e-heading'; | |
| 27 | + return 'a-heading'; | |
| 35 | 28 | } |
| 36 | 29 | |
| 37 | 30 | public function get_title() { |
| 38 | - return esc_html__( 'Heading', 'elementor' ); | |
| 31 | + return esc_html__( 'Atomic Heading', 'elementor' ); | |
| 39 | 32 | } |
| 40 | 33 | |
| 41 | - public function get_keywords() { | |
| 42 | - return [ 'ato', 'atom', 'atoms', 'atomic', 'heading', 'title', 'text', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]; | |
| 43 | - } | |
| 44 | - | |
| 45 | 34 | public function get_icon() { |
| 46 | 35 | return 'eicon-e-heading'; |
| 47 | 36 | } |
| 48 | 37 | |
| 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 | 38 | protected static function define_props_schema(): array { |
| 60 | 39 | return [ |
| 61 | 40 | 'classes' => Classes_Prop_Type::make() |
| 62 | 41 | ->default( [] ), |
| @@ -62,101 +41,78 @@ | ||
| 62 | 41 | ->default( [] ), |
| 63 | 42 | |
| 64 | 43 | 'tag' => String_Prop_Type::make() |
| 65 | 44 | ->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.' ), | |
| 45 | + ->default( 'h2' ), | |
| 68 | 46 | |
| 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' ), | |
| 47 | + 'title' => String_Prop_Type::make() | |
| 48 | + ->default( __( 'Your Title Here', 'elementor' ) ), | |
| 73 | 49 | |
| 74 | 50 | 'link' => Link_Prop_Type::make(), |
| 75 | - | |
| 76 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 77 | 51 | ]; |
| 78 | 52 | } |
| 79 | 53 | |
| 80 | 54 | 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 | 55 | return [ |
| 91 | - $content_section, | |
| 92 | 56 | 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, | |
| 57 | + ->set_label( __( 'Content', 'elementor' ) ) | |
| 58 | + ->set_items( [ | |
| 59 | + Textarea_Control::bind_to( 'title' ) | |
| 60 | + ->set_label( __( 'Title', 'elementor' ) ) | |
| 61 | + ->set_placeholder( __( 'Type your title here', 'elementor' ) ), | |
| 62 | + Select_Control::bind_to( 'tag' ) | |
| 63 | + ->set_label( esc_html__( 'Tag', 'elementor' ) ) | |
| 64 | + ->set_options( [ | |
| 65 | + [ | |
| 66 | + 'value' => 'h1', | |
| 67 | + 'label' => 'H1', | |
| 68 | + ], | |
| 69 | + [ | |
| 70 | + 'value' => 'h2', | |
| 71 | + 'label' => 'H2', | |
| 72 | + ], | |
| 73 | + [ | |
| 74 | + 'value' => 'h3', | |
| 75 | + 'label' => 'H3', | |
| 76 | + ], | |
| 77 | + [ | |
| 78 | + 'value' => 'h4', | |
| 79 | + 'label' => 'H4', | |
| 80 | + ], | |
| 81 | + [ | |
| 82 | + 'value' => 'h5', | |
| 83 | + 'label' => 'H5', | |
| 84 | + ], | |
| 85 | + [ | |
| 86 | + 'value' => 'h6', | |
| 87 | + 'label' => 'H6', | |
| 88 | + ], | |
| 89 | + ]), | |
| 90 | + Link_Control::bind_to( 'link' ), | |
| 134 | 91 | ] ), |
| 135 | - Text_Control::bind_to( '_cssid' ) | |
| 136 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 137 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 138 | 92 | ]; |
| 139 | 93 | } |
| 140 | 94 | |
| 141 | 95 | protected function define_base_styles(): array { |
| 142 | - $margin_value = Size_Prop_Type::generate( [ | |
| 143 | - 'unit' => 'px', | |
| 144 | - 'size' => 0 , | |
| 96 | + $color_value = Color_Prop_Type::generate( 'black' ); | |
| 97 | + $font_family_value = String_Prop_Type::generate( 'Inter' ); | |
| 98 | + $font_size_value = Size_Prop_Type::generate( [ | |
| 99 | + 'size' => 3, | |
| 100 | + 'unit' => 'rem', | |
| 145 | 101 | ] ); |
| 102 | + $line_height_value = String_Prop_Type::generate( '1.1' ); | |
| 103 | + $font_weight_value = String_Prop_Type::generate( '600' ); | |
| 146 | 104 | |
| 147 | 105 | return [ |
| 148 | 106 | 'base' => Style_Definition::make() |
| 149 | 107 | ->add_variant( |
| 150 | 108 | Style_Variant::make() |
| 151 | - ->add_prop( 'margin', $margin_value ) | |
| 109 | + ->add_prop( 'color', $color_value ) | |
| 110 | + ->add_prop( 'font-family', $font_family_value ) | |
| 111 | + ->add_prop( 'font-size', $font_size_value ) | |
| 112 | + ->add_prop( 'line-height', $line_height_value ) | |
| 113 | + ->add_prop( 'font-weight', $font_weight_value ) | |
| 152 | 114 | ), |
| 153 | - self::LINK_BASE_STYLE_KEY => Style_Definition::make() | |
| 154 | - ->add_variant( | |
| 155 | - Style_Variant::make() | |
| 156 | - ->add_prop( 'all', 'unset' ) | |
| 157 | - ->add_prop( 'cursor', 'pointer' ) | |
| 158 | - ), | |
| 159 | 115 | ]; |
| 160 | 116 | } |
| 161 | 117 | |
| 162 | 118 | protected function get_templates(): array { |
| @@ -162,34 +118,6 @@ | ||
| 162 | 118 | protected function get_templates(): array { |
| 163 | 119 | return [ |
| 164 | 120 | 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 165 | 121 | ]; |
| 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 | 122 | } |
| 195 | 123 | } |