',
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' );
}
}