cms
cms copied to clipboard
[5.x] Make it possible to add to form configuration screen
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:
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
+1, this would be a really valuable addition! 👍
[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 not as things stand
If you get a chance could you update this for the latest Statamic version? (for composer patches) Thanks :)
@godismyjudge95 sure - done!
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 its definitely there: https://github.com/ryanmitchell/cms/blob/77852db07f3eed2136354e0e7a40f75244f62c4a/src/Forms/FormRepository.php#L12
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.
This would be cool to have for v5 once it lands!
@ryanmitchell would it be possible to update this pr? Attempting to update a few sites to Statamic 5
@godismyjudge95 its already been updated for 5.x
@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.
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
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.
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.
The query builder line hasn't been touched by the PR:
If its not in the patch theres not a lot I can do about that, its a Github issue.
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.
Amazing, this will be so useful. Thank you.