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