← All changes
|
modules/atomic-widgets/elements/atomic-form/atomic-form.php
+85
-254
4.3.0-beta3
→
4.0.9
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; |
| @@ -12,19 +11,17 @@ | ||
| 12 | 11 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Form_Error_Message\Form_Error_Message; |
| 13 | 12 | use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 14 | 13 | use Elementor\Modules\AtomicWidgets\Elements\Base\Element_Builder; |
| 15 | 14 | use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; |
| 16 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer; | |
| 17 | 15 | use Elementor\Modules\AtomicWidgets\Elements\Base\Widget_Builder; |
| 18 | 16 | use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 19 | 17 | use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 20 | 18 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 21 | -use Elementor\Modules\AtomicWidgets\PropTypes\Emails_Prop_Type; | |
| 19 | +use Elementor\Modules\AtomicWidgets\PropTypes\Email_Prop_Type; | |
| 22 | 20 | use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type; |
| 23 | -use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type; | |
| 24 | 21 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type; |
| 25 | 22 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 26 | -use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type; | |
| 23 | +use Elementor\Modules\AtomicWidgets\PropTypes\Html_V3_Prop_Type; | |
| 27 | 24 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Array_Prop_Type; |
| 28 | 25 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 29 | 26 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 30 | 27 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| @@ -29,9 +26,8 @@ | ||
| 29 | 26 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 30 | 27 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 31 | 28 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 32 | 29 | use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 33 | -use Elementor\Plugin; | |
| 34 | 30 | |
| 35 | 31 | if ( ! defined( 'ABSPATH' ) ) { |
| 36 | 32 | exit; // Exit if accessed directly. |
| 37 | 33 | } |
| @@ -40,32 +36,17 @@ | ||
| 40 | 36 | use Has_Element_Template; |
| 41 | 37 | |
| 42 | 38 | const BASE_STYLE_KEY = 'base'; |
| 43 | 39 | |
| 44 | - public static $widget_description = 'A form container that holds form field widgets (labels, inputs, textareas, checkboxes, submit button) and status messages.'; | |
| 45 | - | |
| 46 | - public const ACTION_EMAIL = 'email'; | |
| 47 | 40 | public const ACTION_COLLECT_SUBMISSIONS = 'collect-submissions'; |
| 48 | - public const ACTION_WEBHOOK = 'webhook'; | |
| 49 | 41 | public const METADATA_REMOTE_IP = 'remote_ip'; |
| 50 | 42 | public const METADATA_USER_AGENT = 'user_agent'; |
| 51 | 43 | |
| 52 | - | |
| 53 | - | |
| 54 | 44 | public function __construct( $data = [], $args = null ) { |
| 55 | 45 | parent::__construct( $data, $args ); |
| 56 | 46 | $this->meta( 'is_container', true ); |
| 57 | - $this->meta( 'is_compound', true ); | |
| 58 | 47 | } |
| 59 | 48 | |
| 60 | - public static function get_default_recipient_email(): string { | |
| 61 | - return sanitize_email( (string) get_option( 'admin_email', '' ) ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - public static function get_default_sender_email(): string { | |
| 65 | - return sanitize_email( (string) 'email@' . wp_parse_url( home_url(), PHP_URL_HOST ) ); | |
| 66 | - } | |
| 67 | - | |
| 68 | 49 | public static function get_type() { |
| 69 | 50 | return 'e-form'; |
| 70 | 51 | } |
| 71 | 52 | |
| @@ -84,49 +65,38 @@ | ||
| 84 | 65 | public function get_icon() { |
| 85 | 66 | return 'eicon-atomic-form'; |
| 86 | 67 | } |
| 87 | 68 | |
| 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 | - | |
| 96 | 69 | protected static function define_props_schema(): array { |
| 97 | - $submissions_metadata_dependencies = Dependency_Manager::make() | |
| 70 | + $email_dependencies = Dependency_Manager::make() | |
| 98 | 71 | ->where( [ |
| 99 | 72 | 'operator' => 'contains', |
| 100 | 73 | 'path' => [ 'actions-after-submit' ], |
| 101 | - 'value' => self::ACTION_COLLECT_SUBMISSIONS, | |
| 74 | + 'value' => 'email', | |
| 102 | 75 | 'effect' => 'hide', |
| 103 | 76 | ] ) |
| 104 | 77 | ->get(); |
| 105 | 78 | |
| 106 | - $webhook_dependencies = Dependency_Manager::make() | |
| 79 | + $submissions_metadata_dependencies = Dependency_Manager::make() | |
| 107 | 80 | ->where( [ |
| 108 | 81 | 'operator' => 'contains', |
| 109 | 82 | 'path' => [ 'actions-after-submit' ], |
| 110 | - 'value' => self::ACTION_WEBHOOK, | |
| 83 | + 'value' => self::ACTION_COLLECT_SUBMISSIONS, | |
| 111 | 84 | 'effect' => 'hide', |
| 112 | 85 | ] ) |
| 113 | 86 | ->get(); |
| 114 | 87 | |
| 115 | - $props = [ | |
| 88 | + return [ | |
| 116 | 89 | 'classes' => Classes_Prop_Type::make() |
| 117 | 90 | ->default( [] ), |
| 118 | 91 | 'form-name' => String_Prop_Type::make() |
| 119 | 92 | ->default( __( 'Form', 'elementor' ) ), |
| 120 | - 'webmcp-autosubmit' => Boolean_Prop_Type::make() | |
| 121 | - ->default( false ), | |
| 122 | 93 | 'form-state' => String_Prop_Type::make() |
| 123 | 94 | ->enum( [ 'default', 'success', 'error' ] ) |
| 124 | 95 | ->default( 'default' ) |
| 125 | 96 | ->meta( 'generates_class', 'form-state-{value}' ), |
| 126 | 97 | 'actions-after-submit' => String_Array_Prop_Type::make() |
| 127 | - ->initial_value( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ) | |
| 128 | - ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ), | |
| 98 | + ->default( [ String_Prop_Type::generate( 'email' ) ] ), | |
| 129 | 99 | 'submissions_metadata' => String_Array_Prop_Type::make() |
| 130 | 100 | ->set_dependencies( $submissions_metadata_dependencies ) |
| 131 | 101 | ->default( [ |
| 132 | 102 | String_Prop_Type::generate( self::METADATA_REMOTE_IP ), |
| @@ -131,83 +101,63 @@ | ||
| 131 | 101 | ->default( [ |
| 132 | 102 | String_Prop_Type::generate( self::METADATA_REMOTE_IP ), |
| 133 | 103 | String_Prop_Type::generate( self::METADATA_USER_AGENT ), |
| 134 | 104 | ] ), |
| 135 | - ]; | |
| 136 | - | |
| 137 | - $props = array_merge( $props, self::get_emails_prop_settings(), [ | |
| 138 | - 'webhook_url' => String_Prop_Type::make() | |
| 139 | - ->set_dependencies( $webhook_dependencies ) | |
| 105 | + 'email' => Email_Prop_Type::make() | |
| 106 | + ->set_dependencies( $email_dependencies ) | |
| 140 | 107 | ->meta( Overridable_Prop_Type::ignore() ) |
| 141 | - ->default( '' ), | |
| 108 | + ->default( [] ), | |
| 142 | 109 | 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 143 | - ] ); | |
| 144 | - | |
| 145 | - return $props; | |
| 110 | + ]; | |
| 146 | 111 | } |
| 147 | 112 | |
| 148 | 113 | protected function define_atomic_controls(): array { |
| 149 | 114 | $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 ) | |
| 165 | 115 | ->set_label( __( 'States', 'elementor' ) ) |
| 166 | 116 | ->set_meta( [ 'topDivider' => true ] ); |
| 167 | 117 | |
| 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, | |
| 118 | + if ( $state_control instanceof Toggle_Control ) { | |
| 119 | + $state_control | |
| 120 | + ->add_options( [ | |
| 121 | + 'default' => [ | |
| 122 | + 'title' => __( 'Normal', 'elementor' ), | |
| 180 | 123 | ], |
| 181 | - ] ); | |
| 182 | - } | |
| 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 ); | |
| 183 | 135 | } |
| 184 | 136 | |
| 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, | |
| 194 | - ], | |
| 195 | - ] ) ) | |
| 196 | - ->set_label( __( 'Actions after submit', 'elementor' ) ) | |
| 197 | - ->set_meta( [ 'topDivider' => true ] ), | |
| 198 | - ]; | |
| 199 | - | |
| 200 | 137 | return [ |
| 201 | 138 | Section::make() |
| 202 | 139 | ->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' ) ) | |
| 208 | 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 | + ] ), | |
| 209 | 157 | Chips_Control::bind_to( 'submissions_metadata' ) |
| 158 | + ->set_label( __( 'Include metadata', 'elementor' ) ) | |
| 159 | + ->set_meta( [ 'topDivider' => true ] ) | |
| 210 | 160 | ->set_options( [ |
| 211 | 161 | [ |
| 212 | 162 | 'label' => __( 'User IP', 'elementor' ), |
| 213 | 163 | 'value' => self::METADATA_REMOTE_IP, |
| @@ -215,19 +165,15 @@ | ||
| 215 | 165 | [ |
| 216 | 166 | 'label' => __( 'User Agent', 'elementor' ), |
| 217 | 167 | 'value' => self::METADATA_USER_AGENT, |
| 218 | 168 | ], |
| 219 | - ] ) | |
| 220 | - ->set_label( __( 'Include metadata', 'elementor' ) ), | |
| 169 | + ] ), | |
| 170 | + Email_Form_Action_Control::bind_to( 'email' ) | |
| 171 | + ->set_meta( [ | |
| 172 | + 'topDivider' => true, | |
| 173 | + ] ), | |
| 221 | 174 | ] ), |
| 222 | 175 | Section::make() |
| 223 | - ->set_label( __( 'Webhook', 'elementor' ) ) | |
| 224 | - ->set_items( [ | |
| 225 | - Text_Control::bind_to( 'webhook_url' ) | |
| 226 | - ->set_placeholder( __( 'https://your-webhook-url.com', 'elementor' ) ) | |
| 227 | - ->set_label( __( 'Webhook URL', 'elementor' ) ), | |
| 228 | - ] ), | |
| 229 | - Section::make() | |
| 230 | 176 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 231 | 177 | ->set_id( 'settings' ) |
| 232 | 178 | ->set_items( [ |
| 233 | 179 | Text_Control::bind_to( '_cssid' ) |
| @@ -232,24 +178,12 @@ | ||
| 232 | 178 | ->set_items( [ |
| 233 | 179 | Text_Control::bind_to( '_cssid' ) |
| 234 | 180 | ->set_label( __( 'ID', 'elementor' ) ) |
| 235 | 181 | ->set_meta( $this->get_css_id_control_meta() ), |
| 236 | - Switch_Control::bind_to( 'webmcp-autosubmit' ) | |
| 237 | - ->set_label( __( 'Agent auto-submit', 'elementor' ) ), | |
| 238 | 182 | ] ), |
| 239 | 183 | ]; |
| 240 | 184 | } |
| 241 | 185 | |
| 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 | - | |
| 252 | 186 | protected function define_base_styles(): array { |
| 253 | 187 | return [ |
| 254 | 188 | static::BASE_STYLE_KEY => Style_Definition::make() |
| 255 | 189 | ->add_variant( |
| @@ -289,13 +223,17 @@ | ||
| 289 | 223 | protected function define_panel_categories(): array { |
| 290 | 224 | return [ 'atomic-form' ]; |
| 291 | 225 | } |
| 292 | 226 | |
| 227 | + protected function define_default_html_tag() { | |
| 228 | + return 'form'; | |
| 229 | + } | |
| 230 | + | |
| 293 | 231 | protected function define_default_children() { |
| 294 | 232 | |
| 295 | 233 | $prefix = 'e-form-'; |
| 296 | 234 | |
| 297 | - $children = [ | |
| 235 | + return [ | |
| 298 | 236 | $this->build_label( __( 'First name', 'elementor' ), $prefix . 'first-name' ), |
| 299 | 237 | $this->build_input( __( 'First name', 'elementor' ), 'text', $prefix . 'first-name' ), |
| 300 | 238 | |
| 301 | 239 | $this->build_label( __( 'Last name', 'elementor' ), $prefix . 'last-name' ), |
| @@ -305,29 +243,30 @@ | ||
| 305 | 243 | $this->build_input( __( 'your@mail.com', 'elementor' ), 'email', $prefix . 'email' ), |
| 306 | 244 | |
| 307 | 245 | $this->build_label( __( 'Message', 'elementor' ), $prefix . 'message' ), |
| 308 | 246 | $this->build_input( __( 'Your message', 'elementor' ), 'textarea', $prefix . 'message' ), |
| 309 | - ]; | |
| 310 | 247 | |
| 311 | - $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ); | |
| 248 | + $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ), | |
| 312 | 249 | |
| 313 | - $children[] = Widget_Builder::make( 'e-form-submit-button' ) | |
| 314 | - ->settings( [ | |
| 315 | - 'text' => Escaped_Html_Prop_Type::generate( __( 'Submit', 'elementor' ) ), | |
| 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' ) |
| @@ -348,9 +287,12 @@ | ||
| 348 | 287 | |
| 349 | 288 | private function build_label( string $text, string $input_id ): array { |
| 350 | 289 | return Widget_Builder::make( 'e-form-label' ) |
| 351 | 290 | ->settings( [ |
| 352 | - 'text' => Escaped_Html_Prop_Type::generate( $text ), | |
| 291 | + 'text' => Html_V3_Prop_Type::generate( [ | |
| 292 | + 'content' => String_Prop_Type::generate( $text ), | |
| 293 | + 'children' => [], | |
| 294 | + ] ), | |
| 353 | 295 | 'input-id' => String_Prop_Type::generate( $input_id ), |
| 354 | 296 | ] ) |
| 355 | 297 | ->build(); |
| 356 | 298 | } |
| @@ -375,9 +317,12 @@ | ||
| 375 | 317 | ->build(); |
| 376 | 318 | } |
| 377 | 319 | |
| 378 | 320 | private function build_status_message( string $message, string $state, string $title ): array { |
| 379 | - $paragraph_value = Escaped_Html_Prop_Type::generate( $message ); | |
| 321 | + $paragraph_value = Html_V3_Prop_Type::generate( [ | |
| 322 | + 'content' => String_Prop_Type::generate( $message ), | |
| 323 | + 'children' => [], | |
| 324 | + ] ); | |
| 380 | 325 | |
| 381 | 326 | $element_type = 'success' === $state |
| 382 | 327 | ? Form_Success_Message::get_element_type() |
| 383 | 328 | : Form_Error_Message::get_element_type(); |
| @@ -382,9 +327,8 @@ | ||
| 382 | 327 | ? Form_Success_Message::get_element_type() |
| 383 | 328 | : Form_Error_Message::get_element_type(); |
| 384 | 329 | |
| 385 | 330 | return Element_Builder::make( $element_type ) |
| 386 | - ->meta( [ 'required' => true ] ) | |
| 387 | 331 | ->settings( [ |
| 388 | 332 | 'attributes' => Attributes_Prop_Type::generate( [ |
| 389 | 333 | Key_Value_Prop_Type::generate( [] ), |
| 390 | 334 | ] ), |
| @@ -398,8 +342,9 @@ | ||
| 398 | 342 | 'paragraph' => $paragraph_value, |
| 399 | 343 | ] ) |
| 400 | 344 | ->build(), |
| 401 | 345 | ] ) |
| 346 | + ->is_locked( true ) | |
| 402 | 347 | ->build(); |
| 403 | 348 | } |
| 404 | 349 | |
| 405 | 350 | protected function get_templates(): array { |
| @@ -412,121 +357,7 @@ | ||
| 412 | 357 | $context = $this->build_base_template_context(); |
| 413 | 358 | |
| 414 | 359 | $context['form_state'] = 'default'; |
| 415 | 360 | |
| 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 | - | |
| 424 | 361 | return $context; |
| 425 | - } | |
| 426 | - | |
| 427 | - private function is_webmcp_enabled(): bool { | |
| 428 | - return ! Plugin::$instance->editor->is_edit_mode(); | |
| 429 | - } | |
| 430 | - | |
| 431 | - public static function is_instance_form( $instance ): bool { | |
| 432 | - return $instance instanceof Atomic_Form; | |
| 433 | - } | |
| 434 | - | |
| 435 | - public function render_markdown(): string { | |
| 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 ); | |
| 531 | 362 | } |
| 532 | 363 | } |