Conversation
can't find any references to it on GitHub, Discord or Slack so it's probably safe to remove. i don't think it has worked since #2092 anyway.
the fluent getter/setter for the `blueprint` property was removed in #2092 and i can't see anything using it. probably safe to remove.
... and make it forwards compatible
| public function fields() | ||
| { | ||
| if (! $blueprint = $this->blueprint()) { | ||
| throw BlueprintUndefinedException::create($this); |
There was a problem hiding this comment.
I've removed this exception as I don't believe it's been thrown since the v3 alpha (specifically since #2092 made blueprint() return an empty blueprint if none existed).
I also can't find any references to it on GitHub, Discord or Slack so it's probably safe to remove.
|
|
||
| protected $handle; | ||
| protected $title; | ||
| protected $blueprint; |
There was a problem hiding this comment.
I've removed this property as the fluent getter/setter for it was removed in the v3 alpha days (in #2092) and nothing seems to be using it. Probably safe to remove.
| { | ||
| public function __invoke($form) | ||
| { | ||
| // TOOD: Remove from this controller when wiring up the form builder. |
There was a problem hiding this comment.
As the TODO suggests, I'm planning on removing this when I wire up the form builder. It's just here for now so we can verify all the select/unselect logic works.
There was a problem hiding this comment.
@duncanmcclean maybe make this TODO so you can find it later? minor typo
There was a problem hiding this comment.
Doh! Sorted the typo.
This pull request refactors how form fields work under the hood, ahead of some changes we're making to forms.
TLDR: Form fields aren't stored in blueprints anymore, they're stored under a
fieldskey in the form data. Fields will be migrated the next time the form is saved.Problem
We want to offer different fieldtypes when editing forms than the ones available elsewhere.
A couple of examples:
Solution
Because they aren't exactly 1:1 mappings with existing fieldtypes, we need to create a layer in between the form builder and the underlying blueprint fields.
This layer (which we're referring to as "form fieldtypes") is responsible for wrapping normal fieldtypes. They can expose their own names, keywords, icons, config options, etc.
Then, instead of storing fields in a blueprint, like you would with normal fieldtypes, fields are stored in the form's data and map to one of the "form fieldtypes".
Behind the scenes, there are new
FormFields,FormFieldandFormFieldtypeclasses powering everything.When rendering form fields — in the CP, on the frontend or in emails — the form fields will be converted to traditional blueprint fields.
Migrating blueprints
When the fields key is missing, Statamic will read from the form blueprint and convert fields to the new "form fieldtypes" on-the-fly.
For example:
textfields will becomeshort_answerfields,textareafields will becomelong_answerfields, etc.When there's no matching "form fieldtype" for an existing field, the
Fallbackform fieldtype will be used which literally returns the field config from the fieldtype'stoFieldArray().The
fieldskey will be written to the form data array and the blueprint will be deleted the next time the form is saved.Custom Form Fieldtypes
To build a custom form fieldtype, create a class that extends Statamic's
FormFieldtypeand add atoFieldArray()method.The
toFieldArray()method is responsible for building the underlying blueprint field used when rendering the field.You may also add a
configFieldItems()method to define any config options which will be editable in the UI.In an app, simply put your class in the
app/FormFieldtypesdirectory and it'll be registered automatically.In an addon, put your class in the
src/FormFieldtypesdirectory or register it manually in yourServiceProvider.php:$selectableInForms&makeSelectableInForms()The
$selectableInFormsproperty and themakeSelectableInForms()/makeUnselectableInForms()methods on theFieldtype classhave been deprecated and will be removed in v7.Until then, fieldtypes using these will continue to show in the form builder — they'll be automatically wrapped in the fallback form fieldtype.
Going forward, you should create a
FormFieldtypeclass instead. You can then usemakeSelectable()ormakeUnselectable()on the form fieldtype class directly: