diff --git a/assets/src/css/admin/settings.scss b/assets/src/css/admin/settings.scss index b2d1a14945..2d2af68567 100644 --- a/assets/src/css/admin/settings.scss +++ b/assets/src/css/admin/settings.scss @@ -383,6 +383,89 @@ div.give-field-description { } } +.give_option_based_form_editor_notice { + display: flex; + margin: -2rem 0 0.5rem 0; + gap: 0.3rem; + padding: 0.5rem; + background-color: #fffaf2; + border-radius: 4px; + border: 1px solid #f29718; + border-left-width: 4px; + font-size: 0.875rem; + font-weight: 500; + color: #1a0f00; + line-height: 1.25rem; + max-width: 60rem; + width: 100%; + + svg { + margin: 0.4rem 0.3rem; + height: 1.25rem; + width: 1.25rem; + } +} + +.give-setting-tab-body-general, +.give-setting-tab-body-display, +.give-settings-advanced-tab { + label { + display: flex; + position: relative; + + .give-settings-section-group-helper { + padding-left: 0.2rem; + --popout-display: none; + display: flex; + cursor: help; + + img { + max-width: 18.9px; + } + + &:hover { + --popout-display: block; + } + + &__popout { + background-color: #fff; + border: 1px solid #e6e6e6; + border-radius: 4px; + box-shadow: 0 4px 8px 0 #0000000D; + color: #404040; + display: var(--popout-display, none); + left: 100%; + overflow: hidden; + position: absolute; + top: 0; + transform: translateX(10px); + z-index: 9999; + + img { + max-width: initial; + display: block; + } + + h5 { + font-size: 0.875rem; + font-weight: 700; + line-height: 1.5; + margin: 0; + padding: 1rem 1.5rem 0.5rem; + } + + p { + font-size: 0.75rem; + font-weight: 500; + line-height: 1.5; + margin: 0; + padding: 0 1.5rem 1.5rem; + } + } + } + } +} + .give-payment-gateways-settings { &.give-settings-section-content { .give-settings-section-group-menu { @@ -917,7 +1000,6 @@ a.give-delete { } img { - object-fit: contain; width: 100%; } diff --git a/give.php b/give.php index 0761287a59..3cadbc00b9 100644 --- a/give.php +++ b/give.php @@ -242,7 +242,8 @@ final class Give Give\BetaFeatures\ServiceProvider::class, Give\FormTaxonomies\ServiceProvider::class, Give\DonationSpam\ServiceProvider::class, - Give\Settings\ServiceProvider::class + Give\Settings\ServiceProvider::class, + Give\FeatureFlags\OptionBasedFormEditor\ServiceProvider::class, ]; /** diff --git a/includes/admin/class-admin-settings.php b/includes/admin/class-admin-settings.php index 1d24c30b27..cc73c84442 100644 --- a/includes/admin/class-admin-settings.php +++ b/includes/admin/class-admin-settings.php @@ -949,7 +949,9 @@ class="give-input-field > - + > diff --git a/includes/post-types.php b/includes/post-types.php index 44f556a905..e0a0e3c313 100644 --- a/includes/post-types.php +++ b/includes/post-types.php @@ -56,8 +56,8 @@ function give_setup_post_types() { 'name' => __( 'Donation Forms', 'give' ), 'singular_name' => __( 'Form', 'give' ), 'add_new' => __( 'Add Form', 'give' ), - 'add_new_item' => __( 'Add New Donation Form', 'give' ), - 'edit_item' => __( 'Edit Donation Form', 'give' ), + 'add_new_item' => __('Add New Donation Form', 'give'), + 'edit_item' => __('Edit Donation Form', 'give'), 'new_item' => __( 'New Form', 'give' ), 'all_items' => __( 'All Forms', 'give' ), 'view_item' => __( 'View Form', 'give' ), diff --git a/src/DonationForms/V2/DonationFormsAdminPage.php b/src/DonationForms/V2/DonationFormsAdminPage.php index f03e36ab75..2d33e7f278 100644 --- a/src/DonationForms/V2/DonationFormsAdminPage.php +++ b/src/DonationForms/V2/DonationFormsAdminPage.php @@ -3,6 +3,7 @@ namespace Give\DonationForms\V2; use Give\DonationForms\V2\ListTable\DonationFormsListTable; +use Give\FeatureFlags\OptionBasedFormEditor\OptionBasedFormEditor; use Give\Helpers\EnqueueScript; use WP_Post; use WP_REST_Request; @@ -105,6 +106,7 @@ public function loadScripts() 'showUpgradedTooltip' => !get_user_meta(get_current_user_id(), 'givewp-show-upgraded-tooltip', true), 'supportedAddons' => $this->getSupportedAddons(), 'supportedGateways' => $this->getSupportedGateways(), + 'isOptionBasedFormEditorEnabled' => OptionBasedFormEditor::isEnabled(), ]; EnqueueScript::make('give-admin-donation-forms', 'assets/dist/js/give-admin-donation-forms.js') diff --git a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx index 2b9ffbd681..38993e202f 100644 --- a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx +++ b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx @@ -26,6 +26,7 @@ declare global { isMigrated: boolean; supportedAddons: Array; supportedGateways: Array; + isOptionBasedFormEditorEnabled: boolean; }; GiveNextGen?: { @@ -257,12 +258,14 @@ export default function DonationFormsListTable() { columnFilters={columnFilters} banner={Onboarding} > - + {window.GiveDonationForms.isOptionBasedFormEditorEnabled && ( + + )} + +
+ +
%3$s
+

%4$s

+
+ ', + esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/help-circle.svg'), + esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/give-settings-gateways-v2.jpg'), + __('Only for Option-Based Form Editor', 'give'), + __('Uses the traditional settings options for creating and customizing a donation form.', + 'give') + ); + } + + /** + * @unreleased + */ + public static function existOptionBasedFormsOnDb(): bool + { + return (bool)give(DonationFormsRepository::class)->prepareQuery() + ->whereNotExists(function ( + QueryBuilder $builder + ) { + $builder + ->select(['meta_value', 'formBuilderSettings']) + ->from(DB::raw(DB::prefix('give_formmeta'))) + ->where('meta_key', 'formBuilderSettings') + ->whereRaw('AND form_id = ID'); + })->count(); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php b/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php new file mode 100644 index 0000000000..25e4b2cd94 --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php @@ -0,0 +1,54 @@ +maybeDisableOptionBasedFormEditorSettings(); + } + + /** + * @return void + */ + private function maybeDisableOptionBasedFormEditorSettings() + { + // General Tab + Hooks::addFilter('give_get_settings_general', GeneralSettings::class, 'maybeDisableOptions', 999); + + // Payment Gateways Tab + add_filter('give_settings_payment_gateways_menu_groups', function ($groups) { + if ( ! OptionBasedFormEditor::isEnabled() && isset($groups['v2'])) { + unset($groups['v2']); + } + + return $groups; + }); + + // Default Options Tab + Hooks::addFilter('give_get_settings_display', DefaultOptionsSettings::class, 'maybeDisableOptions', 999); + + // Advance Tab + Hooks::addFilter('give_get_settings_advanced', AdvancedSettings::class, 'maybeDisableOptions', 999); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php new file mode 100644 index 0000000000..14d621b2b6 --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php @@ -0,0 +1,100 @@ + $value) { + if (in_array($key, $this->getDisabledSectionIds())) { + unset($sections[$key]); + } + } + + return $sections; + } + + /** + * @unreleased + */ + final public function maybeDisableOptions(array $options): array + { + foreach ($options as $key => $value) { + if ( ! $this->isOptionDisabled($value['id']) && ! $this->isCurrentSectionDisabled()) { + continue; + } + + if (OptionBasedFormEditor::isEnabled()) { + $options[$key]['name'] .= isset($value['name']) ? OptionBasedFormEditor::helperText() : ''; + } else { + unset($options[$key]); + } + } + + return $options; + } + + /** + * @unreleased + */ + final public function maybeSetNewDefaultSection($currentSection) + { + if (OptionBasedFormEditor::isEnabled()) { + return $currentSection; + } + + $newDefaultSection = $this->getNewDefaultSection(); + + return ! empty($newDefaultSection) && $newDefaultSection != $currentSection ? $newDefaultSection : $currentSection; + } + + /** + * @unreleased + */ + private function isOptionDisabled($option): bool + { + return $option && in_array($option, $this->getDisabledOptionIds()); + } + + /** + * @unreleased + */ + private function isCurrentSectionDisabled(): bool + { + return in_array(give_get_current_setting_section(), $this->getDisabledSectionIds()); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php new file mode 100644 index 0000000000..746234eccf --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php @@ -0,0 +1,26 @@ +routeForm->getOptionName(), + // Stripe Section + 'stripe_js_fallback', + 'stripe_styles', + ]; + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php new file mode 100644 index 0000000000..ac714a098c --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php @@ -0,0 +1,29 @@ +assertEquals( 'Donation Forms', $wp_post_types['give_forms']->labels->name ); $this->assertEquals( 'Form', $wp_post_types['give_forms']->labels->singular_name ); $this->assertEquals( 'Add Form', $wp_post_types['give_forms']->labels->add_new ); - $this->assertEquals( 'Add New Donation Form', $wp_post_types['give_forms']->labels->add_new_item ); - $this->assertEquals( 'Edit Donation Form', $wp_post_types['give_forms']->labels->edit_item ); + $this->assertEquals('Add New Donation Form', $wp_post_types['give_forms']->labels->add_new_item); + $this->assertEquals('Edit Donation Form', $wp_post_types['give_forms']->labels->edit_item); $this->assertEquals( 'New Form', $wp_post_types['give_forms']->labels->new_item ); $this->assertEquals( 'All Forms', $wp_post_types['give_forms']->labels->all_items ); $this->assertEquals( 'View Form', $wp_post_types['give_forms']->labels->view_item );