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 -221 4.2.0-beta1 → 4.0.0-beta1 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;
@@ -25,9 +25,8 @@
25 25 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
26 26 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
27 27 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
28 28 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
29 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
30 29
31 30 if ( ! defined( 'ABSPATH' ) ) {
32 31 exit; // Exit if accessed directly.
33 32 }
@@ -36,31 +35,17 @@
36 35 use Has_Element_Template;
37 36
38 37 const BASE_STYLE_KEY = 'base';
39 38
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 39 public const ACTION_COLLECT_SUBMISSIONS = 'collect-submissions';
44 - public const ACTION_WEBHOOK = 'webhook';
45 40 public const METADATA_REMOTE_IP = 'remote_ip';
46 41 public const METADATA_USER_AGENT = 'user_agent';
47 42
48 -
49 -
50 43 public function __construct( $data = [], $args = null ) {
51 44 parent::__construct( $data, $args );
52 45 $this->meta( 'is_container', true );
53 46 }
54 47
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 48 public static function get_type() {
64 49 return 'e-form';
65 50 }
66 51
@@ -68,9 +53,9 @@
68 53 return self::get_type();
69 54 }
70 55
71 56 public function get_title() {
72 - return esc_html__( 'Atomic form', 'elementor' );
57 + return esc_html__( 'Atomic Form', 'elementor' );
73 58 }
74 59
75 60 public function get_keywords() {
76 61 return [ 'atomic', 'form' ];
@@ -80,27 +65,27 @@
80 65 return 'eicon-atomic-form';
81 66 }
82 67
83 68 protected static function define_props_schema(): array {
84 - $submissions_metadata_dependencies = Dependency_Manager::make()
69 + $email_dependencies = Dependency_Manager::make()
85 70 ->where( [
86 71 'operator' => 'contains',
87 72 'path' => [ 'actions-after-submit' ],
88 - 'value' => self::ACTION_COLLECT_SUBMISSIONS,
73 + 'value' => 'email',
89 74 'effect' => 'hide',
90 75 ] )
91 76 ->get();
92 77
93 - $webhook_dependencies = Dependency_Manager::make()
78 + $submissions_metadata_dependencies = Dependency_Manager::make()
94 79 ->where( [
95 80 'operator' => 'contains',
96 81 'path' => [ 'actions-after-submit' ],
97 - 'value' => self::ACTION_WEBHOOK,
82 + 'value' => self::ACTION_COLLECT_SUBMISSIONS,
98 83 'effect' => 'hide',
99 84 ] )
100 85 ->get();
101 86
102 - $props = [
87 + return [
103 88 'classes' => Classes_Prop_Type::make()
104 89 ->default( [] ),
105 90 'form-name' => String_Prop_Type::make()
106 91 ->default( __( 'Form', 'elementor' ) ),
@@ -108,10 +93,9 @@
108 93 ->enum( [ 'default', 'success', 'error' ] )
109 94 ->default( 'default' )
110 95 ->meta( 'generates_class', 'form-state-{value}' ),
111 96 '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 ) ] ),
97 + ->default( [ String_Prop_Type::generate( 'email' ) ] ),
114 98 'submissions_metadata' => String_Array_Prop_Type::make()
115 99 ->set_dependencies( $submissions_metadata_dependencies )
116 100 ->default( [
117 101 String_Prop_Type::generate( self::METADATA_REMOTE_IP ),
@@ -116,74 +100,62 @@
116 100 ->default( [
117 101 String_Prop_Type::generate( self::METADATA_REMOTE_IP ),
118 102 String_Prop_Type::generate( self::METADATA_USER_AGENT ),
119 103 ] ),
104 + 'email' => Email_Prop_Type::make()
105 + ->set_dependencies( $email_dependencies )
106 + ->default( [] ),
107 + 'attributes' => Attributes_Prop_Type::make(),
120 108 ];
121 -
122 - $props = array_merge( $props, self::get_emails_prop_settings(), [
123 - 'webhook_url' => String_Prop_Type::make()
124 - ->set_dependencies( $webhook_dependencies )
125 - ->meta( Overridable_Prop_Type::ignore() )
126 - ->default( '' ),
127 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
128 - ] );
129 -
130 - return $props;
131 109 }
132 110
133 111 protected function define_atomic_controls(): array {
134 112 $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 113 ->set_label( __( 'States', 'elementor' ) )
151 114 ->set_meta( [ 'topDivider' => true ] );
152 115
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,
116 + if ( $state_control instanceof Toggle_Control ) {
117 + $state_control
118 + ->add_options( [
119 + 'default' => [
120 + 'title' => __( 'Normal', 'elementor' ),
166 121 ],
167 - [
168 - 'label' => __( 'Webhook', 'elementor' ),
169 - 'value' => self::ACTION_WEBHOOK,
122 + 'success' => [
123 + 'title' => __( 'Success', 'elementor' ),
170 124 ],
171 - ] ) )
172 - ->set_label( __( 'Actions after submit', 'elementor' ) )
173 - ->set_meta( [ 'topDivider' => true ] ),
174 - ];
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 );
133 + }
175 134
176 135 return [
177 136 Section::make()
178 137 ->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 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 + ] ),
185 155 Chips_Control::bind_to( 'submissions_metadata' )
156 + ->set_label( __( 'Include metadata', 'elementor' ) )
157 + ->set_meta( [ 'topDivider' => true ] )
186 158 ->set_options( [
187 159 [
188 160 'label' => __( 'User IP', 'elementor' ),
189 161 'value' => self::METADATA_REMOTE_IP,
@@ -191,19 +163,15 @@
191 163 [
192 164 'label' => __( 'User Agent', 'elementor' ),
193 165 'value' => self::METADATA_USER_AGENT,
194 166 ],
195 - ] )
196 - ->set_label( __( 'Include metadata', 'elementor' ) ),
167 + ] ),
168 + Email_Form_Action_Control::bind_to( 'email' )
169 + ->set_meta( [
170 + 'topDivider' => true,
171 + ] ),
197 172 ] ),
198 173 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 174 ->set_label( __( 'Settings', 'elementor' ) )
207 175 ->set_id( 'settings' )
208 176 ->set_items( [
209 177 Text_Control::bind_to( '_cssid' )
@@ -212,18 +180,8 @@
212 180 ] ),
213 181 ];
214 182 }
215 183
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 184 protected function define_base_styles(): array {
227 185 return [
228 186 static::BASE_STYLE_KEY => Style_Definition::make()
229 187 ->add_variant(
@@ -232,10 +190,8 @@
232 190 ->add_prop( 'display', String_Prop_Type::generate( 'flex' ) )
233 191 ->add_prop( 'flex', String_Prop_Type::generate( '1' ) )
234 192 ->add_prop( 'flex-direction', String_Prop_Type::generate( 'row' ) )
235 193 ->add_prop( 'flex-wrap', String_Prop_Type::generate( 'wrap' ) )
236 - ->add_prop( 'align-items', String_Prop_Type::generate( 'flex-start' ) )
237 - ->add_prop( 'align-content', String_Prop_Type::generate( 'start' ) )
238 194 ->add_prop( 'gap', Size_Prop_Type::generate( [
239 195 'size' => 10,
240 196 'unit' => 'px',
241 197 ] ) )
@@ -271,9 +227,9 @@
271 227 protected function define_default_children() {
272 228
273 229 $prefix = 'e-form-';
274 230
275 - $children = [
231 + return [
276 232 $this->build_label( __( 'First name', 'elementor' ), $prefix . 'first-name' ),
277 233 $this->build_input( __( 'First name', 'elementor' ), 'text', $prefix . 'first-name' ),
278 234
279 235 $this->build_label( __( 'Last name', 'elementor' ), $prefix . 'last-name' ),
@@ -283,32 +239,30 @@
283 239 $this->build_input( __( '[email protected]', 'elementor' ), 'email', $prefix . 'email' ),
284 240
285 241 $this->build_label( __( 'Message', 'elementor' ), $prefix . 'message' ),
286 242 $this->build_input( __( 'Your message', 'elementor' ), 'textarea', $prefix . 'message' ),
287 - ];
288 243
289 - $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' );
244 + $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ),
290 245
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;
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 + ];
311 265 }
312 266
313 267 private function build_checkbox_row( string $label_text, string $checkbox_id ): array {
314 268 $checkbox = Widget_Builder::make( 'e-form-checkbox' )
@@ -369,9 +323,8 @@
369 323 ? Form_Success_Message::get_element_type()
370 324 : Form_Error_Message::get_element_type();
371 325
372 326 return Element_Builder::make( $element_type )
373 - ->meta( [ 'required' => true ] )
374 327 ->settings( [
375 328 'attributes' => Attributes_Prop_Type::generate( [
376 329 Key_Value_Prop_Type::generate( [] ),
377 330 ] ),
@@ -385,8 +338,9 @@
385 338 'paragraph' => $paragraph_value,
386 339 ] )
387 340 ->build(),
388 341 ] )
342 + ->is_locked( true )
389 343 ->build();
390 344 }
391 345
392 346 protected function get_templates(): array {
@@ -400,108 +354,6 @@
400 354
401 355 $context['form_state'] = 'default';
402 356
403 357 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 358 }
507 359 }