false, ]; } /** * List of keys of the default fields we want to display on the builder. * * @since 2.0.0 * @return array */ public function default_fields() { return [ 'name', 'placeholder', 'tooltip', ]; } /** * If you want to force a particular attribute to a value, declare it here. * * @since 2.0.0 * @return array */ public function force_attributes() { return [ 'id' => 'username', 'required' => true, ]; } /** * Returns the list of additional fields specific to this type. * * @since 2.0.0 * @return array */ public function get_fields() { return [ 'auto_generate_username' => [ 'type' => 'toggle', 'title' => __('Auto-generate', 'wp-multisite-waas'), 'desc' => __('Check this option to auto-generate this field based on the email address of the customer.', 'wp-multisite-waas'), 'tooltip' => '', 'value' => 0, 'html_attr' => [ 'v-model' => 'auto_generate_username', ], ], ]; } /** * Returns the field/element actual field array to be used on the checkout form. * * @since 2.0.0 * * @param array $attributes Attributes saved on the editor form. * @return array An array of fields, not the field itself. */ public function to_fields_array($attributes) { /* * Logged in user, bail. */ if (is_user_logged_in()) { return []; } if (isset($attributes['auto_generate_username']) && $attributes['auto_generate_username']) { return [ 'auto_generate_username' => [ 'type' => 'hidden', 'id' => 'auto_generate_username', 'value' => 'email', ], 'username' => [ 'type' => 'hidden', 'id' => 'username', 'value' => uniqid(), ], ]; } return [ 'username' => [ 'type' => 'text', 'id' => 'username', 'name' => $attributes['name'], 'placeholder' => $attributes['placeholder'], 'tooltip' => $attributes['tooltip'], 'wrapper_classes' => wu_get_isset($attributes, 'wrapper_element_classes', ''), 'classes' => wu_get_isset($attributes, 'element_classes', ''), 'required' => true, 'value' => $this->get_value(), 'html_attr' => [ 'v-model' => 'username', 'v-init:username' => "'{$this->get_value()}'", 'autocomplete' => 'username', ], 'wrapper_html_attr' => [ 'style' => $this->calculate_style_attr(), ], ], ]; } }