Draft
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Fieldtype::makeSelectableInForms()&Fieldtype::makeUnselectableInForms()The
makeSelectableInForms()andmakeUnselectableInForms()methods on theFieldtypeclass have been deprecated and will be removed in v7.You should instead call
makeSelectable()ormakeUnselectable()on the form fieldtype class directly: