← All changes
|
modules/atomic-widgets/elements/atomic-form/atomic-form.php
+31
-78
4.1.0-beta2
→
4.0.0-dev3
View file →
| @@ -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 | |
| @@ -84,9 +70,9 @@ | ||
| 84 | 70 | $email_dependencies = Dependency_Manager::make() |
| 85 | 71 | ->where( [ |
| 86 | 72 | 'operator' => 'contains', |
| 87 | 73 | 'path' => [ 'actions-after-submit' ], |
| 88 | - 'value' => self::ACTION_EMAIL, | |
| 74 | + 'value' => 'email', | |
| 89 | 75 | 'effect' => 'hide', |
| 90 | 76 | ] ) |
| 91 | 77 | ->get(); |
| 92 | 78 | |
| @@ -98,17 +84,8 @@ | ||
| 98 | 84 | 'effect' => 'hide', |
| 99 | 85 | ] ) |
| 100 | 86 | ->get(); |
| 101 | 87 | |
| 102 | - $webhook_dependencies = Dependency_Manager::make() | |
| 103 | - ->where( [ | |
| 104 | - 'operator' => 'contains', | |
| 105 | - 'path' => [ 'actions-after-submit' ], | |
| 106 | - 'value' => self::ACTION_WEBHOOK, | |
| 107 | - 'effect' => 'hide', | |
| 108 | - ] ) | |
| 109 | - ->get(); | |
| 110 | - | |
| 111 | 88 | return [ |
| 112 | 89 | 'classes' => Classes_Prop_Type::make() |
| 113 | 90 | ->default( [] ), |
| 114 | 91 | 'form-name' => String_Prop_Type::make() |
| @@ -117,9 +94,9 @@ | ||
| 117 | 94 | ->enum( [ 'default', 'success', 'error' ] ) |
| 118 | 95 | ->default( 'default' ) |
| 119 | 96 | ->meta( 'generates_class', 'form-state-{value}' ), |
| 120 | 97 | 'actions-after-submit' => String_Array_Prop_Type::make() |
| 121 | - ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ), | |
| 98 | + ->default( [ String_Prop_Type::generate( 'email' ) ] ), | |
| 122 | 99 | 'submissions_metadata' => String_Array_Prop_Type::make() |
| 123 | 100 | ->set_dependencies( $submissions_metadata_dependencies ) |
| 124 | 101 | ->default( [ |
| 125 | 102 | String_Prop_Type::generate( self::METADATA_REMOTE_IP ), |
| @@ -127,16 +104,9 @@ | ||
| 127 | 104 | ] ), |
| 128 | 105 | 'email' => Email_Prop_Type::make() |
| 129 | 106 | ->set_dependencies( $email_dependencies ) |
| 130 | 107 | ->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 | - 'webhook_url' => String_Prop_Type::make() | |
| 136 | - ->set_dependencies( $webhook_dependencies ) | |
| 137 | - ->meta( Overridable_Prop_Type::ignore() ) | |
| 138 | - ->default( '' ), | |
| 108 | + ->default( [] ), | |
| 139 | 109 | 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 140 | 110 | ]; |
| 141 | 111 | } |
| 142 | 112 | |
| @@ -175,24 +145,16 @@ | ||
| 175 | 145 | ->set_label( __( 'Actions after submit', 'elementor' ) ) |
| 176 | 146 | ->set_meta( [ 'topDivider' => true ] ) |
| 177 | 147 | ->set_options( [ |
| 178 | 148 | [ |
| 179 | - 'label' => __( 'Email', 'elementor' ), | |
| 180 | - 'value' => self::ACTION_EMAIL, | |
| 181 | - ], | |
| 182 | - [ | |
| 183 | 149 | 'label' => __( 'Collect submissions', 'elementor' ), |
| 184 | 150 | 'value' => self::ACTION_COLLECT_SUBMISSIONS, |
| 185 | 151 | ], |
| 186 | 152 | [ |
| 187 | - 'label' => __( 'Webhook', 'elementor' ), | |
| 188 | - 'value' => self::ACTION_WEBHOOK, | |
| 153 | + 'label' => __( 'Email', 'elementor' ), | |
| 154 | + 'value' => 'email', | |
| 189 | 155 | ], |
| 190 | 156 | ] ), |
| 191 | - Email_Form_Action_Control::bind_to( 'email' ) | |
| 192 | - ->set_meta( [ | |
| 193 | - 'topDivider' => true, | |
| 194 | - ] ), | |
| 195 | 157 | Chips_Control::bind_to( 'submissions_metadata' ) |
| 196 | 158 | ->set_label( __( 'Include metadata', 'elementor' ) ) |
| 197 | 159 | ->set_meta( [ 'topDivider' => true ] ) |
| 198 | 160 | ->set_options( [ |
| @@ -204,12 +166,12 @@ | ||
| 204 | 166 | 'label' => __( 'User Agent', 'elementor' ), |
| 205 | 167 | 'value' => self::METADATA_USER_AGENT, |
| 206 | 168 | ], |
| 207 | 169 | ] ), |
| 208 | - Text_Control::bind_to( 'webhook_url' ) | |
| 209 | - ->set_label( __( 'Webhook URL', 'elementor' ) ) | |
| 210 | - ->set_placeholder( __( 'https://your-webhook-url.com', 'elementor' ) ) | |
| 211 | - ->set_meta( [ 'topDivider' => true ] ), | |
| 170 | + Email_Form_Action_Control::bind_to( 'email' ) | |
| 171 | + ->set_meta( [ | |
| 172 | + 'topDivider' => true, | |
| 173 | + ] ), | |
| 212 | 174 | ] ), |
| 213 | 175 | Section::make() |
| 214 | 176 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 215 | 177 | ->set_id( 'settings' ) |
| @@ -269,9 +231,9 @@ | ||
| 269 | 231 | protected function define_default_children() { |
| 270 | 232 | |
| 271 | 233 | $prefix = 'e-form-'; |
| 272 | 234 | |
| 273 | - $children = [ | |
| 235 | + return [ | |
| 274 | 236 | $this->build_label( __( 'First name', 'elementor' ), $prefix . 'first-name' ), |
| 275 | 237 | $this->build_input( __( 'First name', 'elementor' ), 'text', $prefix . 'first-name' ), |
| 276 | 238 | |
| 277 | 239 | $this->build_label( __( 'Last name', 'elementor' ), $prefix . 'last-name' ), |
| @@ -281,32 +243,30 @@ | ||
| 281 | 243 | $this->build_input( __( '[email protected]', 'elementor' ), 'email', $prefix . 'email' ), |
| 282 | 244 | |
| 283 | 245 | $this->build_label( __( 'Message', 'elementor' ), $prefix . 'message' ), |
| 284 | 246 | $this->build_input( __( 'Your message', 'elementor' ), 'textarea', $prefix . 'message' ), |
| 285 | - ]; | |
| 286 | 247 | |
| 287 | - $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ); | |
| 248 | + $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ), | |
| 288 | 249 | |
| 289 | - $children[] = Widget_Builder::make( 'e-form-submit-button' ) | |
| 290 | - ->settings( [ | |
| 291 | - 'text' => Html_V3_Prop_Type::generate( [ | |
| 292 | - 'content' => String_Prop_Type::generate( __( 'Submit', 'elementor' ) ), | |
| 293 | - 'children' => [], | |
| 294 | - ] ), | |
| 295 | - ] ) | |
| 296 | - ->build(); | |
| 297 | - $children[] = $this->build_status_message( | |
| 298 | - __( 'Great! We’ve received your information.', 'elementor' ), | |
| 299 | - 'success', | |
| 300 | - __( 'Success message', 'elementor' ) | |
| 301 | - ); | |
| 302 | - $children[] = $this->build_status_message( | |
| 303 | - __( 'We couldn’t process your submission. Please retry', 'elementor' ), | |
| 304 | - 'error', | |
| 305 | - __( 'Error message', 'elementor' ) | |
| 306 | - ); | |
| 307 | - | |
| 308 | - 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 | + ]; | |
| 309 | 269 | } |
| 310 | 270 | |
| 311 | 271 | private function build_checkbox_row( string $label_text, string $checkbox_id ): array { |
| 312 | 272 | $checkbox = Widget_Builder::make( 'e-form-checkbox' ) |
| @@ -382,8 +342,9 @@ | ||
| 382 | 342 | 'paragraph' => $paragraph_value, |
| 383 | 343 | ] ) |
| 384 | 344 | ->build(), |
| 385 | 345 | ] ) |
| 346 | + ->is_locked( true ) | |
| 386 | 347 | ->build(); |
| 387 | 348 | } |
| 388 | 349 | |
| 389 | 350 | protected function get_templates(): array { |
| @@ -397,14 +358,6 @@ | ||
| 397 | 358 | |
| 398 | 359 | $context['form_state'] = 'default'; |
| 399 | 360 | |
| 400 | 361 | return $context; |
| 401 | - } | |
| 402 | - | |
| 403 | - public static function is_instance_form( $instance ): bool { | |
| 404 | - return $instance instanceof Atomic_Form; | |
| 405 | - } | |
| 406 | - | |
| 407 | - public function render_markdown(): string { | |
| 408 | - return ''; | |
| 409 | 362 | } |
| 410 | 363 | } |