← All changes
|
modules/atomic-widgets/elements/atomic-form/atomic-form.php
+203
-81
4.1.0-dev1
→
4.3.0-beta3
View file →
| @@ -3,8 +3,9 @@ | ||
| 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; | |
| 7 | 8 | use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 8 | 9 | use Elementor\Modules\AtomicWidgets\Controls\Types\Toggle_Control; |
| 9 | 10 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph; |
| 10 | 11 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Form_Success_Message\Form_Success_Message; |
| @@ -11,17 +12,19 @@ | ||
| 11 | 12 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Form_Error_Message\Form_Error_Message; |
| 12 | 13 | use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 13 | 14 | use Elementor\Modules\AtomicWidgets\Elements\Base\Element_Builder; |
| 14 | 15 | use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; |
| 16 | +use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer; | |
| 15 | 17 | use Elementor\Modules\AtomicWidgets\Elements\Base\Widget_Builder; |
| 16 | 18 | use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 17 | 19 | use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 18 | 20 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 19 | -use Elementor\Modules\AtomicWidgets\PropTypes\Email_Prop_Type; | |
| 21 | +use Elementor\Modules\AtomicWidgets\PropTypes\Emails_Prop_Type; | |
| 20 | 22 | use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type; |
| 23 | +use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type; | |
| 21 | 24 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type; |
| 22 | 25 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 23 | -use Elementor\Modules\AtomicWidgets\PropTypes\Html_V3_Prop_Type; | |
| 26 | +use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type; | |
| 24 | 27 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Array_Prop_Type; |
| 25 | 28 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 26 | 29 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 27 | 30 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| @@ -26,8 +29,9 @@ | ||
| 26 | 29 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 27 | 30 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 28 | 31 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 29 | 32 | use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 33 | +use Elementor\Plugin; | |
| 30 | 34 | |
| 31 | 35 | if ( ! defined( 'ABSPATH' ) ) { |
| 32 | 36 | exit; // Exit if accessed directly. |
| 33 | 37 | } |
| @@ -49,8 +53,9 @@ | ||
| 49 | 53 | |
| 50 | 54 | public function __construct( $data = [], $args = null ) { |
| 51 | 55 | parent::__construct( $data, $args ); |
| 52 | 56 | $this->meta( 'is_container', true ); |
| 57 | + $this->meta( 'is_compound', true ); | |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | public static function get_default_recipient_email(): string { |
| 56 | 61 | return sanitize_email( (string) get_option( 'admin_email', '' ) ); |
| @@ -79,18 +84,17 @@ | ||
| 79 | 84 | public function get_icon() { |
| 80 | 85 | return 'eicon-atomic-form'; |
| 81 | 86 | } |
| 82 | 87 | |
| 88 | + public static function get_computed_html_tag( array $settings ): string { | |
| 89 | + return Html_Tag_Computer::compute( $settings, 'form' ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + public static function get_base_props_schema(): array { | |
| 93 | + return self::define_props_schema(); | |
| 94 | + } | |
| 95 | + | |
| 83 | 96 | 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(); | |
| 92 | - | |
| 93 | 97 | $submissions_metadata_dependencies = Dependency_Manager::make() |
| 94 | 98 | ->where( [ |
| 95 | 99 | 'operator' => 'contains', |
| 96 | 100 | 'path' => [ 'actions-after-submit' ], |
| @@ -107,18 +111,21 @@ | ||
| 107 | 111 | 'effect' => 'hide', |
| 108 | 112 | ] ) |
| 109 | 113 | ->get(); |
| 110 | 114 | |
| 111 | - return [ | |
| 115 | + $props = [ | |
| 112 | 116 | 'classes' => Classes_Prop_Type::make() |
| 113 | 117 | ->default( [] ), |
| 114 | 118 | 'form-name' => String_Prop_Type::make() |
| 115 | 119 | ->default( __( 'Form', 'elementor' ) ), |
| 120 | + 'webmcp-autosubmit' => Boolean_Prop_Type::make() | |
| 121 | + ->default( false ), | |
| 116 | 122 | 'form-state' => String_Prop_Type::make() |
| 117 | 123 | ->enum( [ 'default', 'success', 'error' ] ) |
| 118 | 124 | ->default( 'default' ) |
| 119 | 125 | ->meta( 'generates_class', 'form-state-{value}' ), |
| 120 | 126 | 'actions-after-submit' => String_Array_Prop_Type::make() |
| 127 | + ->initial_value( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ) | |
| 121 | 128 | ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ), |
| 122 | 129 | 'submissions_metadata' => String_Array_Prop_Type::make() |
| 123 | 130 | ->set_dependencies( $submissions_metadata_dependencies ) |
| 124 | 131 | ->default( [ |
| @@ -124,78 +131,83 @@ | ||
| 124 | 131 | ->default( [ |
| 125 | 132 | String_Prop_Type::generate( self::METADATA_REMOTE_IP ), |
| 126 | 133 | String_Prop_Type::generate( self::METADATA_USER_AGENT ), |
| 127 | 134 | ] ), |
| 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 | - ] ), | |
| 135 | + ]; | |
| 136 | + | |
| 137 | + $props = array_merge( $props, self::get_emails_prop_settings(), [ | |
| 135 | 138 | 'webhook_url' => String_Prop_Type::make() |
| 136 | 139 | ->set_dependencies( $webhook_dependencies ) |
| 137 | 140 | ->meta( Overridable_Prop_Type::ignore() ) |
| 138 | 141 | ->default( '' ), |
| 139 | 142 | 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 140 | - ]; | |
| 143 | + ] ); | |
| 144 | + | |
| 145 | + return $props; | |
| 141 | 146 | } |
| 142 | 147 | |
| 143 | 148 | protected function define_atomic_controls(): array { |
| 144 | 149 | $state_control = Toggle_Control::bind_to( 'form-state' ) |
| 150 | + ->add_options( [ | |
| 151 | + 'default' => [ | |
| 152 | + 'title' => __( 'Normal', 'elementor' ), | |
| 153 | + ], | |
| 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 ) | |
| 145 | 165 | ->set_label( __( 'States', 'elementor' ) ) |
| 146 | 166 | ->set_meta( [ 'topDivider' => true ] ); |
| 147 | 167 | |
| 148 | - if ( $state_control instanceof Toggle_Control ) { | |
| 149 | - $state_control | |
| 150 | - ->add_options( [ | |
| 151 | - 'default' => [ | |
| 152 | - 'title' => __( 'Normal', 'elementor' ), | |
| 168 | + $email_control_settings = $this->get_emails_control_settings(); | |
| 169 | + $form_action_chips = $email_control_settings['form-action-chips']; | |
| 170 | + $email_controls = $email_control_settings['email-controls']; | |
| 171 | + | |
| 172 | + if ( class_exists( '\ElementorPro\License\API' ) ) { | |
| 173 | + $has_form_submissions_feature = \ElementorPro\License\API::is_licence_has_feature( 'form-submissions' ); | |
| 174 | + | |
| 175 | + if ( $has_form_submissions_feature ) { | |
| 176 | + $form_action_chips = array_merge( $form_action_chips, [ | |
| 177 | + [ | |
| 178 | + 'label' => __( 'Collect submissions', 'elementor' ), | |
| 179 | + 'value' => self::ACTION_COLLECT_SUBMISSIONS, | |
| 153 | 180 | ], |
| 154 | - 'success' => [ | |
| 155 | - 'title' => __( 'Success', 'elementor' ), | |
| 181 | + ] ); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + $content_controls = [ | |
| 186 | + Text_Control::bind_to( 'form-name' ) | |
| 187 | + ->set_label( __( 'Form name', 'elementor' ) ), | |
| 188 | + $state_control, | |
| 189 | + Chips_Control::bind_to( 'actions-after-submit' ) | |
| 190 | + ->set_options( array_merge( $form_action_chips, [ | |
| 191 | + [ | |
| 192 | + 'label' => __( 'Webhook', 'elementor' ), | |
| 193 | + 'value' => self::ACTION_WEBHOOK, | |
| 156 | 194 | ], |
| 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 ); | |
| 165 | - } | |
| 195 | + ] ) ) | |
| 196 | + ->set_label( __( 'Actions after submit', 'elementor' ) ) | |
| 197 | + ->set_meta( [ 'topDivider' => true ] ), | |
| 198 | + ]; | |
| 166 | 199 | |
| 167 | 200 | return [ |
| 168 | 201 | Section::make() |
| 169 | 202 | ->set_label( __( 'Content', 'elementor' ) ) |
| 203 | + ->set_id( 'content' ) | |
| 204 | + ->set_items( $content_controls ), | |
| 205 | + ...$email_controls, | |
| 206 | + Section::make() | |
| 207 | + ->set_label( __( 'Collect submissions', 'elementor' ) ) | |
| 170 | 208 | ->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 | - ] ), | |
| 195 | 209 | Chips_Control::bind_to( 'submissions_metadata' ) |
| 196 | - ->set_label( __( 'Include metadata', 'elementor' ) ) | |
| 197 | - ->set_meta( [ 'topDivider' => true ] ) | |
| 198 | 210 | ->set_options( [ |
| 199 | 211 | [ |
| 200 | 212 | 'label' => __( 'User IP', 'elementor' ), |
| 201 | 213 | 'value' => self::METADATA_REMOTE_IP, |
| @@ -203,13 +215,17 @@ | ||
| 203 | 215 | [ |
| 204 | 216 | 'label' => __( 'User Agent', 'elementor' ), |
| 205 | 217 | 'value' => self::METADATA_USER_AGENT, |
| 206 | 218 | ], |
| 207 | - ] ), | |
| 219 | + ] ) | |
| 220 | + ->set_label( __( 'Include metadata', 'elementor' ) ), | |
| 221 | + ] ), | |
| 222 | + Section::make() | |
| 223 | + ->set_label( __( 'Webhook', 'elementor' ) ) | |
| 224 | + ->set_items( [ | |
| 208 | 225 | Text_Control::bind_to( 'webhook_url' ) |
| 209 | - ->set_label( __( 'Webhook URL', 'elementor' ) ) | |
| 210 | 226 | ->set_placeholder( __( 'https://your-webhook-url.com', 'elementor' ) ) |
| 211 | - ->set_meta( [ 'topDivider' => true ] ), | |
| 227 | + ->set_label( __( 'Webhook URL', 'elementor' ) ), | |
| 212 | 228 | ] ), |
| 213 | 229 | Section::make() |
| 214 | 230 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 215 | 231 | ->set_id( 'settings' ) |
| @@ -216,12 +232,24 @@ | ||
| 216 | 232 | ->set_items( [ |
| 217 | 233 | Text_Control::bind_to( '_cssid' ) |
| 218 | 234 | ->set_label( __( 'ID', 'elementor' ) ) |
| 219 | 235 | ->set_meta( $this->get_css_id_control_meta() ), |
| 236 | + Switch_Control::bind_to( 'webmcp-autosubmit' ) | |
| 237 | + ->set_label( __( 'Agent auto-submit', 'elementor' ) ), | |
| 220 | 238 | ] ), |
| 221 | 239 | ]; |
| 222 | 240 | } |
| 223 | 241 | |
| 242 | + protected function define_base_settings(): array { | |
| 243 | + $settings = []; | |
| 244 | + | |
| 245 | + foreach ( self::build_email_action_defaults() as $key => $default_email ) { | |
| 246 | + $settings[ $key ] = Emails_Prop_Type::generate( $default_email ); | |
| 247 | + } | |
| 248 | + | |
| 249 | + return $settings; | |
| 250 | + } | |
| 251 | + | |
| 224 | 252 | protected function define_base_styles(): array { |
| 225 | 253 | return [ |
| 226 | 254 | static::BASE_STYLE_KEY => Style_Definition::make() |
| 227 | 255 | ->add_variant( |
| @@ -261,12 +289,8 @@ | ||
| 261 | 289 | protected function define_panel_categories(): array { |
| 262 | 290 | return [ 'atomic-form' ]; |
| 263 | 291 | } |
| 264 | 292 | |
| 265 | - protected function define_default_html_tag() { | |
| 266 | - return 'form'; | |
| 267 | - } | |
| 268 | - | |
| 269 | 293 | protected function define_default_children() { |
| 270 | 294 | |
| 271 | 295 | $prefix = 'e-form-'; |
| 272 | 296 | |
| @@ -287,12 +311,9 @@ | ||
| 287 | 311 | $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ); |
| 288 | 312 | |
| 289 | 313 | $children[] = Widget_Builder::make( 'e-form-submit-button' ) |
| 290 | 314 | ->settings( [ |
| 291 | - 'text' => Html_V3_Prop_Type::generate( [ | |
| 292 | - 'content' => String_Prop_Type::generate( __( 'Submit', 'elementor' ) ), | |
| 293 | - 'children' => [], | |
| 294 | - ] ), | |
| 315 | + 'text' => Escaped_Html_Prop_Type::generate( __( 'Submit', 'elementor' ) ), | |
| 295 | 316 | ] ) |
| 296 | 317 | ->build(); |
| 297 | 318 | $children[] = $this->build_status_message( |
| 298 | 319 | __( 'Great! We’ve received your information.', 'elementor' ), |
| @@ -327,12 +348,9 @@ | ||
| 327 | 348 | |
| 328 | 349 | private function build_label( string $text, string $input_id ): array { |
| 329 | 350 | return Widget_Builder::make( 'e-form-label' ) |
| 330 | 351 | ->settings( [ |
| 331 | - 'text' => Html_V3_Prop_Type::generate( [ | |
| 332 | - 'content' => String_Prop_Type::generate( $text ), | |
| 333 | - 'children' => [], | |
| 334 | - ] ), | |
| 352 | + 'text' => Escaped_Html_Prop_Type::generate( $text ), | |
| 335 | 353 | 'input-id' => String_Prop_Type::generate( $input_id ), |
| 336 | 354 | ] ) |
| 337 | 355 | ->build(); |
| 338 | 356 | } |
| @@ -357,12 +375,9 @@ | ||
| 357 | 375 | ->build(); |
| 358 | 376 | } |
| 359 | 377 | |
| 360 | 378 | private function build_status_message( string $message, string $state, string $title ): array { |
| 361 | - $paragraph_value = Html_V3_Prop_Type::generate( [ | |
| 362 | - 'content' => String_Prop_Type::generate( $message ), | |
| 363 | - 'children' => [], | |
| 364 | - ] ); | |
| 379 | + $paragraph_value = Escaped_Html_Prop_Type::generate( $message ); | |
| 365 | 380 | |
| 366 | 381 | $element_type = 'success' === $state |
| 367 | 382 | ? Form_Success_Message::get_element_type() |
| 368 | 383 | : Form_Error_Message::get_element_type(); |
| @@ -367,8 +382,9 @@ | ||
| 367 | 382 | ? Form_Success_Message::get_element_type() |
| 368 | 383 | : Form_Error_Message::get_element_type(); |
| 369 | 384 | |
| 370 | 385 | return Element_Builder::make( $element_type ) |
| 386 | + ->meta( [ 'required' => true ] ) | |
| 371 | 387 | ->settings( [ |
| 372 | 388 | 'attributes' => Attributes_Prop_Type::generate( [ |
| 373 | 389 | Key_Value_Prop_Type::generate( [] ), |
| 374 | 390 | ] ), |
| @@ -396,11 +412,23 @@ | ||
| 396 | 412 | $context = $this->build_base_template_context(); |
| 397 | 413 | |
| 398 | 414 | $context['form_state'] = 'default'; |
| 399 | 415 | |
| 416 | + if ( ! $this->is_webmcp_enabled() ) { | |
| 417 | + return $context; | |
| 418 | + } | |
| 419 | + | |
| 420 | + $form_name = (string) ( $this->get_atomic_settings()['form-name'] ?? '' ); | |
| 421 | + $context['webmcp_tool_name'] = Webmcp_Utils::build_tool_name( $form_name, (string) $this->get_id() ); | |
| 422 | + $context['webmcp_tool_description'] = Webmcp_Utils::build_tool_description( $form_name ); | |
| 423 | + | |
| 400 | 424 | return $context; |
| 401 | 425 | } |
| 402 | 426 | |
| 427 | + private function is_webmcp_enabled(): bool { | |
| 428 | + return ! Plugin::$instance->editor->is_edit_mode(); | |
| 429 | + } | |
| 430 | + | |
| 403 | 431 | public static function is_instance_form( $instance ): bool { |
| 404 | 432 | return $instance instanceof Atomic_Form; |
| 405 | 433 | } |
| 406 | 434 | |
| @@ -405,6 +433,100 @@ | ||
| 405 | 433 | } |
| 406 | 434 | |
| 407 | 435 | public function render_markdown(): string { |
| 408 | 436 | return ''; |
| 437 | + } | |
| 438 | + | |
| 439 | + private static function get_emails_prop_settings(): array { | |
| 440 | + $props = []; | |
| 441 | + | |
| 442 | + foreach ( self::build_email_action_defaults() as $key => $default_value ) { | |
| 443 | + $props[ $key ] = Emails_Prop_Type::make() | |
| 444 | + ->set_dependencies( self::make_action_dependency( $key ) ) | |
| 445 | + ->meta( Overridable_Prop_Type::ignore() ) | |
| 446 | + ->initial_value( $default_value ) | |
| 447 | + ->default( $default_value ); | |
| 448 | + } | |
| 449 | + | |
| 450 | + return $props; | |
| 451 | + } | |
| 452 | + | |
| 453 | + private function get_emails_control_settings(): array { | |
| 454 | + $form_action_chips = []; | |
| 455 | + $email_controls = []; | |
| 456 | + | |
| 457 | + for ( $i = 0; $i < self::get_email_action_count(); $i++ ) { | |
| 458 | + $key = self::get_email_action_key( $i ); | |
| 459 | + $label = self::get_email_action_label( $i ); | |
| 460 | + | |
| 461 | + $form_action_chips[] = [ | |
| 462 | + 'label' => $label, | |
| 463 | + 'value' => $key, | |
| 464 | + ]; | |
| 465 | + | |
| 466 | + $email_controls[] = Section::make() | |
| 467 | + ->set_label( $label ) | |
| 468 | + ->set_items( [ | |
| 469 | + Email_Form_Action_Control::bind_to( $key ) | |
| 470 | + ->set_free_chips( true ) | |
| 471 | + ->set_label( $label ), | |
| 472 | + ] ); | |
| 473 | + } | |
| 474 | + | |
| 475 | + return [ | |
| 476 | + 'form-action-chips' => $form_action_chips, | |
| 477 | + 'email-controls' => $email_controls, | |
| 478 | + ]; | |
| 479 | + } | |
| 480 | + | |
| 481 | + private static function get_email_action_key( int $index ): string { | |
| 482 | + return 0 === $index | |
| 483 | + ? self::ACTION_EMAIL | |
| 484 | + : self::ACTION_EMAIL . '_' . ( $index + 1 ); | |
| 485 | + } | |
| 486 | + | |
| 487 | + private static function get_email_action_label( int $index ): string { | |
| 488 | + if ( 0 === $index ) { | |
| 489 | + return __( 'Email', 'elementor' ); | |
| 490 | + } | |
| 491 | + | |
| 492 | + // translators: %d is the index of the email action. | |
| 493 | + return sprintf( __( 'Email %d', 'elementor' ), $index + 1 ); | |
| 494 | + } | |
| 495 | + | |
| 496 | + private static function build_email_action_defaults(): array { | |
| 497 | + $defaults = []; | |
| 498 | + $default_email = self::get_default_email_value(); | |
| 499 | + | |
| 500 | + for ( $i = 0; $i < self::get_email_action_count(); $i++ ) { | |
| 501 | + $key = self::get_email_action_key( $i ); | |
| 502 | + $defaults[ $key ] = $default_email; | |
| 503 | + } | |
| 504 | + | |
| 505 | + return $defaults; | |
| 506 | + } | |
| 507 | + | |
| 508 | + private static function get_default_email_value(): array { | |
| 509 | + return [ | |
| 510 | + 'to' => String_Array_Prop_Type::generate( [ | |
| 511 | + String_Prop_Type::generate( self::get_default_recipient_email() ), | |
| 512 | + ] ), | |
| 513 | + 'from' => String_Prop_Type::generate( self::get_default_sender_email() ), | |
| 514 | + 'message' => String_Prop_Type::generate( '[all-fields]' ), | |
| 515 | + ]; | |
| 516 | + } | |
| 517 | + | |
| 518 | + private static function make_action_dependency( string $action_key ): ?array { | |
| 519 | + return Dependency_Manager::make() | |
| 520 | + ->where( [ | |
| 521 | + 'operator' => 'contains', | |
| 522 | + 'path' => [ 'actions-after-submit' ], | |
| 523 | + 'value' => $action_key, | |
| 524 | + 'effect' => 'hide', | |
| 525 | + ] ) | |
| 526 | + ->get(); | |
| 527 | + } | |
| 528 | + | |
| 529 | + private static function get_email_action_count(): int { | |
| 530 | + return apply_filters( 'elementor/atomic/form/email_action_count', 1 ); | |
| 409 | 531 | } |
| 410 | 532 | } |