-
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: Merge block level attributes (#7361)
- Loading branch information
1 parent
2f9b92f
commit 8065dde
Showing
8 changed files
with
128 additions
and
56 deletions.
There are no files selected for viewing
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
80 changes: 80 additions & 0 deletions
80
src/DonationForms/Migrations/UpdateDonationLevelsSchema.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,80 @@ | ||
<?php | ||
|
||
namespace Give\DonationForms\Migrations; | ||
|
||
use Give\DonationForms\Repositories\DonationFormRepository; | ||
use Give\Framework\Migrations\Contracts\Migration; | ||
|
||
/** | ||
* Update the donation levels schema to support descriptions | ||
* | ||
* @unreleased | ||
*/ | ||
class UpdateDonationLevelsSchema extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function id() | ||
{ | ||
return 'donation-forms-donation-levels-schema'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function title() | ||
{ | ||
return 'Update Donation Levels schema to support descriptions'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function timestamp() | ||
{ | ||
return strtotime('2024-04-22'); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function run() | ||
{ | ||
$forms = give(DonationFormRepository::class) | ||
->prepareQuery() | ||
->whereIsNotNull("give_formmeta_attach_meta_fields.meta_value") | ||
->getAll(); | ||
|
||
if ( ! $forms) { | ||
return; | ||
} | ||
|
||
foreach ($forms as $form) { | ||
$amountBlock = $form->blocks->findByName('givewp/donation-amount'); | ||
|
||
if ( ! $amountBlock) { | ||
continue; | ||
} | ||
|
||
$blockAttributes = $amountBlock->getAttributes(); | ||
$levels = $blockAttributes["levels"]; | ||
$defaultLevel = $blockAttributes["defaultLevel"] ?? 0; | ||
|
||
if ( ! is_array($levels) || empty($levels) || isset($levels[0]['value'])) { | ||
continue; | ||
} | ||
|
||
$levels = array_map(function($level) use ($defaultLevel) { | ||
return [ | ||
'value' => $level, | ||
'label' => '', | ||
'checked' => $level === $defaultLevel, | ||
]; | ||
}, $levels); | ||
|
||
$amountBlock->setAttribute('levels', $levels); | ||
$form->save(); | ||
} | ||
} | ||
} |
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
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
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
3 changes: 2 additions & 1 deletion
3
src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/types.ts
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