PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.0
GiveWP – Donation Plugin and Fundraising Platform v4.16.0
4.18.0 4.17.0 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 All 257 releases
give / src / Campaigns / Actions / CreateDefaultCampaignForm.php

CreateDefaultCampaignForm.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.0, at src/Campaigns/Actions/CreateDefaultCampaignForm.php

53 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Actions;
4
5 use Exception;
6 use Give\Campaigns\Models\Campaign;
7 use Give\Campaigns\Repositories\CampaignRepository;
8 use Give\DonationForms\FormDesigns\MultiStepFormDesign\MultiStepFormDesign;
9 use Give\DonationForms\Models\DonationForm;
10 use Give\DonationForms\Properties\FormSettings;
11 use Give\DonationForms\ValueObjects\DonationFormStatus;
12 use Give\DonationForms\ValueObjects\GoalSource;
13 use Give\FormBuilder\Actions\GenerateDefaultDonationFormBlockCollection;
14
15 /**
16 * @since 4.0.0
17 */
18 class CreateDefaultCampaignForm
19 {
20 /**
21 * @since 4.14.2 add formTitle to FormSettings
22 * @since 4.2.0 return if campaign already has default form set
23 * @since 4.1.0 Added inheritCampaignColors property to FormSettings
24 * @since 4.0.0
25 *
26 * @throws Exception
27 */
28 public function __invoke(Campaign $campaign)
29 {
30 if ($campaign->defaultFormId) {
31 return;
32 }
33
34 $defaultCampaignForm = DonationForm::create([
35 'title' => $campaign->title,
36 'status' => DonationFormStatus::PUBLISHED(),
37 'settings' => FormSettings::fromArray([
38 'formTitle' => $campaign->title,
39 'showHeader' => false,
40 'enableDonationGoal' => false,
41 'goalAmount' => $campaign->goal,
42 'goalType' => $campaign->goalType->getValue(),
43 'goalSource' => GoalSource::CAMPAIGN()->getValue(),
44 'designId' => MultiStepFormDesign::id(),
45 'inheritCampaignColors' => true,
46 ]),
47 'blocks' => (new GenerateDefaultDonationFormBlockCollection())(),
48 ]);
49
50 give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm->id, true);
51 }
52 }
53