-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: create new forms using block models for translatable strings (
#7053) Co-authored-by: Jon Waldstein <[email protected]>
- Loading branch information
1 parent
e63e340
commit cb14120
Showing
4 changed files
with
326 additions
and
13 deletions.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
src/FormBuilder/Actions/GenerateDefaultDonationFormBlockCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
namespace Give\FormBuilder\Actions; | ||
|
||
use Give\Framework\Blocks\BlockCollection; | ||
use Give\Framework\Blocks\BlockModel; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class GenerateDefaultDonationFormBlockCollection | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function __invoke(): BlockCollection | ||
{ | ||
$section1 = $this->createSection( | ||
__('How much would you like to donate today?', 'give'), | ||
__('All donations directly impact our organization and help us further our mission.?', 'give'), | ||
$this->createAmountBlock() | ||
); | ||
|
||
$section2 = $this->createSection( | ||
__('Who\'s Giving Today?', 'give'), | ||
__('We\'ll never share this information with anyone', 'give'), | ||
$this->createDonorNameBlock(), | ||
$this->createEmailBlock() | ||
); | ||
|
||
$section3 = $this->createSection( | ||
__('Payment Details', 'give'), | ||
__('How would you like to pay for your donation?', 'give'), | ||
$this->createDonationSummaryBlock(), | ||
$this->createPaymentGatewaysBlock() | ||
); | ||
|
||
return BlockCollection::make([ | ||
$section1, | ||
$section2, | ||
$section3 | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createSection(string $title, string $description, BlockModel ...$innerBlocks): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/section', | ||
'attributes' => [ | ||
'title' => $title, | ||
'description' => $description, | ||
], | ||
'innerBlocks' => new BlockCollection($innerBlocks), | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createAmountBlock(): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/donation-amount', | ||
'attributes' => [ | ||
"label" => __("Donation Amount", 'give'), | ||
"levels" => [ | ||
10, | ||
25, | ||
50, | ||
100, | ||
250, | ||
500 | ||
], | ||
"defaultLevel" => 10, | ||
"priceOption" => "multi", | ||
"setPrice" => 25, | ||
"customAmount" => true, | ||
"customAmountMin" => 1, | ||
"recurringBillingPeriodOptions" => [ | ||
"month" | ||
], | ||
"recurringBillingInterval" => 1, | ||
"recurringEnabled" => false, | ||
"recurringLengthOfTime" => "0", | ||
"recurringOptInDefaultBillingPeriod" => "month", | ||
"recurringEnableOneTimeDonations" => true | ||
], | ||
'innerBlocks' => [], | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createDonorNameBlock(): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/donor-name', | ||
'attributes' => [ | ||
"showHonorific" => false, | ||
"honorifics" => [ | ||
__("Mr", 'give'), | ||
__("Ms", 'give'), | ||
__("Mrs", 'give') | ||
], | ||
"firstNameLabel" => __("First name", 'give'), | ||
"firstNamePlaceholder" => __("First name", 'give'), | ||
"lastNameLabel" => __("Last name", 'give'), | ||
"lastNamePlaceholder" => __("Last name", 'give'), | ||
"requireLastName" => false | ||
], | ||
"innerBlocks" => [] | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createEmailBlock(): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/email', | ||
'attributes' => [ | ||
"label" => __("Email Address", 'give'), | ||
"isRequired" => true, | ||
], | ||
"innerBlocks" => [] | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createDonationSummaryBlock(): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/donation-summary', | ||
'attributes' => [], | ||
'innerBlocks' => [] | ||
]); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function createPaymentGatewaysBlock(): BlockModel | ||
{ | ||
return BlockModel::make([ | ||
'name' => 'givewp/payment-gateways', | ||
'attributes' => [], | ||
'innerBlocks' => [] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.