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