PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / atomic-widgets / elements / atomic-paragraph / atomic-paragraph.php

atomic-paragraph.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/atomic-widgets/elements/atomic-paragraph/atomic-paragraph.php

162 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph;
4
5 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
6 use Elementor\Modules\AtomicWidgets\Controls\Section;
7 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
8 use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
9 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template;
10 use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
11 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
12 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
13 use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type;
14 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
17 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
18 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
19 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
20 use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control;
21 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 class Atomic_Paragraph extends Atomic_Widget_Base {
28 use Has_Template;
29
30 const LINK_BASE_STYLE_KEY = 'link-base';
31
32 public static $widget_description = 'Display a paragraph with customizable tag, styles, and link options.';
33
34 public static function get_element_type(): string {
35 return 'e-paragraph';
36 }
37
38 public function get_title() {
39 return esc_html__( 'Paragraph', 'elementor' );
40 }
41
42 public function get_keywords() {
43 return [ 'ato', 'atom', 'atoms', 'atomic', 'paragraph', 'text', 'content' ];
44 }
45
46 public function get_icon() {
47 return 'eicon-paragraph';
48 }
49
50 public static function html_tag_follows_link(): bool {
51 return false;
52 }
53
54 public static function get_computed_html_tag( array $settings ): string {
55 return Html_Tag_Computer::compute( $settings, 'p', [
56 Html_Tag_Computer::FOLLOW_LINK_OPTION => static::html_tag_follows_link(),
57 ] );
58 }
59
60 protected static function define_props_schema(): array {
61 return [
62 'classes' => Classes_Prop_Type::make()
63 ->default( [] ),
64
65 'paragraph' => Escaped_Html_Prop_Type::make()
66 ->default( __( 'Type your paragraph here', 'elementor' ) )
67 ->description( 'The text content of the paragraph.' )
68 ->alias( 'text', 'content' ),
69
70 'tag' => String_Prop_Type::make()
71 ->enum( [ 'p', 'span' ] )
72 ->default( 'p' )
73 ->description( 'The HTML tag for the paragraph element. One of: p or span. Do not use heading or div tags.' ),
74
75 'link' => Link_Prop_Type::make(),
76
77 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
78 ];
79 }
80
81 protected function define_atomic_controls(): array {
82 return [
83 Section::make()
84 ->set_label( __( 'Content', 'elementor' ) )
85 ->set_id( 'content' )
86 ->set_items( [
87 Inline_Editing_Control::bind_to( 'paragraph' )
88 ->set_placeholder( __( 'Type your paragraph here', 'elementor' ) )
89 ->set_label( __( 'Paragraph', 'elementor' ) ),
90 ] ),
91 Section::make()
92 ->set_label( __( 'Settings', 'elementor' ) )
93 ->set_id( 'settings' )
94 ->set_items( $this->get_settings_controls() ),
95 ];
96 }
97
98 protected function get_settings_controls(): array {
99 return [
100 Select_Control::bind_to( 'tag' )
101 ->set_options([
102 [
103 'value' => 'p',
104 'label' => 'p',
105 ],
106 [
107 'value' => 'span',
108 'label' => 'span',
109 ],
110 ])
111 ->set_label( __( 'Tag', 'elementor' ) ),
112 Link_Control::bind_to( 'link' )
113 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
114 ->set_label( __( 'Link', 'elementor' ) )
115 ->set_meta( [
116 'topDivider' => true,
117 ] ),
118 Text_Control::bind_to( '_cssid' )
119 ->set_label( __( 'ID', 'elementor' ) )
120 ->set_meta( $this->get_css_id_control_meta() ),
121 ];
122 }
123
124 protected function define_base_styles(): array {
125 $margin_value = Size_Prop_Type::generate( [
126 'unit' => 'px',
127 'size' => 0 ,
128 ] );
129
130 return [
131 'base' => Style_Definition::make()
132 ->add_variant(
133 Style_Variant::make()
134 ->add_prop( 'margin', $margin_value )
135 ),
136 self::LINK_BASE_STYLE_KEY => Style_Definition::make()
137 ->add_variant(
138 Style_Variant::make()
139 ->add_prop( 'all', 'unset' )
140 ->add_prop( 'cursor', 'pointer' )
141 ),
142 ];
143 }
144
145 protected function get_templates(): array {
146 return [
147 'elementor/elements/atomic-paragraph' => __DIR__ . '/atomic-paragraph.html.twig',
148 ];
149 }
150
151 public function render_markdown(): string {
152 $settings = $this->get_atomic_settings();
153 $content = $settings['paragraph'] ?? '';
154
155 if ( empty( $content ) ) {
156 return '';
157 }
158
159 return \Elementor\Modules\MarkdownRender\Html_To_Markdown::convert( $content );
160 }
161 }
162