← All changes
|
modules/atomic-widgets/elements/atomic-form/atomic-form.php
+34
-86
4.1.3
→
4.0.0-beta1
View file →
| @@ -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' ]; |
| @@ -84,9 +69,9 @@ | ||
| 84 | 69 | $email_dependencies = Dependency_Manager::make() |
| 85 | 70 | ->where( [ |
| 86 | 71 | 'operator' => 'contains', |
| 87 | 72 | 'path' => [ 'actions-after-submit' ], |
| 88 | - 'value' => self::ACTION_EMAIL, | |
| 73 | + 'value' => 'email', | |
| 89 | 74 | 'effect' => 'hide', |
| 90 | 75 | ] ) |
| 91 | 76 | ->get(); |
| 92 | 77 | |
| @@ -98,17 +83,8 @@ | ||
| 98 | 83 | 'effect' => 'hide', |
| 99 | 84 | ] ) |
| 100 | 85 | ->get(); |
| 101 | 86 | |
| 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 | 87 | return [ |
| 112 | 88 | 'classes' => Classes_Prop_Type::make() |
| 113 | 89 | ->default( [] ), |
| 114 | 90 | 'form-name' => String_Prop_Type::make() |
| @@ -117,9 +93,9 @@ | ||
| 117 | 93 | ->enum( [ 'default', 'success', 'error' ] ) |
| 118 | 94 | ->default( 'default' ) |
| 119 | 95 | ->meta( 'generates_class', 'form-state-{value}' ), |
| 120 | 96 | 'actions-after-submit' => String_Array_Prop_Type::make() |
| 121 | - ->default( [ String_Prop_Type::generate( self::ACTION_EMAIL ) ] ), | |
| 97 | + ->default( [ String_Prop_Type::generate( 'email' ) ] ), | |
| 122 | 98 | 'submissions_metadata' => String_Array_Prop_Type::make() |
| 123 | 99 | ->set_dependencies( $submissions_metadata_dependencies ) |
| 124 | 100 | ->default( [ |
| 125 | 101 | String_Prop_Type::generate( self::METADATA_REMOTE_IP ), |
| @@ -126,18 +102,10 @@ | ||
| 126 | 102 | String_Prop_Type::generate( self::METADATA_USER_AGENT ), |
| 127 | 103 | ] ), |
| 128 | 104 | 'email' => Email_Prop_Type::make() |
| 129 | 105 | ->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 | - 'webhook_url' => String_Prop_Type::make() | |
| 136 | - ->set_dependencies( $webhook_dependencies ) | |
| 137 | - ->meta( Overridable_Prop_Type::ignore() ) | |
| 138 | - ->default( '' ), | |
| 139 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 106 | + ->default( [] ), | |
| 107 | + 'attributes' => Attributes_Prop_Type::make(), | |
| 140 | 108 | ]; |
| 141 | 109 | } |
| 142 | 110 | |
| 143 | 111 | protected function define_atomic_controls(): array { |
| @@ -168,9 +136,9 @@ | ||
| 168 | 136 | Section::make() |
| 169 | 137 | ->set_label( __( 'Content', 'elementor' ) ) |
| 170 | 138 | ->set_items( [ |
| 171 | 139 | Text_Control::bind_to( 'form-name' ) |
| 172 | - ->set_label( __( 'Form name', 'elementor' ) ), | |
| 140 | + ->set_label( __( 'Form Name', 'elementor' ) ), | |
| 173 | 141 | $state_control, |
| 174 | 142 | Chips_Control::bind_to( 'actions-after-submit' ) |
| 175 | 143 | ->set_label( __( 'Actions after submit', 'elementor' ) ) |
| 176 | 144 | ->set_meta( [ 'topDivider' => true ] ) |
| @@ -175,24 +143,16 @@ | ||
| 175 | 143 | ->set_label( __( 'Actions after submit', 'elementor' ) ) |
| 176 | 144 | ->set_meta( [ 'topDivider' => true ] ) |
| 177 | 145 | ->set_options( [ |
| 178 | 146 | [ |
| 179 | - 'label' => __( 'Email', 'elementor' ), | |
| 180 | - 'value' => self::ACTION_EMAIL, | |
| 181 | - ], | |
| 182 | - [ | |
| 183 | 147 | 'label' => __( 'Collect submissions', 'elementor' ), |
| 184 | 148 | 'value' => self::ACTION_COLLECT_SUBMISSIONS, |
| 185 | 149 | ], |
| 186 | 150 | [ |
| 187 | - 'label' => __( 'Webhook', 'elementor' ), | |
| 188 | - 'value' => self::ACTION_WEBHOOK, | |
| 151 | + 'label' => __( 'Email', 'elementor' ), | |
| 152 | + 'value' => 'email', | |
| 189 | 153 | ], |
| 190 | 154 | ] ), |
| 191 | - Email_Form_Action_Control::bind_to( 'email' ) | |
| 192 | - ->set_meta( [ | |
| 193 | - 'topDivider' => true, | |
| 194 | - ] ), | |
| 195 | 155 | Chips_Control::bind_to( 'submissions_metadata' ) |
| 196 | 156 | ->set_label( __( 'Include metadata', 'elementor' ) ) |
| 197 | 157 | ->set_meta( [ 'topDivider' => true ] ) |
| 198 | 158 | ->set_options( [ |
| @@ -204,12 +164,12 @@ | ||
| 204 | 164 | 'label' => __( 'User Agent', 'elementor' ), |
| 205 | 165 | 'value' => self::METADATA_USER_AGENT, |
| 206 | 166 | ], |
| 207 | 167 | ] ), |
| 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 ] ), | |
| 168 | + Email_Form_Action_Control::bind_to( 'email' ) | |
| 169 | + ->set_meta( [ | |
| 170 | + 'topDivider' => true, | |
| 171 | + ] ), | |
| 212 | 172 | ] ), |
| 213 | 173 | Section::make() |
| 214 | 174 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 215 | 175 | ->set_id( 'settings' ) |
| @@ -230,10 +190,8 @@ | ||
| 230 | 190 | ->add_prop( 'display', String_Prop_Type::generate( 'flex' ) ) |
| 231 | 191 | ->add_prop( 'flex', String_Prop_Type::generate( '1' ) ) |
| 232 | 192 | ->add_prop( 'flex-direction', String_Prop_Type::generate( 'row' ) ) |
| 233 | 193 | ->add_prop( 'flex-wrap', String_Prop_Type::generate( 'wrap' ) ) |
| 234 | - ->add_prop( 'align-items', String_Prop_Type::generate( 'flex-start' ) ) | |
| 235 | - ->add_prop( 'align-content', String_Prop_Type::generate( 'start' ) ) | |
| 236 | 194 | ->add_prop( 'gap', Size_Prop_Type::generate( [ |
| 237 | 195 | 'size' => 10, |
| 238 | 196 | 'unit' => 'px', |
| 239 | 197 | ] ) ) |
| @@ -269,9 +227,9 @@ | ||
| 269 | 227 | protected function define_default_children() { |
| 270 | 228 | |
| 271 | 229 | $prefix = 'e-form-'; |
| 272 | 230 | |
| 273 | - $children = [ | |
| 231 | + return [ | |
| 274 | 232 | $this->build_label( __( 'First name', 'elementor' ), $prefix . 'first-name' ), |
| 275 | 233 | $this->build_input( __( 'First name', 'elementor' ), 'text', $prefix . 'first-name' ), |
| 276 | 234 | |
| 277 | 235 | $this->build_label( __( 'Last name', 'elementor' ), $prefix . 'last-name' ), |
| @@ -281,32 +239,30 @@ | ||
| 281 | 239 | $this->build_input( __( '[email protected]', 'elementor' ), 'email', $prefix . 'email' ), |
| 282 | 240 | |
| 283 | 241 | $this->build_label( __( 'Message', 'elementor' ), $prefix . 'message' ), |
| 284 | 242 | $this->build_input( __( 'Your message', 'elementor' ), 'textarea', $prefix . 'message' ), |
| 285 | - ]; | |
| 286 | 243 | |
| 287 | - $children[] = $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ); | |
| 244 | + $this->build_checkbox_row( __( 'Checkbox', 'elementor' ), $prefix . 'checkbox' ), | |
| 288 | 245 | |
| 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; | |
| 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 | + ]; | |
| 309 | 265 | } |
| 310 | 266 | |
| 311 | 267 | private function build_checkbox_row( string $label_text, string $checkbox_id ): array { |
| 312 | 268 | $checkbox = Widget_Builder::make( 'e-form-checkbox' ) |
| @@ -367,9 +323,8 @@ | ||
| 367 | 323 | ? Form_Success_Message::get_element_type() |
| 368 | 324 | : Form_Error_Message::get_element_type(); |
| 369 | 325 | |
| 370 | 326 | return Element_Builder::make( $element_type ) |
| 371 | - ->meta( [ 'required' => true ] ) | |
| 372 | 327 | ->settings( [ |
| 373 | 328 | 'attributes' => Attributes_Prop_Type::generate( [ |
| 374 | 329 | Key_Value_Prop_Type::generate( [] ), |
| 375 | 330 | ] ), |
| @@ -383,8 +338,9 @@ | ||
| 383 | 338 | 'paragraph' => $paragraph_value, |
| 384 | 339 | ] ) |
| 385 | 340 | ->build(), |
| 386 | 341 | ] ) |
| 342 | + ->is_locked( true ) | |
| 387 | 343 | ->build(); |
| 388 | 344 | } |
| 389 | 345 | |
| 390 | 346 | protected function get_templates(): array { |
| @@ -398,14 +354,6 @@ | ||
| 398 | 354 | |
| 399 | 355 | $context['form_state'] = 'default'; |
| 400 | 356 | |
| 401 | 357 | return $context; |
| 402 | - } | |
| 403 | - | |
| 404 | - public static function is_instance_form( $instance ): bool { | |
| 405 | - return $instance instanceof Atomic_Form; | |
| 406 | - } | |
| 407 | - | |
| 408 | - public function render_markdown(): string { | |
| 409 | - return ''; | |
| 410 | 358 | } |
| 411 | 359 | } |