/home/techb158/balacoffee.com/wp-content/plugins/wpforms/src/Pro/Forms/Fields/Layout
NameSizeModeActions
Builder.php127010644editdlrm
Frontend.php49060644editdlrm
Edit: /home/techb158/balacoffee.com/wp-content/plugins/wpforms/src/Pro/Forms/Fields/Layout/Builder.php (12701B)
field_obj = $field_obj; $this->hooks(); } /** * Register hooks. * * @since 1.7.7 */ private function hooks() { add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] ); add_filter( 'wpforms_save_form_args', [ $this, 'save_form_args' ], 20, 3 ); add_filter( 'wpforms_builder_panel_fields_preview_fields', [ $this->field_obj, 'filter_base_fields' ] ); add_filter( 'wpforms_builder_strings', [ $this, 'get_localized_strings' ], 10, 2 ); add_filter( 'wpforms_field_new_class', [ $this, 'preview_field_new_class' ], 10, 2 ); add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'field_preview_column_plus_placeholder_template' ] ); } /** * Enqueue assets. * * @since 1.7.7 */ public function enqueues() { $min = wpforms_get_min_suffix(); wp_enqueue_script( 'wpforms-builder-field-layout', WPFORMS_PLUGIN_URL . "assets/pro/js/admin/builder/layout{$min}.js", [ 'wpforms-builder' ], WPFORMS_VERSION, true ); } /** * Field options panel inside the builder. * * @since 1.7.7 * * @param array $field Field settings. */ public function field_options( $field ) { $this->field_option_columns_json( $field ); // Options open markup. $this->field_obj->field_option( 'basic-options', $field, [ 'markup' => 'open', ] ); $this->field_obj->field_option( 'label', $field, [ 'tooltip' => esc_html__( 'Enter text for the Layout field label. It will help identify your layout block inside the form builder, but will not be displayed in the form.', 'wpforms' ), ] ); $this->field_option_preset_selector( $field ); // Options close markup. $this->field_obj->field_option( 'basic-options', $field, [ 'markup' => 'close', ] ); } /** * Columns JSON hidden field option. * * @since 1.7.7 * * @param array $field Field settings. */ private function field_option_columns_json( $field ) { printf( '', (int) $field['id'], esc_attr( wp_json_encode( isset( $field['columns'] ) ? $field['columns'] : $this->field_obj->defaults['columns'] ) ) ); } /** * Preset selector field option. * * @since 1.7.7 * * @param array $field Field settings. */ private function field_option_preset_selector( $field ) { $presets = $this->field_obj->get_presets(); $this->field_obj->field_element( 'label', $field, [ 'slug' => 'preset', 'value' => esc_html__( 'Select a Layout', 'wpforms' ), 'tooltip' => esc_html__( 'Select a predefined layout preset', 'wpforms' ), ] ); $inputs = ''; foreach ( $presets as $preset ) { $inputs .= sprintf( '', (int) $field['id'], esc_attr( $preset ), $field['preset'] === $preset ? ' checked' : '' ); } $this->field_obj->field_element( 'row', $field, [ 'slug' => 'preset', 'content' => $inputs, ] ); } /** * Display layout field preview inside the builder. * * @since 1.7.7 * * @param array $field Field settings. */ public function field_preview( $field ) { // Label. $this->field_obj->field_preview_option( 'label', $field ); // Notice. $this->field_preview_notice(); // Columns. $columns = isset( $field['columns'] ) && is_array( $field['columns'] ) ? $field['columns'] : $this->field_obj->defaults['columns']; $columns_html = ''; foreach ( $columns as $column ) { $preset_class = ! empty( $column['width_preset'] ) ? ' wpforms-layout-column-' . (int) $column['width_preset'] : ''; $style_width = ! empty( $column['width_custom'] ) ? ' style="width: ' . (int) $column['width_custom'] . '%;"' : ''; $columns_html .= sprintf( '
%3$s
', esc_attr( $preset_class ), $style_width, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $this->field_preview_column_content( $column ) ); } printf( '
%1$s
', $columns_html // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); // Description. $this->field_obj->field_preview_option( 'description', $field ); } /** * Display dismissible notice inside the Layout field preview. * * @since 1.7.7 */ private function field_preview_notice() { $dismissed = get_user_meta( get_current_user_id(), 'wpforms_dismissed', true ); if ( ! empty( $dismissed['edu-builder-layout-field-alert'] ) ) { return; } printf( '

%1$s %3$s

', esc_html__( 'Drag and drop fields into the columns below, or click a column to make it active. You may then click on new fields to easily place them directly into the active column.', 'wpforms' ), esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-use-the-layout-field-in-wpforms/', 'Builder Notice', 'Layout Field Documentation' ) ), esc_html__( 'Learn More', 'wpforms' ), esc_attr__( 'Dismiss this message.', 'wpforms' ) ); } /** * Generate layout field preview column content. * * @since 1.7.7 * * @param array $column Column data. * * @return string Column content HTML. */ public function field_preview_column_content( $column ) { $content = $this->get_field_preview_column_plus_placeholder_template(); if ( empty( $column['fields'] ) || ! is_array( $column['fields'] ) ) { return $content; } $panel_fields_obj = WPForms_Builder_Panel_Fields::instance(); ob_start(); foreach ( $column['fields'] as $field_id ) { if ( empty( $panel_fields_obj->form_data['fields'][ $field_id ] ) ) { continue; } $panel_fields_obj->preview_single_field( $panel_fields_obj->form_data['fields'][ $field_id ], [] ); } $content .= ob_get_clean(); return $content; } /** * Process layout fields data before saving the form. * * @since 1.7.7 * * @param array $form Form array which is usable with `wp_update_post()`. * @param array $data Data retrieved from $_POST and processed. * @param array $args Empty by default, may contain custom data not intended to be saved, but used for processing. * * @return array */ public function save_form_args( $form, $data, $args ) { // Get a filtered form content. $form_data = json_decode( stripslashes( $form['post_content'] ), true ); if ( empty( $form_data['fields'] ) || empty( $args['context'] ) || $args['context'] !== 'save_form' ) { return $form; } foreach ( (array) $form_data['fields'] as $id => $field ) { // Process only layout fields. if ( empty( $field['type'] ) || $field['type'] !== $this->field_obj->type ) { continue; } // Decode columns data from JSON. if ( isset( $field['columns-json'] ) ) { $field['columns'] = json_decode( $field['columns-json'], true ); // Do not need to store JSON. unset( $field['columns-json'] ); } // Set defaults to some field options. // For example, we don't have Label option in the Form Builder. $form_data['fields'][ $id ] = wp_parse_args( $field, $this->field_obj->defaults ); } $form['post_content'] = wpforms_encode( $form_data ); return $form; } /** * Pass localized strings to builder. * * @since 1.7.7 * * @param array $strings All strings that will be passed to builder. * @param WP_Post $form Form object. * * @return array */ public function get_localized_strings( $strings, $form ) { $legacy_layout_notice_text = sprintf( wp_kses( /* translators: %1$s - WPForms.com URL to a related doc. */ __( 'We’ve added a new field to help you build advanced form layouts more easily. Give the Layout Field a try! Layout CSS classes are still supported. Learn More', 'wpforms' ), [ 'a' => [ 'href' => [], 'target' => [], 'rel' => [], ], ] ), esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-use-the-layout-field-in-wpforms/', 'Field Options', 'How to Use the Layout Field Documentation' ) ) ); $strings['layout'] = [ 'not_allowed_fields' => $this->field_obj->get_not_allowed_fields(), /* translators: %s - Field name. */ 'not_allowed_alert_text' => esc_html__( 'The %s field can’t be placed inside a Layout field.', 'wpforms' ), 'empty_label' => esc_html__( 'Layout', 'wpforms' ), 'got_it' => esc_html__( 'Got it!', 'wpforms' ), 'size_notice_text' => esc_html__( 'Field size cannot be changed when used in a layout.', 'wpforms' ), 'size_notice_tooltip' => esc_html__( 'When a field is placed inside a column, the field size always equals the column width.', 'wpforms' ), 'dont_show_again' => esc_html__( 'Don’t Show Again', 'wpforms' ), 'legacy_layout_notice_title' => esc_html__( 'Layouts Have Moved!', 'wpforms' ), 'legacy_layout_notice_text' => $legacy_layout_notice_text, 'enabled_cf_alert_text' => esc_html__( 'The Layout field cannot be used when Conversational Forms is enabled.', 'wpforms' ), 'delete_confirm' => esc_html__( 'Are you sure you want to delete the Layout field? Deleting this field will also delete the fields inside it.', 'wpforms' ), ]; return $strings; } /** * Get template for the column "plus" placeholder. * * @since 1.7.7 * * @return string */ private function get_field_preview_column_plus_placeholder_template() { return sprintf( '
', esc_attr__( 'Click to set this column as default. Click again to unset.', 'wpforms' ) ); } /** * Output template for the column "plus" placeholder. * * @since 1.7.7 */ public function field_preview_column_plus_placeholder_template() { ?> field_obj->type ) { return $class; } return trim( $class . ' label_hide' ); } }