PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.4
GiveWP – Donation Plugin and Fundraising Platform v4.15.4
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
64 lines 2.1 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 use Give\Helpers\Language;
13
14 /**
15 * Route to create a new form
16 */
17 class CreateFormRoute
18 {
19 /**
20 * @since 4.14.2 update default form title
21 * @since 3.22.0 Add locale support
22 * @since 3.1.0 updated default form blocks to be generated from block models instead of json
23 * @since 3.0.0
24 *
25 * @return void
26 * @throws Exception
27 */
28 public function __invoke()
29 {
30 if (isset($_GET['page']) && FormBuilderRouteBuilder::SLUG === $_GET['page']) {
31 $locale = $_GET['locale'] ?? '';
32
33 // Little hack for alpha users to make sure the form builder is loaded.
34 if (!isset($_GET['donationFormID'])) {
35 wp_redirect(FormBuilderRouteBuilder::makeCreateFormRoute($locale)->getUrl());
36 exit();
37 }
38 if ('new' === $_GET['donationFormID']) {
39 // Make sure the Form will be created using the proper locale
40 $locale = $_GET['locale'] ?? '';
41 Language::switchToLocale($locale);
42
43 $form = new DonationForm([
44 'title' => __('Donation Form', 'give'),
45 'status' => DonationFormStatus::DRAFT(),
46 'settings' => FormSettings::fromArray([
47 'enableDonationGoal' => true,
48 'goalAmount' => 1000,
49 'inheritCampaignColors' => true,
50 ]),
51 'blocks' => (new GenerateDefaultDonationFormBlockCollection())(),
52 ]);
53
54 Hooks::doAction('givewp_form_builder_new_form', $form);
55
56 $form->save();
57
58 wp_redirect(FormBuilderRouteBuilder::makeEditFormRoute($form->id, $locale)->getUrl());
59 exit();
60 }
61 }
62 }
63 }
64