From f63346cafde1c08826ca2180a0aab8c438ab1bab Mon Sep 17 00:00:00 2001 From: Kevin Zoschke Date: Mon, 18 Dec 2023 17:35:10 -0500 Subject: [PATCH 1/2] Contact Form: add extra field settings to base field --- .../update-contact-form-extra-field-settings | 4 + .../components/jetpack-field-controls.js | 74 ++++++++++++------- 2 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 projects/packages/forms/changelog/update-contact-form-extra-field-settings diff --git a/projects/packages/forms/changelog/update-contact-form-extra-field-settings b/projects/packages/forms/changelog/update-contact-form-extra-field-settings new file mode 100644 index 0000000000000..58d4f1a42f30a --- /dev/null +++ b/projects/packages/forms/changelog/update-contact-form-extra-field-settings @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Contact Form: add extra field settings to base field diff --git a/projects/packages/forms/src/blocks/contact-form/components/jetpack-field-controls.js b/projects/packages/forms/src/blocks/contact-form/components/jetpack-field-controls.js index 4fe8431504e22..59482070b4351 100644 --- a/projects/packages/forms/src/blocks/contact-form/components/jetpack-field-controls.js +++ b/projects/packages/forms/src/blocks/contact-form/components/jetpack-field-controls.js @@ -13,6 +13,7 @@ import { ToggleControl, RangeControl, } from '@wordpress/components'; +import { isValidElement } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { useFormStyle, FORM_STYLE, getBlockStyle } from '../util/form'; import ToolbarRequiredGroup from './block-controls/toolbar-required-group'; @@ -31,6 +32,7 @@ const JetpackFieldControls = ( { setAttributes, type, width, + extraFieldSettings = [], } ) => { const formStyle = useFormStyle( clientId ); const blockStyle = getBlockStyle( blockClassNames ); @@ -103,6 +105,50 @@ const JetpackFieldControls = ( { setAttributes( { id: newValue } ); }; + let fieldSettings = [ + setAttributes( { required: value } ) } + help={ __( 'You can edit the "required" label in the editor', 'jetpack-forms' ) } + />, + ! hidePlaceholder && ( + setAttributes( { [ placeholderField ]: value } ) } + help={ __( + 'Show visitors an example of the type of content expected. Otherwise, leave blank.', + 'jetpack-forms' + ) } + /> + ), + , + setAttributes( { shareFieldAttributes: value } ) } + help={ __( 'Deactivate for individual styling of this block', 'jetpack-forms' ) } + />, + ]; + + extraFieldSettings.forEach( ( { element, index } ) => { + if ( ! isValidElement( element ) ) { + return; + } + + if ( index >= 0 && index < fieldSettings.length ) { + fieldSettings = [ + ...fieldSettings.slice( 0, index ), + element, + ...fieldSettings.slice( index ), + ]; + } else { + fieldSettings.push( element ); + } + } ); + return ( <> @@ -117,31 +163,9 @@ const JetpackFieldControls = ( { - setAttributes( { required: value } ) } - help={ __( 'You can edit the "required" label in the editor', 'jetpack-forms' ) } - /> - { ! hidePlaceholder && ( - setAttributes( { [ placeholderField ]: value } ) } - help={ __( - 'Show visitors an example of the type of content expected. Otherwise, leave blank.', - 'jetpack-forms' - ) } - /> - ) } - - setAttributes( { shareFieldAttributes: value } ) } - help={ __( 'Deactivate for individual styling of this block', 'jetpack-forms' ) } - /> + { fieldSettings.filter( Boolean ).map( ( elt, index ) => ( +
{ elt }
+ ) ) }
Date: Tue, 19 Dec 2023 10:51:58 -0500 Subject: [PATCH 2/2] Fix package version --- projects/packages/forms/composer.json | 2 +- projects/packages/forms/package.json | 2 +- projects/packages/forms/src/class-jetpack-forms.php | 2 +- .../changelog/update-contact-form-extra-field-settings | 5 +++++ projects/plugins/jetpack/composer.lock | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-contact-form-extra-field-settings diff --git a/projects/packages/forms/composer.json b/projects/packages/forms/composer.json index a0b6f17d23937..5f3e71f727afc 100644 --- a/projects/packages/forms/composer.json +++ b/projects/packages/forms/composer.json @@ -62,7 +62,7 @@ "link-template": "https://github.com/automattic/jetpack-forms/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "0.27.x-dev" + "dev-trunk": "0.28.x-dev" }, "textdomain": "jetpack-forms", "version-constants": { diff --git a/projects/packages/forms/package.json b/projects/packages/forms/package.json index d0e2b3923420b..0e98d8040e82a 100644 --- a/projects/packages/forms/package.json +++ b/projects/packages/forms/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-forms", - "version": "0.27.0", + "version": "0.28.0-alpha", "description": "Jetpack Forms", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/forms/#readme", "bugs": { diff --git a/projects/packages/forms/src/class-jetpack-forms.php b/projects/packages/forms/src/class-jetpack-forms.php index 335f543f58f51..c139e1ae04a1a 100644 --- a/projects/packages/forms/src/class-jetpack-forms.php +++ b/projects/packages/forms/src/class-jetpack-forms.php @@ -15,7 +15,7 @@ */ class Jetpack_Forms { - const PACKAGE_VERSION = '0.27.0'; + const PACKAGE_VERSION = '0.28.0-alpha'; /** * Load the contact form module. diff --git a/projects/plugins/jetpack/changelog/update-contact-form-extra-field-settings b/projects/plugins/jetpack/changelog/update-contact-form-extra-field-settings new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-contact-form-extra-field-settings @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index fc35b572a0db1..880e1af195d03 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -1167,7 +1167,7 @@ "dist": { "type": "path", "url": "../../packages/forms", - "reference": "91cdedeae6c8fc54fb18196d9465098efca69975" + "reference": "c72fbe74edbc293518b22c39de5c8f609e2f235b" }, "require": { "automattic/jetpack-assets": "@dev", @@ -1193,7 +1193,7 @@ "link-template": "https://github.com/automattic/jetpack-forms/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "0.27.x-dev" + "dev-trunk": "0.28.x-dev" }, "textdomain": "jetpack-forms", "version-constants": {