Skip to content

Commit

Permalink
Feature: add excerpt for v3 forms (#7287)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva authored Mar 19, 2024
1 parent 9b84325 commit b4923b9
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 82 deletions.
129 changes: 53 additions & 76 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/DonationForms/Properties/FormSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ class FormSettings implements Arrayable, Jsonable
*/
public $designSettingsImageOpacity;

/* @unreleased
* @var string
*/
public $formExcerpt;

/**
* @unreleased Added formExcerpt
/**
* @since 3.2.0 Added registrationNotification
* @since 3.0.0
Expand Down Expand Up @@ -327,6 +335,8 @@ public static function fromArray(array $array): self

$self->designSettingsImageOpacity = $array['designSettingsImageOpacity'] ?? '';

$self->formExcerpt = $array['formExcerpt'] ?? '';

return $self;
}

Expand Down
24 changes: 24 additions & 0 deletions src/FormBuilder/Actions/UpdateFormExcerpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Give\FormBuilder\Actions;

use Give\DonationForms\Models\DonationForm;

/**
* @unreleased
*/
class UpdateFormExcerpt
{
/**
* @unreleased
*
* @param DonationForm $form
*/
public function __invoke(DonationForm $form)
{
wp_update_post([
'ID' => $form->id,
'post_excerpt' => $form->settings->formExcerpt,
]);
}
}
2 changes: 2 additions & 0 deletions src/FormBuilder/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Give\FormBuilder\Actions\UpdateDonorCommentsMeta;
use Give\FormBuilder\Actions\UpdateEmailSettingsMeta;
use Give\FormBuilder\Actions\UpdateEmailTemplateMeta;
use Give\FormBuilder\Actions\UpdateFormExcerpt;
use Give\FormBuilder\Actions\UpdateFormGridMeta;
use Give\FormBuilder\EmailPreview\Routes\RegisterEmailPreviewRoutes;
use Give\FormBuilder\Routes\CreateFormRoute;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function boot()
give(UpdateEmailSettingsMeta::class)->__invoke($form);
give(UpdateEmailTemplateMeta::class)->__invoke($form);
give(UpdateDonorCommentsMeta::class)->__invoke($form);
give(UpdateFormExcerpt::class)->__invoke($form);
});

Hooks::addAction('givewp_form_builder_new_form', ConvertGlobalDefaultOptionsToDefaultBlocks::class);
Expand Down
2 changes: 2 additions & 0 deletions src/FormBuilder/ViewModels/FormBuilderViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class FormBuilderViewModel
{
/**
* @unreleased Add support to isExcerptEnabled key in the compared array
* @since 3.2.0 Add nameTitlePrefixes key to the returned array
* @since 3.0.0
*/
Expand Down Expand Up @@ -76,6 +77,7 @@ public function storageData(int $donationFormId): array
],
'goalTypeOptions' => $this->getGoalTypeOptions(),
'nameTitlePrefixes' => give_get_option('title_prefixes'),
'isExcerptEnabled' => give_is_setting_enabled(give_get_option('forms_excerpt')),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type GoalTypeOption = {
};

/**
* @unreleased Added isExcerptEnabled
* @since 3.0.0
*/
interface FormBuilderWindowData {
Expand Down Expand Up @@ -48,6 +49,7 @@ interface FormBuilderWindowData {
termsAndConditions: TermsAndConditions;
goalTypeOptions: GoalTypeOption[];
nameTitlePrefixes: string[];
isExcerptEnabled: boolean;
}

/**
Expand All @@ -62,7 +64,7 @@ declare const window: {
[key: string]: Component;
};
};
}
};
} & Window;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { PanelRow, SelectControl, TextControl } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import {PanelRow, SelectControl, TextareaControl, TextControl} from '@wordpress/components';
import {__} from '@wordpress/i18n';

import { isFormPageEnabled, PageSlugControl } from "./page-slug";
import { cleanForSlug } from "@wordpress/url";
import {isFormPageEnabled, PageSlugControl} from './page-slug';
import {cleanForSlug} from '@wordpress/url';
import {getWindowData} from '@givewp/form-builder/common';

const {isExcerptEnabled} = getWindowData();

/**
* @unreleased Added formExcerpt text area
* @since 3.1.0 dispatch page slug from form title on initial publish.
*/
const FormSummarySettings = ({settings, setSettings}) => {
const {formTitle, pageSlug, formStatus, newFormStatus} = settings;
const {formTitle, pageSlug, formStatus, newFormStatus, formExcerpt} = settings;
const isPublished = ['publish', 'private'].includes(formStatus);
const isTitleSlug = !isPublished && cleanForSlug(formTitle) === pageSlug;

Expand Down Expand Up @@ -51,6 +55,20 @@ const FormSummarySettings = ({settings, setSettings}) => {
onChange={(newFormStatus) => setSettings({newFormStatus})}
/>
</PanelRow>

{isExcerptEnabled && (
<PanelRow>
<TextareaControl
label={'Excerpt'}
help={__(
'The excerpt is an optional summary or description of a donation form; in short, a summary as to why the user should give.',
'give'
)}
value={formExcerpt}
onChange={(formExcerpt) => setSettings({formExcerpt})}
/>
</PanelRow>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {FormStatus} from '@givewp/form-builder/types/formStatus';
import {EmailTemplateOption} from '@givewp/form-builder/types/emailTemplateOption';

/**
* @unreleased Added formExcerpt
* @since 3.0.0
*/
export type FormSettings = {
Expand Down Expand Up @@ -50,4 +51,5 @@ export type FormSettings = {
designSettingsTextFieldStyle: string;
designSettingsImageOpacity: string;
designSettingsImageColor: string;
formExcerpt: string;
};
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function register()
Steps\FundsAndDesignations::class,
Steps\GiftAid::class,
Steps\FormFeaturedImage::class,
Steps\FormExcerpt::class,
]);
});
}
Expand Down
19 changes: 19 additions & 0 deletions src/FormMigration/Steps/FormExcerpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Give\FormMigration\Steps;

use Give\FormMigration\Contracts\FormMigrationStep;

/**
* @unreleased
*/
class FormExcerpt extends FormMigrationStep
{
/**
* @unreleased
*/
public function process()
{
$this->formV3->settings->formExcerpt = get_the_excerpt($this->formV2->id);
}
}
3 changes: 3 additions & 0 deletions tests/Unit/ViewModels/FormBuilderViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FormBuilderViewModelTest extends TestCase
use RefreshDatabase;

/**
*
* @unreleased Add support to isExcerptEnabled key in the compared array
* @since 3.2.0 Add support to nameTitlePrefixes key in the compared array
* @since 3.0.0
*
Expand Down Expand Up @@ -85,6 +87,7 @@ public function testShouldReturnStorageData()
],
'goalTypeOptions' => $viewModel->getGoalTypeOptions(),
'nameTitlePrefixes' => give_get_option('title_prefixes'),
'isExcerptEnabled' => give_is_setting_enabled(give_get_option('forms_excerpt')),
],
$viewModel->storageData($formId)
);
Expand Down

0 comments on commit b4923b9

Please sign in to comment.