From c8e3709762b281b8aa1d8f531a42f570b66f53bd Mon Sep 17 00:00:00 2001 From: Kuba Birecki Date: Tue, 17 Jan 2023 18:16:39 +0100 Subject: [PATCH 1/3] Hook up packages/jetpack-forms to plugins/jetpack --- .../forms/src/class-jetpack-forms.php | 5 ++ projects/plugins/jetpack/composer.json | 1 + projects/plugins/jetpack/composer.lock | 64 ++++++++++++++++++- .../plugins/jetpack/modules/contact-form.php | 7 ++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/projects/packages/forms/src/class-jetpack-forms.php b/projects/packages/forms/src/class-jetpack-forms.php index 0d1bce094bae..385830b004c8 100644 --- a/projects/packages/forms/src/class-jetpack-forms.php +++ b/projects/packages/forms/src/class-jetpack-forms.php @@ -14,4 +14,9 @@ class Jetpack_Forms { const PACKAGE_VERSION = '0.1.0-alpha'; + /** + * Load the contact form module. + */ + public static function load_contact_form() { + } } diff --git a/projects/plugins/jetpack/composer.json b/projects/plugins/jetpack/composer.json index 10e2292d30b4..49dd93266c26 100644 --- a/projects/plugins/jetpack/composer.json +++ b/projects/plugins/jetpack/composer.json @@ -26,6 +26,7 @@ "automattic/jetpack-constants": "@dev", "automattic/jetpack-device-detection": "@dev", "automattic/jetpack-error": "@dev", + "automattic/jetpack-forms": "@dev", "automattic/jetpack-google-fonts-provider": "@dev", "automattic/jetpack-identity-crisis": "@dev", "automattic/jetpack-jitm": "@dev", diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 3fd5ebf128b5..caa3b2f0637e 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dc0cbe8e26c2170694a504dd282d294a", + "content-hash": "885f93512258c1b17a95fec63e503ec8", "packages": [ { "name": "automattic/jetpack-a8c-mc-stats", @@ -914,6 +914,67 @@ "relative": true } }, + { + "name": "automattic/jetpack-forms", + "version": "dev-trunk", + "dist": { + "type": "path", + "url": "../../packages/forms", + "reference": "fb95e8781f9cd26bc4cb8f3d6645a99a748a6248" + }, + "require-dev": { + "automattic/jetpack-changelogger": "@dev", + "automattic/wordbless": "dev-master", + "yoast/phpunit-polyfills": "1.0.4" + }, + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-forms", + "changelogger": { + "link-template": "https://github.com/automattic/jetpack-forms/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "0.1.x-dev" + }, + "textdomain": "jetpack-forms", + "version-constants": { + "::PACKAGE_VERSION": "src/class-jetpack-forms.php" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-coverage": [ + "php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\"" + ], + "test-php": [ + "@composer phpunit" + ], + "build-production": [ + "echo 'Add your build step to composer.json, please!'" + ], + "build-development": [ + "echo 'Add your build step to composer.json, please!'" + ], + "post-update-cmd": [ + "php -r \"copy('vendor/automattic/wordbless/src/dbless-wpdb.php', 'wordpress/wp-content/db.php');\"" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "description": "Jetpack Forms", + "transport-options": { + "relative": true + } + }, { "name": "automattic/jetpack-google-fonts-provider", "version": "dev-trunk", @@ -5495,6 +5556,7 @@ "automattic/jetpack-constants": 20, "automattic/jetpack-device-detection": 20, "automattic/jetpack-error": 20, + "automattic/jetpack-forms": 20, "automattic/jetpack-google-fonts-provider": 20, "automattic/jetpack-identity-crisis": 20, "automattic/jetpack-jitm": 20, diff --git a/projects/plugins/jetpack/modules/contact-form.php b/projects/plugins/jetpack/modules/contact-form.php index 15d815d7ee43..d8192860ac5f 100644 --- a/projects/plugins/jetpack/modules/contact-form.php +++ b/projects/plugins/jetpack/modules/contact-form.php @@ -5,6 +5,8 @@ * @package automattic/jetpack */ +use Automattic\Jetpack\Forms\Jetpack_Forms; + /** * Module Name: Contact Form * Module Description: Add a customizable contact form to any post or page using the Jetpack Form Block. @@ -18,6 +20,11 @@ * Additional Search Queries: contact, form, grunion, feedback, submission, contact form, email, feedback, contact form plugin, custom form, custom form plugin, form builder, forms, form maker, survey, contact by jetpack, contact us, forms free */ +if ( defined( 'JETPACK_FORMS_PACKAGE_ENABLED' ) && JETPACK_FORMS_PACKAGE_ENABLED ) { + Jetpack_Forms::load_contact_form(); + return true; // Not returning true will cause the module to become deactivated. +} + require_once __DIR__ . '/contact-form/grunion-contact-form.php'; /* From 06c7674b5105497d6cd0f6b5c743a1bf53d825e1 Mon Sep 17 00:00:00 2001 From: Kuba Birecki Date: Tue, 17 Jan 2023 18:20:54 +0100 Subject: [PATCH 2/3] changelog --- projects/packages/forms/changelog/add-forms-dependency | 4 ++++ projects/plugins/jetpack/changelog/add-forms-dependency | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 projects/packages/forms/changelog/add-forms-dependency create mode 100644 projects/plugins/jetpack/changelog/add-forms-dependency diff --git a/projects/packages/forms/changelog/add-forms-dependency b/projects/packages/forms/changelog/add-forms-dependency new file mode 100644 index 000000000000..7b325dac7f44 --- /dev/null +++ b/projects/packages/forms/changelog/add-forms-dependency @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Added a public load_contact_form method for initializing the contact form module. diff --git a/projects/plugins/jetpack/changelog/add-forms-dependency b/projects/plugins/jetpack/changelog/add-forms-dependency new file mode 100644 index 000000000000..1d478f383ac3 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-forms-dependency @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +Added the dependency on automattic/jetpack-forms From c835db08d4249c61ecda66252cd9326fa86c1c4c Mon Sep 17 00:00:00 2001 From: Kuba Birecki Date: Wed, 18 Jan 2023 12:26:25 +0100 Subject: [PATCH 3/3] Update condition to use a filter instead of a constant --- projects/plugins/jetpack/modules/contact-form.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/contact-form.php b/projects/plugins/jetpack/modules/contact-form.php index d8192860ac5f..810d01abce6a 100644 --- a/projects/plugins/jetpack/modules/contact-form.php +++ b/projects/plugins/jetpack/modules/contact-form.php @@ -20,7 +20,17 @@ * Additional Search Queries: contact, form, grunion, feedback, submission, contact form, email, feedback, contact form plugin, custom form, custom form plugin, form builder, forms, form maker, survey, contact by jetpack, contact us, forms free */ -if ( defined( 'JETPACK_FORMS_PACKAGE_ENABLED' ) && JETPACK_FORMS_PACKAGE_ENABLED ) { +/** + * Whether to load the newer Jetpack Forms package. + * + * @use add_filter( 'jetpack_contact_form_use_package', '__return_true' ); + * @module contact-form + * + * @since $$next-version$$ + * + * @param bool $load_contact_form_package Load Jetpack Forms package. Default to false. + */ +if ( apply_filters( 'jetpack_contact_form_use_package', false ) ) { Jetpack_Forms::load_contact_form(); return true; // Not returning true will cause the module to become deactivated. }