Field API: rename text to string to align with block.json API#74105
Field API: rename text to string to align with block.json API#74105oandregal wants to merge 6 commits into
text to string to align with block.json API#74105Conversation
youknowriad
left a comment
There was a problem hiding this comment.
This is a good thing for me. I wonder if we should keep a deprecation and back compat for a couple releases (like we used to do in early Gutenberg) as a courtesy for users, give them sometime to upgrade and leave the breaking change for a later release).
7cba35b to
34f3d99
Compare
text to string to align with block.json API
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I relived this scaffolding PR I had and scoped it to only rename the |
|
Flaky tests detected in 0ff122f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22100155440
|
| @@ -774,7 +774,7 @@ export const TextComponent = ( { | |||
| manyElements: boolean; | |||
| } ) => { | |||
| const textFields = useMemo( | |||
There was a problem hiding this comment.
Nit: stringFields. Similarly for TextComponent.
| type: 'text', | ||
| type: 'string', | ||
| render, | ||
| Edit: 'text', |
There was a problem hiding this comment.
Should we update the Edit to string too?
There was a problem hiding this comment.
No, I don't think so. The controls aren't a 1:1 match with field types, and text/textarea remain a useful nomenclature in the domain of UI controls.
|
This is an impactful change and I'd echo Riad to keep the |
|
I think aligning here is good, but I'll just note that on the block.json side things can also get complicated, as we have both type // {"type":"array","source":"query"}
// {"type":"boolean","source":"attribute"}
{"type":"rich-text","source":"rich-text"}
{"type":"string","source":"attribute"}
{"type":"string","source":"html"}
{"type":"string","source":"raw"}`jq` queryjq -rc '.attributes.[]? | select(.source) | {type, source}' packages/block-library/src/*/block.json | sort -u |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@youknowriad @ntsekouras every breaking change we've introduced would qualify as something we could maintain a few releases. This change is no different from others we've done ( |
|
@mcsf Thanks for the nudge. Taking the following atts from the button block: "linkTarget": {
"type": "string",
"source": "attribute",
"selector": "a",
"attribute": "target",
"role": "content"
},
"rel": {
"type": "string",
"source": "attribute",
"selector": "a",
"attribute": "rel",
"role": "content"
},
"placeholder": {
"type": "string"
},
"backgroundColor": {
"type": "string"
},
"textColor": {
"type": "string"
},These are the Field API types I'd assign to each:
It's not a 1:1 match from block attribute types to Field API types. We're going to need better heuristics to match an attribute to the proper Field API type (perhaps format and others as discussed there?), and there will be a mapping of some kind. Whether the Field API type is called I scaffolded this PR a few months ago in a conversation with Riad/Héctor. I didn't give it much thought back in the day, to be honest. In updating it to today's code, I already removed some parts that were suggested back in the day (elements to enum) because it was confusing. Now that you nudged me to think more about this, I cannot help but think that this is also unnecessary. I don't feel strongly either way, but given the cost/benefit, I lean towards maintaining the status quo. I'm going to let this PR sit here for a few days in case the conversation evolves. |
|
before WordPress 5.0 we had a policy in Gutenberg where we'd introduce a breaking change, if it's easy to shim we shim it for 2 releases and remove the shim in the third release. Maybe something like this could work here. |
Related #74102
What?
This PR renames the
textfield type to bestring.Why?
So it's aligned with block.json and the block-based controls we create going forward (PHP-only, block fields), don't need any type mapping — both block.json and the Field API use
string.How?
textstringNot done:
While they reflect similar concerns, they have a different shape:
enumis a list of values,elementsis a list of options (object with value/label properties). If we were to do the rename, I argue we should support the block.json shape (a list of values) and we could remove this code.Testing Instructions