PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / FormBuilder / Actions / ConvertGlobalDefaultOptionsToDefaultBlocks.php

ConvertGlobalDefaultOptionsToDefaultBlocks.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/FormBuilder/Actions/ConvertGlobalDefaultOptionsToDefaultBlocks.php

62 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }