PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8
GiveWP – Donation Plugin and Fundraising Platform v4.16.8
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 2.31.0 2.31.1 All 253 releases
give / src / Campaigns / Actions / CreateDefaultCampaignForm.php
CreateDefaultCampaignForm.php
55 lines 1.9 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.16.8 Set formStatus on FormSettings so it agrees with the form's own status.
22 * @since 4.14.2 add formTitle to FormSettings
23 * @since 4.2.0 return if campaign already has default form set
24 * @since 4.1.0 Added inheritCampaignColors property to FormSettings
25 * @since 4.0.0
26 *
27 * @throws Exception
28 */
29 public function __invoke(Campaign $campaign)
30 {
31 if ($campaign->defaultFormId) {
32 return;
33 }
34
35 $defaultCampaignForm = DonationForm::create([
36 'title' => $campaign->title,
37 'status' => DonationFormStatus::PUBLISHED(),
38 'settings' => FormSettings::fromArray([
39 'formTitle' => $campaign->title,
40 'formStatus' => DonationFormStatus::PUBLISHED,
41 'showHeader' => false,
42 'enableDonationGoal' => false,
43 'goalAmount' => $campaign->goal,
44 'goalType' => $campaign->goalType->getValue(),
45 'goalSource' => GoalSource::CAMPAIGN()->getValue(),
46 'designId' => MultiStepFormDesign::id(),
47 'inheritCampaignColors' => true,
48 ]),
49 'blocks' => (new GenerateDefaultDonationFormBlockCollection())(),
50 ]);
51
52 give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm->id, true);
53 }
54 }
55