| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormMigration\Steps\FormTemplate; |
| 4 |
|
| 5 |
use Give\DonationForms\Properties\FormSettings; |
| 6 |
use Give\FormMigration\Actions\MapSettingsToDesignHeader; |
| 7 |
use Give\FormMigration\Actions\MapSettingsToDonationSummary; |
| 8 |
use Give\FormMigration\Contracts\FormMigrationStep; |
| 9 |
use Give\FormMigration\DataTransferObjects\DesignHeaderSettings; |
| 10 |
use Give\FormMigration\DataTransferObjects\DonationSummarySettings; |
| 11 |
|
| 12 |
class SequoiaTemplateSettings extends FormMigrationStep |
| 13 |
{ |
| 14 |
public function canHandle(): bool |
| 15 |
{ |
| 16 |
return 'sequoia' === $this->formV2->getFormTemplate(); |
| 17 |
} |
| 18 |
|
| 19 |
public function process() |
| 20 |
{ |
| 21 |
[ |
| 22 |
'visual_appearance' => $visualAppearance, |
| 23 |
'introduction' => $introduction, |
| 24 |
'payment_amount' => $paymentAmount, |
| 25 |
'payment_information' => $paymentInformation, |
| 26 |
'thank-you' => $donationReceipt, |
| 27 |
] = $this->formV2->getFormTemplateSettings(); |
| 28 |
|
| 29 |
/** @var FormSettings $formSettings */ |
| 30 |
$formSettings = $this->formV3->settings; |
| 31 |
$formSettings->designId = 'multi-step'; |
| 32 |
|
| 33 |
$this->visualAppearance($visualAppearance); |
| 34 |
$this->introduction($introduction); |
| 35 |
$this->paymentAmount($paymentAmount); |
| 36 |
$this->paymentInformation($paymentInformation); |
| 37 |
$this->donationReceipt($donationReceipt); |
| 38 |
} |
| 39 |
|
| 40 |
protected function visualAppearance($settings) |
| 41 |
{ |
| 42 |
[ |
| 43 |
'primary_color' => $primaryColor, // '#28C77B' |
| 44 |
'google-fonts' => $googleFonts, // 'enabled' |
| 45 |
'decimals_enabled' => $decimalsEnabled, // 'disabled' |
| 46 |
] = $settings; |
| 47 |
|
| 48 |
$this->formV3->settings->primaryColor = $primaryColor; |
| 49 |
|
| 50 |
// @note `google-fonts` is not supported in v3 forms (defers to the Form Design). |
| 51 |
|
| 52 |
// @note `decimals_enabled` is not supported in v3 forms (defers to the Form Design). |
| 53 |
} |
| 54 |
|
| 55 |
protected function introduction($settings) |
| 56 |
{ |
| 57 |
[ |
| 58 |
'enabled' => $enabled, // 'enabled', |
| 59 |
'headline' => $headline, // 'Tributes Form', |
| 60 |
'description' => $description, // 'Help our organization by donating today! All donations go directly to making a difference for our cause.', |
| 61 |
'image' => $image, // '', |
| 62 |
'donate_label' => $donateLabel, // 'Donate Now', |
| 63 |
] = $settings; |
| 64 |
|
| 65 |
MapSettingsToDesignHeader::make($this->formV3) |
| 66 |
->__invoke(new DesignHeaderSettings($enabled, $headline, $description)); |
| 67 |
|
| 68 |
$this->formV3->settings->multiStepFirstButtonText = $donateLabel; |
| 69 |
|
| 70 |
// @note `image` is not supported in v3 forms (defers to the Form Design). |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
protected function paymentAmount($settings) |
| 75 |
{ |
| 76 |
[ |
| 77 |
'header_label' => $headerLabel, // 'Choose Amount', |
| 78 |
'content' => $content, // 'How much would you like to donate? As a contributor to WordPress we make sure your donation goes directly to supporting our cause. Thank you for your generosity!', |
| 79 |
'next_label' => $nextLabel, // 'Continue', |
| 80 |
] = $settings; |
| 81 |
|
| 82 |
$this->fieldBlocks->findParentByChildName('givewp/donation-amount') |
| 83 |
->setAttribute('title', $headerLabel) |
| 84 |
->setAttribute('description', $content); |
| 85 |
|
| 86 |
$this->formV3->settings->multiStepNextButtonText = $nextLabel; |
| 87 |
} |
| 88 |
|
| 89 |
protected function paymentInformation($settings) |
| 90 |
{ |
| 91 |
[ |
| 92 |
'header_label' => $headerLabel, // 'Add Your Information', |
| 93 |
'headline' => $headline, // 'Who\'s giving today?', |
| 94 |
'description' => $description, // 'We’ll never share this information with anyone.', |
| 95 |
'donation_summary_enabled' => $donationSummaryEnabled, // 'enabled', |
| 96 |
'donation_summary_heading' => $donationSummaryHeading, // 'Here\'s what you\'re about to donate:', |
| 97 |
'donation_summary_location' => $donationSummaryLocation, // 'give_donation_form_before_submit', |
| 98 |
'checkout_label' => $checkoutLabel, // 'Donate Now', |
| 99 |
] = $settings; |
| 100 |
|
| 101 |
$this->fieldBlocks->findParentByChildName('givewp/payment-gateways') |
| 102 |
->setAttribute('title', $headline) // @note Should this be `headline` or `header_label`? |
| 103 |
->setAttribute('description', $description); |
| 104 |
|
| 105 |
MapSettingsToDonationSummary::make($this->fieldBlocks) |
| 106 |
->__invoke(DonationSummarySettings::make($settings)); |
| 107 |
|
| 108 |
$this->formV3->settings->donateButtonCaption = $checkoutLabel; |
| 109 |
} |
| 110 |
|
| 111 |
protected function donationReceipt($settings) |
| 112 |
{ |
| 113 |
[ |
| 114 |
'headline' => $headline, |
| 115 |
'description' => $description, |
| 116 |
] = $settings; |
| 117 |
|
| 118 |
$this->formV3->settings->receiptHeading = $headline; |
| 119 |
$this->formV3->settings->receiptDescription = $description; |
| 120 |
|
| 121 |
// @note `image`, `sharing`, `sharing_instruction`, `twitter_message` are not supported in v3 forms. |
| 122 |
} |
| 123 |
} |
| 124 |
|