| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\Elements\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\Controls\Types\Textarea_Control; |
| 10 |
use Elementor\Modules\AtomicWidgets\Elements\Has_Template; |
| 11 |
use Elementor\Modules\AtomicWidgets\Module as Atomic_Widgets_Module; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 16 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 17 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 18 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 19 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 20 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 21 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control; |
| 22 |
use Elementor\Plugin; |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; |
| 26 |
} |
| 27 |
|
| 28 |
class Atomic_Paragraph extends Atomic_Widget_Base { |
| 29 |
use Has_Template; |
| 30 |
|
| 31 |
const LINK_BASE_STYLE_KEY = 'link-base'; |
| 32 |
|
| 33 |
public static function get_element_type(): string { |
| 34 |
return 'e-paragraph'; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_title() { |
| 38 |
return esc_html__( 'Paragraph', 'elementor' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_keywords() { |
| 42 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_icon() { |
| 46 |
return 'eicon-paragraph'; |
| 47 |
} |
| 48 |
|
| 49 |
protected static function define_props_schema(): array { |
| 50 |
$is_feature_active = Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_INLINE_EDITING ); |
| 51 |
|
| 52 |
$paragraph_prop = $is_feature_active |
| 53 |
? Html_Prop_Type::make()->default( __( 'Type your paragraph here', 'elementor' ) ) |
| 54 |
: String_Prop_Type::make()->default( __( 'Type your paragraph here', 'elementor' ) ); |
| 55 |
|
| 56 |
$props = [ |
| 57 |
'classes' => Classes_Prop_Type::make() |
| 58 |
->default( [] ), |
| 59 |
|
| 60 |
'paragraph' => $paragraph_prop |
| 61 |
->description( 'The text content of the paragraph.' ), |
| 62 |
|
| 63 |
'tag' => String_Prop_Type::make() |
| 64 |
->enum( [ 'p', 'span' ] ) |
| 65 |
->default( 'p' ), |
| 66 |
|
| 67 |
'link' => Link_Prop_Type::make(), |
| 68 |
|
| 69 |
'attributes' => Attributes_Prop_Type::make(), |
| 70 |
]; |
| 71 |
|
| 72 |
return $props; |
| 73 |
} |
| 74 |
|
| 75 |
protected function define_atomic_controls(): array { |
| 76 |
$is_feature_active = Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_INLINE_EDITING ); |
| 77 |
|
| 78 |
$control = $is_feature_active |
| 79 |
? Inline_Editing_Control::bind_to( 'paragraph' ) |
| 80 |
->set_placeholder( __( 'Type your paragraph here', 'elementor' ) ) |
| 81 |
->set_label( __( 'Paragraph', 'elementor' ) ) |
| 82 |
: Textarea_Control::bind_to( 'paragraph' ) |
| 83 |
->set_placeholder( __( 'Type your paragraph here', 'elementor' ) ) |
| 84 |
->set_label( __( 'Paragraph', 'elementor' ) ); |
| 85 |
|
| 86 |
return [ |
| 87 |
Section::make() |
| 88 |
->set_label( __( 'Content', 'elementor' ) ) |
| 89 |
->set_items( [ $control ] ), |
| 90 |
Section::make() |
| 91 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 92 |
->set_id( 'settings' ) |
| 93 |
->set_items( $this->get_settings_controls() ), |
| 94 |
]; |
| 95 |
} |
| 96 |
|
| 97 |
protected function get_settings_controls(): array { |
| 98 |
return [ |
| 99 |
Select_Control::bind_to( 'tag' ) |
| 100 |
->set_options([ |
| 101 |
[ |
| 102 |
'value' => 'p', |
| 103 |
'label' => 'p', |
| 104 |
], |
| 105 |
[ |
| 106 |
'value' => 'span', |
| 107 |
'label' => 'span', |
| 108 |
], |
| 109 |
]) |
| 110 |
->set_label( __( 'Tag', 'elementor' ) ), |
| 111 |
Link_Control::bind_to( 'link' ) |
| 112 |
->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) |
| 113 |
->set_label( __( 'Link', 'elementor' ) ) |
| 114 |
->set_meta( [ |
| 115 |
'topDivider' => true, |
| 116 |
] ), |
| 117 |
Text_Control::bind_to( '_cssid' ) |
| 118 |
->set_label( __( 'ID', 'elementor' ) ) |
| 119 |
->set_meta( $this->get_css_id_control_meta() ), |
| 120 |
]; |
| 121 |
} |
| 122 |
|
| 123 |
protected function define_base_styles(): array { |
| 124 |
$margin_value = Size_Prop_Type::generate( [ |
| 125 |
'unit' => 'px', |
| 126 |
'size' => 0 , |
| 127 |
] ); |
| 128 |
|
| 129 |
return [ |
| 130 |
'base' => Style_Definition::make() |
| 131 |
->add_variant( |
| 132 |
Style_Variant::make() |
| 133 |
->add_prop( 'margin', $margin_value ) |
| 134 |
), |
| 135 |
self::LINK_BASE_STYLE_KEY => Style_Definition::make() |
| 136 |
->add_variant( |
| 137 |
Style_Variant::make() |
| 138 |
->add_prop( 'all', 'unset' ) |
| 139 |
->add_prop( 'cursor', 'pointer' ) |
| 140 |
), |
| 141 |
]; |
| 142 |
} |
| 143 |
|
| 144 |
protected function get_templates(): array { |
| 145 |
return [ |
| 146 |
'elementor/elements/atomic-paragraph' => __DIR__ . '/atomic-paragraph.html.twig', |
| 147 |
]; |
| 148 |
} |
| 149 |
} |
| 150 |
|