Opened 20 minutes ago
Last modified 18 minutes ago
#66852 new enhancement
Block Bindings: Add datetime and url block attribute types.
| Reported by: | cbravobernal | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | REST API | Version: | |
| Severity: | normal | Keywords: | 2nd-opinion has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Block attributes can only use JSON Schema types, so a block can't say that an attribute is a date or a URL. Because of that, the block bindings Attributes panel lets Post Date bind to any text field, and Post Date then shows "Invalid Date" (https://github.com/WordPress/gutenberg/issues/72446). Gutenberg hides the panel for Post Date and Navigation Link until this is fixed.
This adds datetime and url, the same type names the Field API already uses. Before Core checks a value, it maps datetime to a string with the date-time format, and url to a string with the uri format. This happens in WP_Block_Type::prepare_attributes_for_render() and in the block renderer endpoint. rest-api.php doesn't change.
Today these types raise _doing_it_wrong() and accept any value.
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/87563
Change History (1)
This ticket was mentioned in PR #16294 on WordPress/wordpress-develop by @cbravobernal.
18 minutes ago
#1
- Keywords has-patch has-unit-tests added
Block attributes can use the types
datetimeandurl, the same names the Field API uses. Before Core checks a value, it mapsdatetimeto a string with thedate-timeformat, andurlto a string with theuriformat. This happens inWP_Block_Type::prepare_attributes_for_render()and in the block renderer endpoint.rest-api.phpdoesn't change, so Core still validates with JSON Schema.Without this, these types raise
_doing_it_wrong()and accept any value, including values that aren't strings.Gutenberg PR: https://github.com/WordPress/gutenberg/pull/87563
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: The code and tests, based on https://github.com/WordPress/gutenberg/pull/73624. The block bindings e2e tests in Gutenberg passed on a site running this branch (68 passed), and the PHPUnit tests for
WP_Block_Type, the block renderer controller and block registration passed (127). Both ran before the last rebase on trunk.