ConvertGlobalDefaultOptionsToDefaultBlocks.php
2 years ago
ConvertLegacyNotificationToEmailNotificationData.php
2 years ago
DequeueAdminScriptsInFormBuilder.php
2 years ago
DequeueAdminStylesInFormBuilder.php
2 years ago
GenerateDefaultDonationFormBlockCollection.php
2 years ago
UpdateDonorCommentsMeta.php
2 years ago
UpdateEmailSettingsMeta.php
2 years ago
UpdateEmailTemplateMeta.php
2 years ago
UpdateFormGridMeta.php
2 years ago
ConvertGlobalDefaultOptionsToDefaultBlocks.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormBuilder\Actions; |
| 4 | |
| 5 | use Give\DonationForms\Models\DonationForm; |
| 6 | use Give\Framework\Blocks\BlockModel; |
| 7 | |
| 8 | /** |
| 9 | * In v2 forms, there was a concept of "Default Options" in global GiveWP settings. |
| 10 | * In v3 forms, we have "Default Blocks" instead. This action converts the global default options into default blocks. |
| 11 | * |
| 12 | * @since 3.0.0 |
| 13 | */ |
| 14 | class ConvertGlobalDefaultOptionsToDefaultBlocks |
| 15 | { |
| 16 | /** |
| 17 | * @since 3.0.0 |
| 18 | */ |
| 19 | public function __invoke(DonationForm $form) |
| 20 | { |
| 21 | $this->handleDonorComments($form); |
| 22 | $this->handleAnonymousDonations($form); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @since 3.0.0 |
| 27 | */ |
| 28 | protected function handleDonorComments(DonationForm $form) |
| 29 | { |
| 30 | if (give_is_donor_comment_field_enabled($form->id) && !$form->blocks->findByName('givewp/donor-comments')) { |
| 31 | $block = BlockModel::make([ |
| 32 | 'name' => 'givewp/donor-comments', |
| 33 | 'attributes' => [ |
| 34 | 'label' => __('Comment', 'give'), |
| 35 | 'description' => __('Would you like to add a comment to this donation?', 'give'), |
| 36 | ], |
| 37 | ]); |
| 38 | |
| 39 | $form->blocks->insertAfter('givewp/email', $block); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @since 3.0.0 |
| 45 | */ |
| 46 | protected function handleAnonymousDonations(DonationForm $form) |
| 47 | { |
| 48 | if (give_is_anonymous_donation_field_enabled($form->id) && !$form->blocks->findByName('givewp/anonymous')) { |
| 49 | $anonymousDonationsBlock = BlockModel::make([ |
| 50 | 'name' => 'givewp/anonymous', |
| 51 | 'attributes' => [ |
| 52 | 'label' => __('Make this an anonymous donation.', 'give'), |
| 53 | 'description' => __( |
| 54 | 'Would you like to prevent your name, image, and comment from being displayed publicly?', |
| 55 | 'give' |
| 56 | ), |
| 57 | ], |
| 58 | ]); |
| 59 | $form->blocks->insertAfter('givewp/email', $anonymousDonationsBlock); |
| 60 | } |
| 61 | } |
| 62 | } |