Skip to content

Commit

Permalink
Widgets editor: Fix error when saving empty Legacy Widget block (#32359)
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks authored and youknowriad committed Jun 7, 2021
1 parent 39db7d4 commit 029b797
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/edit-widgets/src/store/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export function transformWidgetToBlock( widget ) {
export function transformBlockToWidget( block, relatedWidget = {} ) {
let widget;

if ( block.name === 'core/legacy-widget' ) {
const isValidLegacyWidgetBlock =
block.name === 'core/legacy-widget' &&
( block.attributes.id || block.attributes.instance );

if ( isValidLegacyWidgetBlock ) {
widget = {
...relatedWidget,
id: block.attributes.id ?? relatedWidget.id,
Expand All @@ -56,13 +60,6 @@ export function transformBlockToWidget( block, relatedWidget = {} ) {
};
}

// Delete deprecated properties.
delete widget.description;
delete widget.name;
delete widget.number;
delete widget.settings;
delete widget.widget_class;

// Delete read-only properties.
delete widget.rendered;
delete widget.rendered_form;
Expand Down

0 comments on commit 029b797

Please sign in to comment.