Skip to content

Commit

Permalink
Feature: add Gift Aid migration step (#7186)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski authored Jan 17, 2024
1 parent 6ee0c8c commit f1784a3
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
67 changes: 66 additions & 1 deletion src/FormMigration/FormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Give\DonationForms\V2\Models\DonationForm;
use Give\DonationForms\ValueObjects\GoalType;
use Give\FormMigration\Contracts\FormModelDecorator;
use Give\Log\Log;
use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\StripePaymentElementGateway;
use Give_Email_Notification_Util;

Expand Down Expand Up @@ -684,4 +683,70 @@ private function isDefaultFund(int $fundId): bool

return $fund->id === $fundId;
}

/**
* @unreleased
*
* @return string 'global', 'enabled', 'disabled'
*/
public function getGiftAidStatus(): string
{
return $this->getMeta('give_gift_aid_enable_disable');
}

/**
* @unreleased
*/
public function getGiftAidTitle(): string
{
return $this->getMeta('give_gift_aid_fieldset_title');
}

/**
* @unreleased
*/
public function getGiftAidDescription(): string
{
return $this->getMeta('give_gift_aid_explanation_content');
}

/**
* @unreleased
*/
public function getGiftAidLongExplanationEnabled(): bool
{
return $this->getMeta('give_gift_aid_long_explanation_enable_disable');
}

/**
* @unreleased
*/
public function getGiftAidLongExplanation(): string
{
return $this->getMeta('give_gift_aid_long_explanation_content');
}

/**
* @unreleased
*/
public function getGiftAidCheckboxLabel(): string
{
return $this->getMeta('give_gift_aid_checkbox_label');
}

/**
* @unreleased
*/
public function getGiftAidAgreementText(): string
{
return $this->getMeta('give_gift_aid_agreement');
}

/**
* @unreleased
*/
public function getGiftAidDeclarationForm(): string
{
return $this->getMeta('give_gift_aid_declaration_form');
}
}
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function register()
Steps\PerFormGateways::class,
Steps\Mailchimp::class,
Steps\FundsAndDesignations::class,
Steps\GiftAid::class,
]);
});
}
Expand Down
47 changes: 47 additions & 0 deletions src/FormMigration/Steps/GiftAid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Give\FormMigration\Steps;

use Give\FormMigration\Contracts\FormMigrationStep;
use Give\Framework\Blocks\BlockModel;

class GiftAid extends FormMigrationStep
{

/**
* @unreleased
*
* @return void
*/
public function process()
{
$giftAidStatus = $this->formV2->getGiftAidStatus();
$useGlobalSettings = $giftAidStatus === 'global';

if (empty($giftAidStatus) || (
$useGlobalSettings === true &&
!give_is_setting_enabled(give_get_option('give_gift_aid_enable_disable', 'disabled'))
) || !in_array($giftAidStatus, ['enabled', 'global'], true)) {
return;
}

$giftAidSettings = [
'useGlobalSettings' => $useGlobalSettings,
'title' => $this->formV2->getGiftAidTitle(),
'description' => $this->formV2->getGiftAidDescription(),
'longExplanationEnabled' => $this->formV2->getGiftAidLongExplanationEnabled(),
'linkText' => __('Tell me more', 'give-gift-aid'),
'modalHeader' => __('What is Gift Aid?', 'give-gift-aid'),
'longExplanation' => $this->formV2->getGiftAidLongExplanation(),
'checkboxLabel' => $this->formV2->getGiftAidCheckboxLabel(),
'agreementText' => $this->formV2->getGiftAidAgreementText(),
'declarationForm' => $this->formV2->getGiftAidDeclarationForm(),
];

$giftAidBlock = BlockModel::make([
'name' => 'givewp-gift-aid/gift-aid',
'attributes' => $giftAidSettings,
]);
$this->fieldBlocks->insertAfter('givewp/donation-amount', $giftAidBlock);
}
}

0 comments on commit f1784a3

Please sign in to comment.