PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.21.1
GiveWP – Donation Plugin and Fundraising Platform v3.21.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 2.31.0 2.31.1 All 253 releases
give / src / FormBuilder / Routes / CreateFormRoute.php
CreateFormRoute.php
54 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\FormBuilder\Routes;
4
5 use Exception;
6 use Give\DonationForms\Models\DonationForm;
7 use Give\DonationForms\Properties\FormSettings;
8 use Give\DonationForms\ValueObjects\DonationFormStatus;
9 use Give\FormBuilder\Actions\GenerateDefaultDonationFormBlockCollection;
10 use Give\FormBuilder\FormBuilderRouteBuilder;
11 use Give\Helpers\Hooks;
12
13 /**
14 * Route to create a new form
15 */
16 class CreateFormRoute
17 {
18 /**
19 * @since 3.1.0 updated default form blocks to be generated from block models instead of json
20 * @since 3.0.0
21 *
22 * @return void
23 * @throws Exception
24 */
25 public function __invoke()
26 {
27 if (isset($_GET['page']) && FormBuilderRouteBuilder::SLUG === $_GET['page']) {
28 // Little hack for alpha users to make sure the form builder is loaded.
29 if (!isset($_GET['donationFormID'])) {
30 wp_redirect(FormBuilderRouteBuilder::makeCreateFormRoute());
31 exit();
32 }
33 if ('new' === $_GET['donationFormID']) {
34 $form = new DonationForm([
35 'title' => __('GiveWP Donation Form', 'give'),
36 'status' => DonationFormStatus::DRAFT(),
37 'settings' => FormSettings::fromArray([
38 'enableDonationGoal' => true,
39 'goalAmount' => 1000,
40 ]),
41 'blocks' => (new GenerateDefaultDonationFormBlockCollection())(),
42 ]);
43
44 Hooks::doAction('givewp_form_builder_new_form', $form);
45
46 $form->save();
47
48 wp_redirect(FormBuilderRouteBuilder::makeEditFormRoute($form->id));
49 exit();
50 }
51 }
52 }
53 }
54