Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
887c31f
Properly apply styles and classes to the form block
aristath Nov 1, 2023
cd9b0a7
CS fix
aristath Nov 1, 2023
568083a
apply changes in the editor - fixes typography issue
aristath Nov 2, 2023
5121b86
A better method to save styles & classes
aristath Nov 2, 2023
8283769
revert index.php changes
aristath Nov 2, 2023
926570e
remove className: false
aristath Dec 4, 2023
a1037d0
Remove unnecessary styles and classes
t-hamano Dec 4, 2023
996f280
Merge branch 'trunk' into try/fix-form-styles
aristath Jan 31, 2024
b8474c8
Add deprecation
aristath Jan 31, 2024
6e7c287
Merge branch 'trunk' into try/fix-form-styles
aristath Feb 1, 2024
f612d4e
Merge branch 'trunk' into try/fix-form-styles
aristath Feb 13, 2024
c6cdda0
WIP - fix deprecation
aristath Feb 16, 2024
de8f0e1
Merge branch 'trunk' into try/fix-form-styles
aristath Feb 16, 2024
abb69b9
Add anchor attribute to deprecated.js
aristath Feb 19, 2024
9f2b296
Merge branch 'trunk' into try/fix-form-styles
aristath Apr 19, 2024
3f4f6cc
Update core-blocks.md
aristath Apr 19, 2024
b0645e0
add fixture for deprecated version of block
aristath Apr 19, 2024
eb62475
Revert "add fixture for deprecated version of block"
aristath Apr 19, 2024
77efc02
remove deprecation
aristath May 20, 2024
f4c3f0e
Merge branch 'trunk' into try/fix-form-styles
t-hamano May 21, 2024
b2734fa
Add deprecation
t-hamano May 21, 2024
9c38985
Merge branch 'trunk' into try/fix-form-styles
t-hamano Jul 14, 2025
006337e
Merge branch 'trunk' into try/fix-form-styles
t-hamano Aug 10, 2025
3e9c06a
Explicitly add props and add fixtures
t-hamano Aug 10, 2025
87e931a
Merge branch 'trunk' into try/fix-form-styles
t-hamano Aug 21, 2025
8be747e
Split fixture file
t-hamano Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Explicitly add props and add fixtures
  • Loading branch information
t-hamano committed Aug 10, 2025
commit 3e9c06acd8391dc92fc2c24f1680b3687541f1b9
26 changes: 24 additions & 2 deletions packages/block-library/src/form/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import {
InnerBlocks,
useBlockProps,
getTypographyClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,
} from '@wordpress/block-editor';

const v1 = {
// The block supports here are deliberately empty despite this
Expand Down Expand Up @@ -35,6 +41,9 @@ const v1 = {
// supports at the time of the deprecation. See above for details.
anchor: {
type: 'string',
source: 'attribute',
attribute: 'id',
selector: '*',
},
backgroundColor: {
type: 'string',
Expand All @@ -56,8 +65,21 @@ const v1 = {
},
},
save( { attributes } ) {
const blockProps = useBlockProps.save();
const { submissionMethod } = attributes;
const colorProps = getColorClassesAndStyles( attributes );
const typographyProps = getTypographyClassesAndStyles( attributes );
const spacingProps = getSpacingClassesAndStyles( attributes );
const blockProps = useBlockProps.save( {
// In this deprecated version, the block support is deliberately empty.
// As a result, the useBlockProps.save() does not output style or id attributes,
// so we apply them explicitly here.
style: {
...colorProps.style,
...typographyProps.style,
...spacingProps.style,
},
id: attributes.anchor,
} );

return (
<form
Expand Down
2 changes: 2 additions & 0 deletions phpunit/class-block-fixture-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Block_Fixture_Test extends WP_UnitTestCase {
public function filter_allowed_html( $tags ) {
$tags['form']['class'] = true;
$tags['form']['enctype'] = true;
$tags['form']['style'] = true;
$tags['form']['id'] = true;
return $tags;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- wp:form {"className":"custom-class","style":{"elements":{"link":{"color":{"text":"#ff0000"}}},"color":{"text":"#ff0000","background":"#00ffff"},"typography":{"fontSize":"30px"},"spacing":{"padding":{"top":"1px","bottom":"1px","left":"2px","right":"2px"},"margin":{"top":"3px","bottom":"3px","left":"4px","right":"4px"}}}} -->
<form id="anchor" class="wp-block-form" style="color:#ff0000;background-color:#00ffff;margin-top:3px;margin-right:4px;margin-bottom:3px;margin-left:4px;padding-top:1px;padding-right:2px;padding-bottom:1px;padding-left:2px;font-size:30px" enctype="text/plain"></form>
<!-- /wp:form -->

<!-- wp:form {"className":"custom-class","style":{"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"spacing":{"padding":{"top":"var:preset|spacing|40","bottom":"var:preset|spacing|40","left":"var:preset|spacing|40","right":"var:preset|spacing|40"},"margin":{"top":"var:preset|spacing|40","bottom":"var:preset|spacing|40","left":"var:preset|spacing|40","right":"var:preset|spacing|40"}}},"backgroundColor":"accent-1","textColor":"contrast","fontSize":"x-large"} -->
<form id="anchor" class="wp-block-form" style="margin-top:var(--wp--preset--spacing--40);margin-right:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40);margin-left:var(--wp--preset--spacing--40);padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)" enctype="text/plain"></form>
<!-- /wp:form -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I have prepared two types of HTML: The first block has custom values, and the second block has preset values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I prefer the approach other blocks have taken where individual use cases are split into separate fixtures. It makes what the fixture represents and what you're testing clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated: 8be747e

78 changes: 78 additions & 0 deletions test/integration/fixtures/blocks/core__form__deprecated-v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"name": "core/form",
"isValid": true,
"attributes": {
"submissionMethod": "email",
"method": "post",
"anchor": "anchor",
"style": {
"elements": {
"link": {
"color": {
"text": "#ff0000"
}
}
},
"color": {
"text": "#ff0000",
"background": "#00ffff"
},
"typography": {
"fontSize": "30px"
},
"spacing": {
"padding": {
"top": "1px",
"bottom": "1px",
"left": "2px",
"right": "2px"
},
"margin": {
"top": "3px",
"bottom": "3px",
"left": "4px",
"right": "4px"
}
}
}
},
"innerBlocks": []
},
{
"name": "core/form",
"isValid": true,
"attributes": {
"submissionMethod": "email",
"method": "post",
"anchor": "anchor",
"backgroundColor": "accent-1",
"textColor": "contrast",
"style": {
"elements": {
"link": {
"color": {
"text": "var:preset|color|contrast"
}
}
},
"spacing": {
"padding": {
"top": "var:preset|spacing|40",
"bottom": "var:preset|spacing|40",
"left": "var:preset|spacing|40",
"right": "var:preset|spacing|40"
},
"margin": {
"top": "var:preset|spacing|40",
"bottom": "var:preset|spacing|40",
"left": "var:preset|spacing|40",
"right": "var:preset|spacing|40"
}
}
},
"fontSize": "x-large"
},
"innerBlocks": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"blockName": "core/form",
"attrs": {
"className": "custom-class",
"style": {
"elements": {
"link": {
"color": {
"text": "#ff0000"
}
}
},
"color": {
"text": "#ff0000",
"background": "#00ffff"
},
"typography": {
"fontSize": "30px"
},
"spacing": {
"padding": {
"top": "1px",
"bottom": "1px",
"left": "2px",
"right": "2px"
},
"margin": {
"top": "3px",
"bottom": "3px",
"left": "4px",
"right": "4px"
}
}
}
},
"innerBlocks": [],
"innerHTML": "\n<form id=\"anchor\" class=\"wp-block-form\" style=\"color:#ff0000;background-color:#00ffff;margin-top:3px;margin-right:4px;margin-bottom:3px;margin-left:4px;padding-top:1px;padding-right:2px;padding-bottom:1px;padding-left:2px;font-size:30px\" enctype=\"text/plain\"></form>\n",
"innerContent": [
"\n<form id=\"anchor\" class=\"wp-block-form\" style=\"color:#ff0000;background-color:#00ffff;margin-top:3px;margin-right:4px;margin-bottom:3px;margin-left:4px;padding-top:1px;padding-right:2px;padding-bottom:1px;padding-left:2px;font-size:30px\" enctype=\"text/plain\"></form>\n"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\n",
"innerContent": [ "\n\n" ]
},
{
"blockName": "core/form",
"attrs": {
"className": "custom-class",
"style": {
"elements": {
"link": {
"color": {
"text": "var:preset|color|contrast"
}
}
},
"spacing": {
"padding": {
"top": "var:preset|spacing|40",
"bottom": "var:preset|spacing|40",
"left": "var:preset|spacing|40",
"right": "var:preset|spacing|40"
},
"margin": {
"top": "var:preset|spacing|40",
"bottom": "var:preset|spacing|40",
"left": "var:preset|spacing|40",
"right": "var:preset|spacing|40"
}
}
},
"backgroundColor": "accent-1",
"textColor": "contrast",
"fontSize": "x-large"
},
"innerBlocks": [],
"innerHTML": "\n<form id=\"anchor\" class=\"wp-block-form\" style=\"margin-top:var(--wp--preset--spacing--40);margin-right:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40);margin-left:var(--wp--preset--spacing--40);padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)\" enctype=\"text/plain\"></form>\n",
"innerContent": [
"\n<form id=\"anchor\" class=\"wp-block-form\" style=\"margin-top:var(--wp--preset--spacing--40);margin-right:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40);margin-left:var(--wp--preset--spacing--40);padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)\" enctype=\"text/plain\"></form>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- wp:form {"style":{"elements":{"link":{"color":{"text":"#ff0000"}}},"color":{"text":"#ff0000","background":"#00ffff"},"typography":{"fontSize":"30px"},"spacing":{"padding":{"top":"1px","bottom":"1px","left":"2px","right":"2px"},"margin":{"top":"3px","bottom":"3px","left":"4px","right":"4px"}}}} -->
<form id="anchor" class="wp-block-form has-text-color has-background has-link-color" style="color:#ff0000;background-color:#00ffff;margin-top:3px;margin-right:4px;margin-bottom:3px;margin-left:4px;padding-top:1px;padding-right:2px;padding-bottom:1px;padding-left:2px;font-size:30px" enctype="text/plain"></form>
<!-- /wp:form -->

<!-- wp:form {"backgroundColor":"accent-1","textColor":"contrast","fontSize":"x-large","style":{"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"spacing":{"padding":{"top":"var:preset|spacing|40","bottom":"var:preset|spacing|40","left":"var:preset|spacing|40","right":"var:preset|spacing|40"},"margin":{"top":"var:preset|spacing|40","bottom":"var:preset|spacing|40","left":"var:preset|spacing|40","right":"var:preset|spacing|40"}}}} -->
<form id="anchor" class="wp-block-form has-contrast-color has-accent-1-background-color has-text-color has-background has-link-color has-x-large-font-size" style="margin-top:var(--wp--preset--spacing--40);margin-right:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40);margin-left:var(--wp--preset--spacing--40);padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)" enctype="text/plain"></form>
<!-- /wp:form -->
Loading