cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Make it possible to add to form configuration screen

Open ryanmitchell opened this issue 1 year ago • 17 comments

Not sure if this is niche, but it would be really useful to be able to add to the form configuration screen so that fields can be modified through the UI. This is specifically useful when we want to integrate with 3rd party services (such as adding a Zapier URL), but also may be useful for other developers to add things such as success messages.

I can also see it being useful for add-ons (such as Mailchimp).

I initially thought of adding a "configuration" section with a blueprint builder, but that is a config screen to modify a config screen and that doesn't feel right to me.

So instead, what I'm suggesting is adding ContainsData to forms, and giving the ability for developers to register extra fields using the following method:

\Statamic\Facades\Form::appendConfigFields($handles, string $display, array $fields);

You can also pass a $handle of '*' if you want the fields to be added to all forms.

This then appends a config section to the screen as follows:

Screenshot 2023-07-26 at 12 38 23

My config call for this is as follows:


\Statamic\Facades\Form::appendConfigFields('*', __('Configuration of something else'), [
    'data' => [
        'type' => 'grid',
        'mode' => 'stacked',
        'add_row' => __('Add Field'),
        'fields' => [
            [
                'handle' => 'handle',
                'field' => [
                    'type' => 'slug',
                    'display' => __('Handle'),
                    'validate' => [
                        'required',
                    ],
                ],
            ],
            [
                'handle' => 'value',
                'field' => [
                    'type' => 'text',
                    'display' => __('Value'),
                    'validate' => [
                        'required',
                    ],
                ],
            ],
        ],
    ],
]);

Is this something you might consider?

Closes statamic/ideas#1112

ryanmitchell avatar Jul 26 '23 11:07 ryanmitchell

+1, this would be a really valuable addition! 👍

caseydwyer avatar Aug 12 '23 16:08 caseydwyer

[maybe a dumb] question on this...would config values be accessible within the blueprint? Eg, could you set blueprint field visibility based on one of these new config fields? 🤔

caseydwyer avatar Dec 04 '23 18:12 caseydwyer

@caseydwyer not as things stand

ryanmitchell avatar Dec 04 '23 19:12 ryanmitchell

If you get a chance could you update this for the latest Statamic version? (for composer patches) Thanks :)

godismyjudge95 avatar Jan 10 '24 17:01 godismyjudge95

@godismyjudge95 sure - done!

ryanmitchell avatar Jan 10 '24 18:01 ryanmitchell

I have been using this pull request as a patch and the latest version seems to be missing use Statamic\Support\Arr; from the appendConfigFields function

plexus77 avatar Apr 09 '24 04:04 plexus77

@plexus77 its definitely there: https://github.com/ryanmitchell/cms/blob/77852db07f3eed2136354e0e7a40f75244f62c4a/src/Forms/FormRepository.php#L12

ryanmitchell avatar Apr 09 '24 05:04 ryanmitchell

Apologies but the patch I am using attached to this pull request includes it also. Perhaps the patch did not apply properly for some reason.

plexus77 avatar Apr 09 '24 05:04 plexus77

This would be cool to have for v5 once it lands!

andjsch avatar May 03 '24 13:05 andjsch

@ryanmitchell would it be possible to update this pr? Attempting to update a few sites to Statamic 5

godismyjudge95 avatar May 14 '24 18:05 godismyjudge95

@godismyjudge95 its already been updated for 5.x

ryanmitchell avatar May 14 '24 19:05 ryanmitchell

@godismyjudge95 its already been updated for 5.x

Oh weird... I was getting an error about not being able to apply it as a composer patch. Must be something on my end then.

godismyjudge95 avatar May 14 '24 19:05 godismyjudge95

Hi there the patch is also not applying correctly for me either for example I can see that there are some extra classes in the use statement for eample this is the updated patch for the Form class

--- /dev/null
+++ ../src/Forms/Form.php
@@ -7,6 +7,7 @@
 use Statamic\Contracts\Data\Augmented;
 use Statamic\Contracts\Forms\Form as FormContract;
 use Statamic\Contracts\Forms\Submission;
+use Statamic\Data\ContainsData;
 use Statamic\Contracts\Forms\SubmissionQueryBuilder;
 use Statamic\Data\HasAugmentedInstance;
 use Statamic\Events\FormBlueprintFound;

The original patch did not have the SubmissionQueryBuilder line in it so was rejected

plexus77 avatar May 19 '24 06:05 plexus77

Hi there the patch is also not applying correctly for me either for example I can see that there are some extra classes in the use statement for eample this is the updated patch for the Form class

--- /dev/null
+++ ../src/Forms/Form.php
@@ -7,6 +7,7 @@
 use Statamic\Contracts\Data\Augmented;
 use Statamic\Contracts\Forms\Form as FormContract;
 use Statamic\Contracts\Forms\Submission;
+use Statamic\Data\ContainsData;
 use Statamic\Contracts\Forms\SubmissionQueryBuilder;
 use Statamic\Data\HasAugmentedInstance;
 use Statamic\Events\FormBlueprintFound;

The original patch did not have the SubmissionQueryBuilder line in it so was rejected

Yes it’s been update for v5 and there are other changes made in v5. If you are trying to patch tov4 it won’t work.

ryanmitchell avatar May 19 '24 07:05 ryanmitchell

I'm using v5 though, it is this patch https://patch-diff.githubusercontent.com/raw/statamic/cms/pull/8491.patch that we should be using right?

diff --git a/src/Forms/Form.php b/src/Forms/Form.php
index ed905535a2..9d9346eae4 100644
--- a/src/Forms/Form.php
+++ b/src/Forms/Form.php
@@ -7,6 +7,7 @@
 use Statamic\Contracts\Data\Augmented;
 use Statamic\Contracts\Forms\Form as FormContract;
 use Statamic\Contracts\Forms\Submission;
+use Statamic\Data\ContainsData;
 use Statamic\Data\HasAugmentedInstance;
 use Statamic\Events\FormBlueprintFound;
 use Statamic\Events\FormCreated;
@@ -25,7 +26,7 @@

The code above is from the patch, it's not correct as there is no SubmissionQueryBuilder line, it will fail as the latest version of v5 which I am using has that in it.

plexus77 avatar May 19 '24 07:05 plexus77

The query builder line hasn't been touched by the PR:

CleanShot 2024-05-19 at 08 58 15@2x

If its not in the patch theres not a lot I can do about that, its a Github issue.

ryanmitchell avatar May 19 '24 07:05 ryanmitchell

Ok no probs, I have patched them myself anyway so all good for now, hopefully this PR can be merged in soon, thanks for having a look.

plexus77 avatar May 19 '24 09:05 plexus77

Amazing, this will be so useful. Thank you.

ryanmitchell avatar Jul 30 '24 05:07 ryanmitchell