Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add Option-Based Form Editor feature flag #7571

Merged
merged 30 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c64c9ec
feature: add logic to disable legacy options on the settings page
glaubersilva Oct 15, 2024
d8bfab8
refactor: create abstract class and add helper text
glaubersilva Oct 15, 2024
a23e2cf
feature: add existOptionBasedFormsOnDb method
glaubersilva Oct 15, 2024
5d452dd
feature: add option to enable or disable legacy editor
glaubersilva Oct 15, 2024
e3a9171
feature: add a modal that allows users to choose the form editor befo…
glaubersilva Oct 16, 2024
8bd7ecf
doc: add unreleased tag
glaubersilva Oct 16, 2024
d65827c
feature: add campaign link on form builder header
glaubersilva Oct 16, 2024
e63e082
fix: wrong parameter type
glaubersilva Oct 16, 2024
b6a3ffe
feature: add Manage Campaign link to legacy editor
glaubersilva Oct 16, 2024
d5aaffc
feature: add styles for add campaign form modal
glaubersilva Oct 17, 2024
cb5d918
refactor: add BackToCampaignOverview component
glaubersilva Oct 17, 2024
828e8db
feature: add notice for Option-Based Form Editor advanced option
glaubersilva Oct 17, 2024
dd9b38a
fix: broken helper icons
glaubersilva Oct 17, 2024
726835e
feature: disable v2 gateways when legacy editor is disabled
glaubersilva Oct 17, 2024
f36877b
refactor: rename method and clean up classes
glaubersilva Oct 17, 2024
a988150
fix: test_give_post_type_labels
glaubersilva Oct 17, 2024
e8cbfc3
fix: wrong parameter
glaubersilva Oct 17, 2024
070d13c
chore: roll back previous name
glaubersilva Oct 17, 2024
1d1d804
Merge branch 'epic/campaigns' into feature/feature-flag-GIVE-1264
glaubersilva Oct 17, 2024
8174123
chore: remove commented code
glaubersilva Oct 17, 2024
caaaee0
Merge branch 'feature/feature-flag-GIVE-1264' of github.com:impress-o…
glaubersilva Oct 17, 2024
349b56f
refactor: move editor options logic to EditorTypeOption component
glaubersilva Oct 21, 2024
2a34798
refactor: implement editor selection design
glaubersilva Oct 21, 2024
bc53a2c
refactor: use DB::prefix
glaubersilva Oct 21, 2024
224c913
refactor: use alias
glaubersilva Oct 21, 2024
ae59601
refactor: add FeatureFlags interface
glaubersilva Oct 21, 2024
cbb1de1
refactor: move and rename service provider class
glaubersilva Oct 21, 2024
674b890
refactor: simplify getByFormId method
glaubersilva Oct 21, 2024
d4799d3
Merge branch 'epic/campaigns' into feature/feature-flag-GIVE-1264
glaubersilva Oct 22, 2024
762ff64
fix: remove duplicated methods
glaubersilva Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions assets/src/css/admin/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,90 @@ div.give-field-description {
}
}

.give_option_based_form_editor_notice {
display: flex;
margin: -2rem 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;
gap: 0.4rem;
padding: 1.25rem 1rem;
position: relative;

.give-settings-section-group-helper {
--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 {
Expand Down
2 changes: 2 additions & 0 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use Give\DonorDashboards\Tabs\TabsRegister;
use Give\Donors\Repositories\DonorRepositoryProxy;
use Give\Donors\ServiceProvider as DonorsServiceProvider;
use Give\FeatureFlags\FeatureFlagsServiceProvider;
use Give\Form\LegacyConsumer\ServiceProvider as FormLegacyConsumerServiceProvider;
use Give\Form\Templates;
use Give\FormBuilder\ServiceProvider as FormBuilderServiceProvider;
Expand Down Expand Up @@ -242,6 +243,7 @@ final class Give
Give\FormTaxonomies\ServiceProvider::class,
Give\DonationSpam\ServiceProvider::class,
Give\Campaigns\ServiceProvider::class,
FeatureFlagsServiceProvider::class,
];

/**
Expand Down
4 changes: 3 additions & 1 deletion includes/admin/class-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,9 @@ class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_att
?>
<tr valign="top" <?php echo $wrapper_class; ?>>
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
<label for="<?php
echo esc_attr($value['id']); ?>"><?php
echo wp_kses_post(self::get_field_title($value)); ?></label>
</th>
<td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
<select
Expand Down
50 changes: 50 additions & 0 deletions includes/admin/settings/class-settings-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @since 1.8
*/

use Give\FeatureFlags\OptionBasedFormEditor\OptionBasedFormEditor;
use Give\Onboarding\Setup\Page as SetupPage;

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -45,6 +46,8 @@ public function __construct() {
);
add_action( 'give_save_settings_give_settings', [ $this, 'validate_settngs' ] );
add_filter( "give_admin_settings_sanitize_option_donor_default_user_role", [$this, 'sanitize_option_donor_default_user_role']);
add_action('give_admin_field_give_option_based_form_editor_notice',
[$this, '_render_give_based_form_editor_notice'], 10, 2);
}

parent::__construct();
Expand All @@ -69,6 +72,22 @@ public function get_settings() {
'id' => 'give_title_data_control_2',
'type' => 'title',
],
[
'name' => __('Option-Based Form Editor', 'give'),
'desc' => __('If enabled, you\'ll gain access to the legacy settings and can create forms using the Option-Based Editor. Disabling this option will not affect existing forms created with the Option-Based Editor.',
'give'),
'id' => 'option_based_form_editor',
'type' => 'radio_inline',
'default' => (OptionBasedFormEditor::existOptionBasedFormsOnDb()) ? 'enabled' : 'disabled',
'options' => [
'enabled' => __('Enabled', 'give'),
'disabled' => __('Disabled', 'give'),
],
],
[
'id' => 'option_based_form_editor_notice',
'type' => 'give_option_based_form_editor_notice',
],
[
'name' => __( 'Default GiveWP Styles', 'give' ),
'desc' => __( 'This controls GiveWP\'s default styles for legacy donation forms and other front end elements. Disabling this option means that you\'ll need to supply your own styles.', 'give' ),
Expand Down Expand Up @@ -368,6 +387,37 @@ public function sanitize_option_donor_default_user_role($value) {
}
return $value;
}

/**
* @unreleased
*/
public function _render_give_based_form_editor_notice($field, $value)
{
if (OptionBasedFormEditor::isEnabled()) {
?>
<tr valign="top" <?php
echo ! empty($field['wrapper_class']) ? 'class="' . $field['wrapper_class'] . '"' : ''; ?>>
<th scope="row" class="titledesc">
</th>
<td class="give-forminp">
<div class="give_option_based_form_editor_notice">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M10.678 1.39a1.667 1.667 0 0 0-1.355 0c-.333.148-.549.409-.7.621-.147.21-.306.483-.48.784l-6.89 11.9c-.174.301-.333.576-.441.809-.11.237-.228.555-.19.918.048.47.295.898.677 1.176.295.214.63.271.89.295.256.023.573.023.922.023H16.89c.349 0 .666 0 .922-.023.26-.024.594-.08.89-.295.382-.278.628-.706.677-1.176.038-.363-.08-.681-.19-.918a10.943 10.943 0 0 0-.442-.81l-6.89-11.9a10.856 10.856 0 0 0-.48-.783c-.15-.212-.367-.473-.7-.621zm.156 6.11a.833.833 0 0 0-1.667 0v3.333a.833.833 0 0 0 1.667 0V7.5zM10 13.333A.833.833 0 0 0 10 15h.009a.833.833 0 0 0 0-1.667H10z"
fill="#F29718" />
</svg>
<p>
<?php
echo esc_html__('We recommend moving away from Legacy settings and the Option-Based Editor as they are not compatible with newer features and will eventually be removed.',
'give'); ?>
</p>
</div>
</td>
</tr>
<?php
}
}
}

endif;
Expand Down
77 changes: 43 additions & 34 deletions includes/admin/settings/class-settings-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,50 +410,59 @@ static function ($value, $key) {
],
],
];

/**
* @unreleased
*/
$groups = apply_filters('give_settings_payment_gateways_menu_groups', $groups);

$defaultGroup = current(array_keys($groups));

ob_start();

echo '<h4>' . __('Enabled Gateways', 'give') . '</h4>';
echo '<div class="give-settings-section-content give-payment-gateways-settings">';
echo '<div class="give-settings-section-group-menu">';
echo '<ul>';
foreach ($groups as $slug => $group) {
$current_group = !empty($_GET['group']) ? give_clean($_GET['group']) : $defaultGroup;
$active_class = ($slug === $current_group) ? 'active' : '';

if ($group['helper']) {
$helper = sprintf(
'<div class="give-settings-section-group-helper">
<img src="%1$s" />
<div class="give-settings-section-group-helper__popout">
<img src="%2$s" />
<h5>%3$s</h5>
<p>%4$s</p>
</div>
</div>',
esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/help-circle.svg'),
esc_url($group['helper']['image']),

if (count($groups) > 1) {
echo '<div class="give-settings-section-group-menu">';
echo '<ul>';
foreach ($groups as $slug => $group) {
$current_group = ! empty($_GET['group']) ? give_clean($_GET['group']) : $defaultGroup;
$active_class = ($slug === $current_group) ? 'active' : '';

if ($group['helper']) {
$helper = sprintf(
'<div class="give-settings-section-group-helper">
<img src="%1$s" />
<div class="give-settings-section-group-helper__popout">
<img src="%2$s" />
<h5>%3$s</h5>
<p>%4$s</p>
</div>
</div>',
esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/help-circle.svg'),
esc_url($group['helper']['image']),
esc_html($group['label']),
esc_html($group['helper']['text'])
);
}

echo sprintf(
'<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s %5$s</a></li>',
esc_html($active_class),
esc_url(
admin_url(
"edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}"
)
),
esc_html($slug),
esc_html($group['label']),
esc_html($group['helper']['text'])
$helper ?? ''
);
}

echo sprintf(
'<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s %5$s</a></li>',
esc_html($active_class),
esc_url(
admin_url(
"edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}"
)
),
esc_html($slug),
esc_html($group['label']),
$helper ?? ''
);
echo '</ul>';
echo '</div>';
}
echo '</ul>';
echo '</div>';

echo '<div class="give-settings-section-group-content">';
foreach ($groups as $slug => $group) :
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/settings/class-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public function _render_give_currency_preview($field, $value)
<label
for="<?php
echo esc_attr($field['id']); ?>"><?php
echo esc_html($field['name']); ?></label>
echo wp_kses_post($field['name']); ?></label>
</th>
<td class="give-forminp">
<input id="<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,8 @@ public function stripe_styles_field( $field_options, $option_value ) {
<tr valign="top" <?php echo ! empty( $field_options['wrapper_class'] ) ? 'class="' . esc_attr( $field_options['wrapper_class'] ) . '"' : ''; ?>>
<th scope="row" class="titledesc">
<label for="<?php echo esc_html( $field_options['type'] ); ?>">
<?php echo esc_attr( $field_options['title'] ); ?>
<?php
echo wp_kses_post($field_options['title']); ?>
</label>
</th>
<td class="give-forminp give-forminp-<?php echo esc_html( $field_options['type'] ); ?>">
Expand Down
4 changes: 2 additions & 2 deletions includes/post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Campaign Form', 'give' ),
'edit_item' => __( 'Edit Campaign Form', 'give' ),
'new_item' => __( 'New Form', 'give' ),
'all_items' => __( 'All Forms', 'give' ),
'view_item' => __( 'View Form', 'give' ),
Expand Down
19 changes: 17 additions & 2 deletions src/Campaigns/Actions/AddCampaignFormFromRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
use Give\Campaigns\Models\Campaign;
use Give\Campaigns\Repositories\CampaignRepository;
use Give\DonationForms\Models\DonationForm;
use WP_Post;

/**
* @unreleased
*/
class AddCampaignFormFromRequest
{
/**
* @unreleased
*
* @throws Exception
*/
public function __invoke(DonationForm $donationForm)
public function optionBasedFormEditor(int $formId, WP_Post $post, bool $update)
{
if ( ! $update && isset($_GET['campaignId']) && $campaign = Campaign::find(absint($_GET['campaignId']))) {
give(CampaignRepository::class)->addCampaignForm($campaign, $formId);
}
}

/**
* @unreleased
*
* @throws Exception
*/
public function visualFormBuilder(DonationForm $donationForm)
{
if (isset($_GET['campaignId']) && $campaign = Campaign::find(absint($_GET['campaignId']))) {
give(CampaignRepository::class)->addCampaignForm($campaign, $donationForm);
give(CampaignRepository::class)->addCampaignForm($campaign, $donationForm->id);
}
}
}
2 changes: 1 addition & 1 deletion src/Campaigns/Actions/CreateDefaultCampaignForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function __invoke(Campaign $campaign)
'status' => DonationFormStatus::DRAFT(),
]);

give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm, true);
give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm->id, true);
}
}
8 changes: 8 additions & 0 deletions src/Campaigns/Models/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public static function find($id): ?Campaign
return give(CampaignRepository::class)->getById($id);
}

/**
* @unreleased
*/
public static function findByFormId(int $formId): ?Campaign
{
return give(CampaignRepository::class)->getByFormId($formId);
}

/**
* @unreleased
*
Expand Down
Loading
Loading