PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-beta1
Elementor Website Builder – more than just a page builder v4.1.0-beta1
4.3.3 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 All 456 releases
← All changes | modules/atomic-widgets/elements/atomic-form/atomic-form.php +64 -193 4.2.2 → 4.1.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;
@@ -28,9 +26,8 @@
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 29 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
32 -use Elementor\Plugin;
33 30
34 31 if ( ! defined( 'ABSPATH' ) ) {
35 32 exit; // Exit if accessed directly.
36 33 }
@@ -82,13 +79,18 @@
82 79 public function get_icon() {
83 80 return 'eicon-atomic-form';
84 81 }
85 82
86 - public static function get_base_props_schema(): array {
87 - return self::define_props_schema();
88 - }
83 + protected static function define_props_schema(): array {
84 + $email_dependencies = Dependency_Manager::make()
85 + ->where( [
86 + 'operator' => 'contains',
87 + 'path' => [ 'actions-after-submit' ],
88 + 'value' => self::ACTION_EMAIL,
89 + 'effect' => 'hide',
90 + ] )
91 + ->get();
89 92
90 - protected static function define_props_schema(): array {
91 93 $submissions_metadata_dependencies = Dependency_Manager::make()
92 94 ->where( [
93 95 'operator' => 'contains',
94 96 'path' => [ 'actions-after-submit' ],
@@ -105,21 +107,18 @@
105 107 'effect' => 'hide',
106 108 ] )
107 109 ->get();
108 110
109 - $props = [
111 + return [
110 112 'classes' => Classes_Prop_Type::make()
111 113 ->default( [] ),
112 114 'form-name' => String_Prop_Type::make()
113 115 ->default( __( 'Form', 'elementor' ) ),
114 - 'webmcp-autosubmit' => Boolean_Prop_Type::make()
115 - ->default( false ),
116 116 'form-state' => String_Prop_Type::make()
117 117 ->enum( [ 'default', 'success', 'error' ] )
118 118 ->default( 'default' )
119 119 ->meta( 'generates_class', 'form-state-{value}' ),
120 120 'actions-after-submit' => String_Array_Prop_Type::make()
121 - ->initial_value( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] )
122 121 ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ),
123 122 'submissions_metadata' => String_Array_Prop_Type::make()
124 123 ->set_dependencies( $submissions_metadata_dependencies )
125 124 ->default( [
@@ -125,83 +124,78 @@
125 124 ->default( [
126 125 String_Prop_Type::generate( self::METADATA_REMOTE_IP ),
127 126 String_Prop_Type::generate( self::METADATA_USER_AGENT ),
128 127 ] ),
129 - ];
130 -
131 - $props = array_merge( $props, self::get_emails_prop_settings(), [
128 + 'email' => Email_Prop_Type::make()
129 + ->set_dependencies( $email_dependencies )
130 + ->meta( Overridable_Prop_Type::ignore() )
131 + ->default( [
132 + 'to' => String_Prop_Type::generate( self::get_default_recipient_email() ),
133 + 'from' => String_Prop_Type::generate( self::get_default_sender_email() ),
134 + ] ),
132 135 'webhook_url' => String_Prop_Type::make()
133 136 ->set_dependencies( $webhook_dependencies )
134 137 ->meta( Overridable_Prop_Type::ignore() )
135 138 ->default( '' ),
136 139 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
137 - ] );
138 -
139 - return $props;
140 + ];
140 141 }
141 142
142 143 protected function define_atomic_controls(): array {
143 144 $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 145 ->set_label( __( 'States', 'elementor' ) )
160 146 ->set_meta( [ 'topDivider' => true ] );
161 147
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,
148 + if ( $state_control instanceof Toggle_Control ) {
149 + $state_control
150 + ->add_options( [
151 + 'default' => [
152 + 'title' => __( 'Normal', 'elementor' ),
174 153 ],
175 - ] );
176 - }
154 + 'success' => [
155 + 'title' => __( 'Success', 'elementor' ),
156 + ],
157 + 'error' => [
158 + 'title' => __( 'Error', 'elementor' ),
159 + ],
160 + ] )
161 + ->set_exclusive( true )
162 + ->set_convert_options( true )
163 + ->set_size( 'tiny' )
164 + ->set_full_width( true );
177 165 }
178 166
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 167 return [
195 168 Section::make()
196 169 ->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 170 ->set_items( [
171 + Text_Control::bind_to( 'form-name' )
172 + ->set_label( __( 'Form name', 'elementor' ) ),
173 + $state_control,
174 + Chips_Control::bind_to( 'actions-after-submit' )
175 + ->set_label( __( 'Actions after submit', 'elementor' ) )
176 + ->set_meta( [ 'topDivider' => true ] )
177 + ->set_options( [
178 + [
179 + 'label' => __( 'Email', 'elementor' ),
180 + 'value' => self::ACTION_EMAIL,
181 + ],
182 + [
183 + 'label' => __( 'Collect submissions', 'elementor' ),
184 + 'value' => self::ACTION_COLLECT_SUBMISSIONS,
185 + ],
186 + [
187 + 'label' => __( 'Webhook', 'elementor' ),
188 + 'value' => self::ACTION_WEBHOOK,
189 + ],
190 + ] ),
191 + Email_Form_Action_Control::bind_to( 'email' )
192 + ->set_meta( [
193 + 'topDivider' => true,
194 + ] ),
203 195 Chips_Control::bind_to( 'submissions_metadata' )
196 + ->set_label( __( 'Include metadata', 'elementor' ) )
197 + ->set_meta( [ 'topDivider' => true ] )
204 198 ->set_options( [
205 199 [
206 200 'label' => __( 'User IP', 'elementor' ),
207 201 'value' => self::METADATA_REMOTE_IP,
@@ -209,17 +203,13 @@
209 203 [
210 204 'label' => __( 'User Agent', 'elementor' ),
211 205 'value' => self::METADATA_USER_AGENT,
212 206 ],
213 - ] )
214 - ->set_label( __( 'Include metadata', 'elementor' ) ),
215 - ] ),
216 - Section::make()
217 - ->set_label( __( 'Webhook', 'elementor' ) )
218 - ->set_items( [
207 + ] ),
219 208 Text_Control::bind_to( 'webhook_url' )
209 + ->set_label( __( 'Webhook URL', 'elementor' ) )
220 210 ->set_placeholder( __( 'https://your-webhook-url.com', 'elementor' ) )
221 - ->set_label( __( 'Webhook URL', 'elementor' ) ),
211 + ->set_meta( [ 'topDivider' => true ] ),
222 212 ] ),
223 213 Section::make()
224 214 ->set_label( __( 'Settings', 'elementor' ) )
225 215 ->set_id( 'settings' )
@@ -226,24 +216,12 @@
226 216 ->set_items( [
227 217 Text_Control::bind_to( '_cssid' )
228 218 ->set_label( __( 'ID', 'elementor' ) )
229 219 ->set_meta( $this->get_css_id_control_meta() ),
230 - Switch_Control::bind_to( 'webmcp-autosubmit' )
231 - ->set_label( __( 'Agent auto-submit', 'elementor' ) ),
232 220 ] ),
233 221 ];
234 222 }
235 223
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 224 protected function define_base_styles(): array {
247 225 return [
248 226 static::BASE_STYLE_KEY => Style_Definition::make()
249 227 ->add_variant(
@@ -389,9 +367,8 @@
389 367 ? Form_Success_Message::get_element_type()
390 368 : Form_Error_Message::get_element_type();
391 369
392 370 return Element_Builder::make( $element_type )
393 - ->meta( [ 'required' => true ] )
394 371 ->settings( [
395 372 'attributes' => Attributes_Prop_Type::generate( [
396 373 Key_Value_Prop_Type::generate( [] ),
397 374 ] ),
@@ -419,23 +396,11 @@
419 396 $context = $this->build_base_template_context();
420 397
421 398 $context['form_state'] = 'default';
422 399
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 400 return $context;
432 401 }
433 402
434 - private function is_webmcp_enabled(): bool {
435 - return ! Plugin::$instance->editor->is_edit_mode();
436 - }
437 -
438 403 public static function is_instance_form( $instance ): bool {
439 404 return $instance instanceof Atomic_Form;
440 405 }
441 406
@@ -440,100 +405,6 @@
440 405 }
441 406
442 407 public function render_markdown(): string {
443 408 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 409 }
539 410 }