PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.8
Elementor Website Builder – more than just a page builder v4.0.8
4.3.2 4.3.1 4.3.0 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 All 455 releases
← All changes | modules/atomic-widgets/elements/atomic-form/atomic-form.php +85 -253 4.3.0-beta1 → 4.0.8 View file →
@@ -3,9 +3,8 @@
3 3
4 4 use Elementor\Modules\AtomicWidgets\Controls\Section;
5 5 use Elementor\Modules\AtomicWidgets\Controls\Types\Chips_Control;
6 6 use Elementor\Modules\AtomicWidgets\Controls\Types\Email_Form_Action_Control;
7 -use Elementor\Modules\AtomicWidgets\Controls\Types\Switch_Control;
8 7 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
9 8 use Elementor\Modules\AtomicWidgets\Controls\Types\Toggle_Control;
10 9 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph;
11 10 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Form_Success_Message\Form_Success_Message;
@@ -12,19 +11,17 @@
12 11 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Form_Error_Message\Form_Error_Message;
13 12 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
14 13 use Elementor\Modules\AtomicWidgets\Elements\Base\Element_Builder;
15 14 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template;
16 -use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
17 15 use Elementor\Modules\AtomicWidgets\Elements\Base\Widget_Builder;
18 16 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
19 17 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
20 18 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
21 -use Elementor\Modules\AtomicWidgets\PropTypes\Emails_Prop_Type;
19 +use Elementor\Modules\AtomicWidgets\PropTypes\Email_Prop_Type;
22 20 use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type;
23 -use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type;
24 21 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type;
25 22 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
26 -use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type;
23 +use Elementor\Modules\AtomicWidgets\PropTypes\Html_V3_Prop_Type;
27 24 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Array_Prop_Type;
28 25 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
29 26 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
30 27 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
@@ -29,9 +26,8 @@
29 26 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
30 27 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
31 28 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
32 29 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
33 -use Elementor\Plugin;
34 30
35 31 if ( ! defined( 'ABSPATH' ) ) {
36 32 exit; // Exit if accessed directly.
37 33 }
@@ -40,31 +36,17 @@
40 36 use Has_Element_Template;
41 37
42 38 const BASE_STYLE_KEY = 'base';
43 39
44 - public static $widget_description = 'A form container that holds form field widgets (labels, inputs, textareas, checkboxes, submit button) and status messages.';
45 -
46 - public const ACTION_EMAIL = 'email';
47 40 public const ACTION_COLLECT_SUBMISSIONS = 'collect-submissions';
48 - public const ACTION_WEBHOOK = 'webhook';
49 41 public const METADATA_REMOTE_IP = 'remote_ip';
50 42 public const METADATA_USER_AGENT = 'user_agent';
51 43
52 -
53 -
54 44 public function __construct( $data = [], $args = null ) {
55 45 parent::__construct( $data, $args );
56 46 $this->meta( 'is_container', true );
57 47 }
58 48
59 - public static function get_default_recipient_email(): string {
60 - return sanitize_email( (string) get_option( 'admin_email', '' ) );
61 - }
62 -
63 - public static function get_default_sender_email(): string {
64 - return sanitize_email( (string) 'email@' . wp_parse_url( home_url(), PHP_URL_HOST ) );
65 - }
66 -
67 49 public static function get_type() {
68 50 return 'e-form';
69 51 }
70 52
@@ -83,49 +65,38 @@
83 65 public function get_icon() {
84 66 return 'eicon-atomic-form';
85 67 }
86 68
87 - public static function get_computed_html_tag( array $settings ): string {
88 - return Html_Tag_Computer::compute( $settings, 'form' );
89 - }
90 -
91 - public static function get_base_props_schema(): array {
92 - return self::define_props_schema();
93 - }
94 -
95 69 protected static function define_props_schema(): array {
96 - $submissions_metadata_dependencies = Dependency_Manager::make()
70 + $email_dependencies = Dependency_Manager::make()
97 71 ->where( [
98 72 'operator' => 'contains',
99 73 'path' => [ 'actions-after-submit' ],
100 - 'value' => self::ACTION_COLLECT_SUBMISSIONS,
74 + 'value' => 'email',
101 75 'effect' => 'hide',
102 76 ] )
103 77 ->get();
104 78
105 - $webhook_dependencies = Dependency_Manager::make()
79 + $submissions_metadata_dependencies = Dependency_Manager::make()
106 80 ->where( [
107 81 'operator' => 'contains',
108 82 'path' => [ 'actions-after-submit' ],
109 - 'value' => self::ACTION_WEBHOOK,
83 + 'value' => self::ACTION_COLLECT_SUBMISSIONS,
110 84 'effect' => 'hide',
111 85 ] )
112 86 ->get();
113 87
114 - $props = [
88 + return [
115 89 'classes' => Classes_Prop_Type::make()
116 90 ->default( [] ),
117 91 'form-name' => String_Prop_Type::make()
118 92 ->default( __( 'Form', 'elementor' ) ),
119 - 'webmcp-autosubmit' => Boolean_Prop_Type::make()
120 - ->default( false ),
121 93 'form-state' => String_Prop_Type::make()
122 94 ->enum( [ 'default', 'success', 'error' ] )
123 95 ->default( 'default' )
124 96 ->meta( 'generates_class', 'form-state-{value}' ),
125 97 'actions-after-submit' => String_Array_Prop_Type::make()
126 - ->initial_value( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] )
127 - ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ),
98 + ->default( [ String_Prop_Type::generate( 'email' ) ] ),
128 99 'submissions_metadata' => String_Array_Prop_Type::make()
129 100 ->set_dependencies( $submissions_metadata_dependencies )
130 101 ->default( [
131 102 String_Prop_Type::generate( self::METADATA_REMOTE_IP ),
@@ -130,83 +101,63 @@
130 101 ->default( [
131 102 String_Prop_Type::generate( self::METADATA_REMOTE_IP ),
132 103 String_Prop_Type::generate( self::METADATA_USER_AGENT ),
133 104 ] ),
134 - ];
135 -
136 - $props = array_merge( $props, self::get_emails_prop_settings(), [
137 - 'webhook_url' => String_Prop_Type::make()
138 - ->set_dependencies( $webhook_dependencies )
105 + 'email' => Email_Prop_Type::make()
106 + ->set_dependencies( $email_dependencies )
139 107 ->meta( Overridable_Prop_Type::ignore() )
140 - ->default( '' ),
108 + ->default( [] ),
141 109 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
142 - ] );
143 -
144 - return $props;
110 + ];
145 111 }
146 112
147 113 protected function define_atomic_controls(): array {
148 114 $state_control = Toggle_Control::bind_to( 'form-state' )
149 - ->add_options( [
150 - 'default' => [
151 - 'title' => __( 'Normal', 'elementor' ),
152 - ],
153 - 'success' => [
154 - 'title' => __( 'Success', 'elementor' ),
155 - ],
156 - 'error' => [
157 - 'title' => __( 'Error', 'elementor' ),
158 - ],
159 - ] )
160 - ->set_exclusive( true )
161 - ->set_convert_options( true )
162 - ->set_size( 'tiny' )
163 - ->set_full_width( true )
164 115 ->set_label( __( 'States', 'elementor' ) )
165 116 ->set_meta( [ 'topDivider' => true ] );
166 117
167 - $email_control_settings = $this->get_emails_control_settings();
168 - $form_action_chips = $email_control_settings['form-action-chips'];
169 - $email_controls = $email_control_settings['email-controls'];
170 -
171 - if ( class_exists( '\ElementorPro\License\API' ) ) {
172 - $has_form_submissions_feature = \ElementorPro\License\API::is_licence_has_feature( 'form-submissions' );
173 -
174 - if ( $has_form_submissions_feature ) {
175 - $form_action_chips = array_merge( $form_action_chips, [
176 - [
177 - 'label' => __( 'Collect submissions', 'elementor' ),
178 - 'value' => self::ACTION_COLLECT_SUBMISSIONS,
118 + if ( $state_control instanceof Toggle_Control ) {
119 + $state_control
120 + ->add_options( [
121 + 'default' => [
122 + 'title' => __( 'Normal', 'elementor' ),
179 123 ],
180 - ] );
181 - }
124 + 'success' => [
125 + 'title' => __( 'Success', 'elementor' ),
126 + ],
127 + 'error' => [
128 + 'title' => __( 'Error', 'elementor' ),
129 + ],
130 + ] )
131 + ->set_exclusive( true )
132 + ->set_convert_options( true )
133 + ->set_size( 'tiny' )
134 + ->set_full_width( true );
182 135 }
183 136
184 - $content_controls = [
185 - Text_Control::bind_to( 'form-name' )
186 - ->set_label( __( 'Form name', 'elementor' ) ),
187 - $state_control,
188 - Chips_Control::bind_to( 'actions-after-submit' )
189 - ->set_options( array_merge( $form_action_chips, [
190 - [
191 - 'label' => __( 'Webhook', 'elementor' ),
192 - 'value' => self::ACTION_WEBHOOK,
193 - ],
194 - ] ) )
195 - ->set_label( __( 'Actions after submit', 'elementor' ) )
196 - ->set_meta( [ 'topDivider' => true ] ),
197 - ];
198 -
199 137 return [
200 138 Section::make()
201 139 ->set_label( __( 'Content', 'elementor' ) )
202 - ->set_id( 'content' )
203 - ->set_items( $content_controls ),
204 - ...$email_controls,
205 - Section::make()
206 - ->set_label( __( 'Collect submissions', 'elementor' ) )
207 140 ->set_items( [
141 + Text_Control::bind_to( 'form-name' )
142 + ->set_label( __( 'Form name', 'elementor' ) ),
143 + $state_control,
144 + Chips_Control::bind_to( 'actions-after-submit' )
145 + ->set_label( __( 'Actions after submit', 'elementor' ) )
146 + ->set_meta( [ 'topDivider' => true ] )
147 + ->set_options( [
148 + [
149 + 'label' => __( 'Collect submissions', 'elementor' ),
150 + 'value' => self::ACTION_COLLECT_SUBMISSIONS,
151 + ],
152 + [
153 + 'label' => __( 'Email', 'elementor' ),
154 + 'value' => 'email',
155 + ],
156 + ] ),
208 157 Chips_Control::bind_to( 'submissions_metadata' )
158 + ->set_label( __( 'Include metadata', 'elementor' ) )
159 + ->set_meta( [ 'topDivider' => true ] )
209 160 ->set_options( [
210 161 [
211 162 'label' => __( 'User IP', 'elementor' ),
212 163 'value' => self::METADATA_REMOTE_IP,
@@ -214,19 +165,15 @@
214 165 [
215 166 'label' => __( 'User Agent', 'elementor' ),
216 167 'value' => self::METADATA_USER_AGENT,
217 168 ],
218 - ] )
219 - ->set_label( __( 'Include metadata', 'elementor' ) ),
169 + ] ),
170 + Email_Form_Action_Control::bind_to( 'email' )
171 + ->set_meta( [
172 + 'topDivider' => true,
173 + ] ),
220 174 ] ),
221 175 Section::make()
222 - ->set_label( __( 'Webhook', 'elementor' ) )
223 - ->set_items( [
224 - Text_Control::bind_to( 'webhook_url' )
225 - ->set_placeholder( __( 'https://your-webhook-url.com', 'elementor' ) )
226 - ->set_label( __( 'Webhook URL', 'elementor' ) ),
227 - ] ),
228 - Section::make()
229 176 ->set_label( __( 'Settings', 'elementor' ) )
230 177 ->set_id( 'settings' )
231 178 ->set_items( [
232 179 Text_Control::bind_to( '_cssid' )
@@ -231,24 +178,12 @@
231 178 ->set_items( [
232 179 Text_Control::bind_to( '_cssid' )
233 180 ->set_label( __( 'ID', 'elementor' ) )
234 181 ->set_meta( $this->get_css_id_control_meta() ),
235 - Switch_Control::bind_to( 'webmcp-autosubmit' )
236 - ->set_label( __( 'Agent auto-submit', 'elementor' ) ),
237 182 ] ),
238 183 ];
239 184 }
240 185
241 - protected function define_base_settings(): array {
242 - $settings = [];
243 -
244 - foreach ( self::build_email_action_defaults() as $key => $default_email ) {
245 - $settings[ $key ] = Emails_Prop_Type::generate( $default_email );
246 - }
247 -
248 - return $settings;
249 - }
250 -
251 186 protected function define_base_styles(): array {
252 187 return [
253 188 static::BASE_STYLE_KEY => Style_Definition::make()
254 189 ->add_variant(
@@ -288,13 +223,17 @@
288 223 protected function define_panel_categories(): array {
289 224 return [ 'atomic-form' ];
290 225 }
291 226
227 + protected function define_default_html_tag() {
228 + return 'form';
229 + }
230 +
292 231 protected function define_default_children() {
293 232
294 233 $prefix = 'e-form-';
295 234
296 - $children = [
235 + return [
297 236 $this->build_label( __( 'First name', 'elementor' ), $prefix . 'first-name' ),
298 237 $this->build_input( __( 'First name', 'elementor' ), 'text', $prefix . 'first-name' ),
299 238
300 239 $this->build_label( __( 'Last name', 'elementor' ), $prefix . 'last-name' ),
@@ -304,29 +243,30 @@
304 243 $this->build_input( __( '[email protected]', 'elementor' ), 'email', $prefix . 'email' ),
305 244
306 245 $this->build_label( __( 'Message', 'elementor' ), $prefix . 'message' ),
307 246 $this->build_input( __( 'Your message', 'elementor' ), 'textarea', $prefix . 'message' ),
308 - ];
309 247
310 - $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' );
248 + $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ),
311 249
312 - $children[] = Widget_Builder::make( 'e-form-submit-button' )
313 - ->settings( [
314 - 'text' => Escaped_Html_Prop_Type::generate( __( 'Submit', 'elementor' ) ),
315 - ] )
316 - ->build();
317 - $children[] = $this->build_status_message(
318 - __( 'Great! We’ve received your information.', 'elementor' ),
319 - 'success',
320 - __( 'Success message', 'elementor' )
321 - );
322 - $children[] = $this->build_status_message(
323 - __( 'We couldn’t process your submission. Please retry', 'elementor' ),
324 - 'error',
325 - __( 'Error message', 'elementor' )
326 - );
327 -
328 - return $children;
250 + Widget_Builder::make( 'e-form-submit-button' )
251 + ->settings( [
252 + 'text' => Html_V3_Prop_Type::generate( [
253 + 'content' => String_Prop_Type::generate( __( 'Submit', 'elementor' ) ),
254 + 'children' => [],
255 + ] ),
256 + ] )
257 + ->build(),
258 + $this->build_status_message(
259 + __( 'Great! We’ve received your information.', 'elementor' ),
260 + 'success',
261 + __( 'Success message', 'elementor' )
262 + ),
263 + $this->build_status_message(
264 + __( 'We couldn’t process your submission. Please retry', 'elementor' ),
265 + 'error',
266 + __( 'Error message', 'elementor' )
267 + ),
268 + ];
329 269 }
330 270
331 271 private function build_checkbox_row( string $label_text, string $checkbox_id ): array {
332 272 $checkbox = Widget_Builder::make( 'e-form-checkbox' )
@@ -347,9 +287,12 @@
347 287
348 288 private function build_label( string $text, string $input_id ): array {
349 289 return Widget_Builder::make( 'e-form-label' )
350 290 ->settings( [
351 - 'text' => Escaped_Html_Prop_Type::generate( $text ),
291 + 'text' => Html_V3_Prop_Type::generate( [
292 + 'content' => String_Prop_Type::generate( $text ),
293 + 'children' => [],
294 + ] ),
352 295 'input-id' => String_Prop_Type::generate( $input_id ),
353 296 ] )
354 297 ->build();
355 298 }
@@ -374,9 +317,12 @@
374 317 ->build();
375 318 }
376 319
377 320 private function build_status_message( string $message, string $state, string $title ): array {
378 - $paragraph_value = Escaped_Html_Prop_Type::generate( $message );
321 + $paragraph_value = Html_V3_Prop_Type::generate( [
322 + 'content' => String_Prop_Type::generate( $message ),
323 + 'children' => [],
324 + ] );
379 325
380 326 $element_type = 'success' === $state
381 327 ? Form_Success_Message::get_element_type()
382 328 : Form_Error_Message::get_element_type();
@@ -381,9 +327,8 @@
381 327 ? Form_Success_Message::get_element_type()
382 328 : Form_Error_Message::get_element_type();
383 329
384 330 return Element_Builder::make( $element_type )
385 - ->meta( [ 'required' => true ] )
386 331 ->settings( [
387 332 'attributes' => Attributes_Prop_Type::generate( [
388 333 Key_Value_Prop_Type::generate( [] ),
389 334 ] ),
@@ -397,8 +342,9 @@
397 342 'paragraph' => $paragraph_value,
398 343 ] )
399 344 ->build(),
400 345 ] )
346 + ->is_locked( true )
401 347 ->build();
402 348 }
403 349
404 350 protected function get_templates(): array {
@@ -411,121 +357,7 @@
411 357 $context = $this->build_base_template_context();
412 358
413 359 $context['form_state'] = 'default';
414 360
415 - if ( ! $this->is_webmcp_enabled() ) {
416 - return $context;
417 - }
418 -
419 - $form_name = (string) ( $this->get_atomic_settings()['form-name'] ?? '' );
420 - $context['webmcp_tool_name'] = Webmcp_Utils::build_tool_name( $form_name, (string) $this->get_id() );
421 - $context['webmcp_tool_description'] = Webmcp_Utils::build_tool_description( $form_name );
422 -
423 361 return $context;
424 - }
425 -
426 - private function is_webmcp_enabled(): bool {
427 - return ! Plugin::$instance->editor->is_edit_mode();
428 - }
429 -
430 - public static function is_instance_form( $instance ): bool {
431 - return $instance instanceof Atomic_Form;
432 - }
433 -
434 - public function render_markdown(): string {
435 - return '';
436 - }
437 -
438 - private static function get_emails_prop_settings(): array {
439 - $props = [];
440 -
441 - foreach ( self::build_email_action_defaults() as $key => $default_value ) {
442 - $props[ $key ] = Emails_Prop_Type::make()
443 - ->set_dependencies( self::make_action_dependency( $key ) )
444 - ->meta( Overridable_Prop_Type::ignore() )
445 - ->initial_value( $default_value )
446 - ->default( $default_value );
447 - }
448 -
449 - return $props;
450 - }
451 -
452 - private function get_emails_control_settings(): array {
453 - $form_action_chips = [];
454 - $email_controls = [];
455 -
456 - for ( $i = 0; $i < self::get_email_action_count(); $i++ ) {
457 - $key = self::get_email_action_key( $i );
458 - $label = self::get_email_action_label( $i );
459 -
460 - $form_action_chips[] = [
461 - 'label' => $label,
462 - 'value' => $key,
463 - ];
464 -
465 - $email_controls[] = Section::make()
466 - ->set_label( $label )
467 - ->set_items( [
468 - Email_Form_Action_Control::bind_to( $key )
469 - ->set_free_chips( true )
470 - ->set_label( $label ),
471 - ] );
472 - }
473 -
474 - return [
475 - 'form-action-chips' => $form_action_chips,
476 - 'email-controls' => $email_controls,
477 - ];
478 - }
479 -
480 - private static function get_email_action_key( int $index ): string {
481 - return 0 === $index
482 - ? self::ACTION_EMAIL
483 - : self::ACTION_EMAIL . '_' . ( $index + 1 );
484 - }
485 -
486 - private static function get_email_action_label( int $index ): string {
487 - if ( 0 === $index ) {
488 - return __( 'Email', 'elementor' );
489 - }
490 -
491 - // translators: %d is the index of the email action.
492 - return sprintf( __( 'Email %d', 'elementor' ), $index + 1 );
493 - }
494 -
495 - private static function build_email_action_defaults(): array {
496 - $defaults = [];
497 - $default_email = self::get_default_email_value();
498 -
499 - for ( $i = 0; $i < self::get_email_action_count(); $i++ ) {
500 - $key = self::get_email_action_key( $i );
501 - $defaults[ $key ] = $default_email;
502 - }
503 -
504 - return $defaults;
505 - }
506 -
507 - private static function get_default_email_value(): array {
508 - return [
509 - 'to' => String_Array_Prop_Type::generate( [
510 - String_Prop_Type::generate( self::get_default_recipient_email() ),
511 - ] ),
512 - 'from' => String_Prop_Type::generate( self::get_default_sender_email() ),
513 - 'message' => String_Prop_Type::generate( '[all-fields]' ),
514 - ];
515 - }
516 -
517 - private static function make_action_dependency( string $action_key ): ?array {
518 - return Dependency_Manager::make()
519 - ->where( [
520 - 'operator' => 'contains',
521 - 'path' => [ 'actions-after-submit' ],
522 - 'value' => $action_key,
523 - 'effect' => 'hide',
524 - ] )
525 - ->get();
526 - }
527 -
528 - private static function get_email_action_count(): int {
529 - return apply_filters( 'elementor/atomic/form/email_action_count', 1 );
530 362 }
531 363 }