Skip to content

Field API: rename text to string to align with block.json API#74105

Open
oandregal wants to merge 6 commits into
trunkfrom
update/fieldapi-blockjson-alignment
Open

Field API: rename text to string to align with block.json API#74105
oandregal wants to merge 6 commits into
trunkfrom
update/fieldapi-blockjson-alignment

Conversation

@oandregal
Copy link
Copy Markdown
Member

@oandregal oandregal commented Dec 18, 2025

Related #74102

What?

This PR renames the text field type to be string.

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?

Before After
Field type text string

Not done:

  • elements/getElements/useElements to enum/getEnum/useEnum.

While they reflect similar concerns, they have a different shape: enum is a list of values, elements is 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

  • Smoke test stories: DataViews, DataForm, DataviewsPicker, Fields.
  • Smoke test the site editor: Pages, Templates, Patterns.

@oandregal oandregal self-assigned this Dec 18, 2025
@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Dec 18, 2025
@oandregal oandregal added [Status] In Progress Tracking issues with work in progress [Type] Code Quality Issues or PRs that relate to code quality [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond and removed [Package] DataViews /packages/dataviews labels Dec 18, 2025
@oandregal oandregal changed the title Update/fieldapi blockjson alignment Field API: rename to align with block.json API Dec 18, 2025
Copy link
Copy Markdown
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

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

@oandregal oandregal force-pushed the update/fieldapi-blockjson-alignment branch from 7cba35b to 34f3d99 Compare February 17, 2026 13:16
@github-actions github-actions Bot added [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor [Package] Media Utils /packages/media-utils [Package] DataViews /packages/dataviews [Package] Fields /packages/fields labels Feb 17, 2026
@oandregal oandregal changed the title Field API: rename to align with block.json API Field API: rename text to string to align with block.json API Feb 17, 2026
@oandregal oandregal marked this pull request as ready for review February 17, 2026 13:16
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 17, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@oandregal oandregal requested a review from mcsf February 17, 2026 13:21
@oandregal oandregal removed the [Status] In Progress Tracking issues with work in progress label Feb 17, 2026
@oandregal
Copy link
Copy Markdown
Member Author

I relived this scaffolding PR I had and scoped it to only rename the text field type to string. See PR description.

@github-actions
Copy link
Copy Markdown

Flaky tests detected in 0ff122f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22100155440
📝 Reported issues:

@@ -774,7 +774,7 @@ export const TextComponent = ( {
manyElements: boolean;
} ) => {
const textFields = useMemo(
Copy link
Copy Markdown
Contributor

@ntsekouras ntsekouras Feb 17, 2026

Choose a reason for hiding this comment

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

Nit: stringFields. Similarly for TextComponent.

type: 'text',
type: 'string',
render,
Edit: 'text',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we update the Edit to string too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@ntsekouras
Copy link
Copy Markdown
Contributor

This is an impactful change and I'd echo Riad to keep the text around for a couple of releases.

@mcsf
Copy link
Copy Markdown
Contributor

mcsf commented Feb 17, 2026

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 string and rich-text. These are the current existing pairings of type and source in the core block library:

// {"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` query
jq -rc '.attributes.[]? | select(.source) | {type, source}' packages/block-library/src/*/block.json | sort -u

@github-actions
Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@oandregal
Copy link
Copy Markdown
Member Author

@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 (groupByField to groupBy.field, no longer providing an empty value for the select control, remove boolean form control, etc.). I worry that if we start doing it for every breaking change, it'll impact our velocity and ability to perform changes. All consumers we have so far are npm packages that can decide when to update, so we're covered.

@oandregal
Copy link
Copy Markdown
Member Author

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

  • linkTarget: url
  • rel: text
  • placeholder: text
  • backgroundColor: color
  • textColor: color

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 text or string won't make a big difference. That mapping will still be necessary. If anything, it can be argued that using string in the Field API can create confusion.

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.

@youknowriad
Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] DataViews /packages/dataviews [Package] Fields /packages/fields [Package] Media Utils /packages/media-utils [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants