-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Iterate on Legacy Widget block #29960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: -1.69 kB (0%) Total Size: 1.41 MB
ℹ️ View Unchanged
|
c629341 to
6d98741
Compare
c361ca4 to
bb5878e
Compare
|
I need to test this some more, elaborate on the dot points in the PR's description, and write some documentation, but this should be ready for an initial "broad stroke" review. |
kevin940726
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work!
I'm still playing with it. Just some code smell and nitpicking for now.
packages/block-library/src/legacy-widget/edit/widget-type-selector.js
Outdated
Show resolved
Hide resolved
Rewrites the Legacy Widget block with a view to: - Handle instance attributes that can't be serialised into JSON. - Remove unnecessary block attributes. There is now only `id`, `idBase` and `instance`. - Improve how widgets that don't extend WP_Widget are handled. These are now manually saved and their data is completely seperate to the block editor. - Make the block use @wordpress/core-data APIs instead of relying on @wordpress/edit-post. This makes it possible to use the block in the Customizer, and, perhaps in the future, the site editor and post editor. - Use hooks instead of class components.
Co-authored-by: Kai Hao <[email protected]>
Co-authored-by: Kai Hao <[email protected]>
Co-authored-by: Kai Hao <[email protected]>
Co-authored-by: Kai Hao <[email protected]>
285ebaf to
4ddf54e
Compare
4ddf54e to
c2ec483
Compare
|
This should be ready now 🙂 |
kevin940726
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What this is
Rewrites the Legacy Widget block with a view to:
1) Handle instance attributes that can't be serialised into JSON. See #28902.
This is done by sending user input to the REST API which will return the instance serialized as a base64 string. The serialized data is stored in the block's
instance.encodedattribute along with a hash ininstance.hash.The complete flow of how this works is detailed in #28902 (comment).
2) Remove unnecessary block attributes. There is now only
id,idBaseandinstance.Attributes such as
number,widget_classandclassnameare not necessary to store in the block editor. Widgets that extendWP_Widgetare now represented usingidBaseandinstance. Widgets that do not extendWP_Widgetare represented usingid.See
legacy-widget/README.mda lengthier explanation.3) Improve how widgets that don't extend
WP_Widgetare handled. These are now manually saved and their data is completely seperate to the block editor.Widgets that do not extend
WP_Widgetare treated as a dumb<form>. We cannot assume anything about this kind of widgets, and so no data is stored in the block editor.See
legacy-widget/README.mda lengthier explanation.4) Make the block use
@wordpress/core-dataAPIs instead of relying on@wordpress/edit-post. This makes it possible to use the block in the Customizer. See #28618 (comment).Note that while the Legacy Widget block is now fully functional when used in the post editor or site editor, I have disabled it in these contexts. We can enable it if/when we are sure that we want to maintain support for this into the future.
5) Use hooks instead of class components.
This reduces the amount of boilerplate and makes things simpler (I think) to understand.
What to test
The only user visible changes are in the Appearance → Widgets screen, so please test adding, editing, saving, and removing Legacy Widgets here.
You can test the Core widgets by adding this line e.g. to
gutenberg.php:You can test a non-
WP_Widgetby adding this code e.g. togutenberg.php:https://gist.github.com/noisysocks/c9e20ef813d3b17a15da7e6d5bc8f611#file-marquee-php
Follow up tasks
class_namefrom the REST API. This property is deprecated.ServerSideRenderfor the Preview tab.