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