Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 27 commits into from
Jul 30, 2024

Conversation

ryanmitchell
Copy link
Contributor

@ryanmitchell ryanmitchell commented Jul 26, 2023

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 ryanmitchell changed the title Give the ability to add to form configuration screen [4.x] Give the ability to add to form configuration screen Jul 26, 2023
@ryanmitchell ryanmitchell changed the title [4.x] Give the ability to add to form configuration screen [4.x] Make it possible to add to form configuration screen Aug 1, 2023
@ryanmitchell ryanmitchell marked this pull request as ready for review August 1, 2023 06:34
@caseydwyer
Copy link
Contributor

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

Copy link
Member

@duncanmcclean duncanmcclean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some initial testing, this is working well. I've left a few comments with some thoughts.

src/Forms/FormRepository.php Show resolved Hide resolved
src/Http/Controllers/CP/Forms/FormsController.php Outdated Show resolved Hide resolved
@caseydwyer
Copy link
Contributor

caseydwyer commented Dec 4, 2023

[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? 🤔

@ryanmitchell
Copy link
Contributor Author

@caseydwyer not as things stand

@godismyjudge95
Copy link
Contributor

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

@ryanmitchell
Copy link
Contributor Author

@godismyjudge95 sure - done!

@plexus77
Copy link

plexus77 commented Apr 9, 2024

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

@ryanmitchell ryanmitchell changed the base branch from 4.x to 5.x May 10, 2024 09:45
@ryanmitchell ryanmitchell changed the title [4.x] Make it possible to add to form configuration screen [5.x] Make it possible to add to form configuration screen May 10, 2024
@godismyjudge95
Copy link
Contributor

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

@ryanmitchell
Copy link
Contributor Author

@godismyjudge95 its already been updated for 5.x

@godismyjudge95
Copy link
Contributor

@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.

@plexus77
Copy link

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

@ryanmitchell
Copy link
Contributor Author

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.

@plexus77
Copy link

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.

@ryanmitchell
Copy link
Contributor Author

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.

@plexus77
Copy link

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.

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for thie PR. Sorry for the delay. 😅

Just a few minor tweaks.

  • It's Form::appendConfigFields and Form::extraConfigFor to match other places (like Fieldtype::appendConfigFields)

@jasonvarga jasonvarga merged commit f9777b8 into statamic:5.x Jul 30, 2024
16 checks passed
@ryanmitchell ryanmitchell deleted the feature/form-config-config branch July 30, 2024 05:03
@ryanmitchell
Copy link
Contributor Author

Amazing, this will be so useful. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow additional actions to be added to a form's GUI
7 participants