[英]Wordpress: Block validation failed after changing default settings for a block
我正在尝试更改 Gutenberg 块的默认块设置。 我正在使用以下代码:
const { addFilter } = wp.hooks;
addFilter(
"blocks.registerBlockType",
"my_theme/change_block_settings",
my_theme_change_block_settings
);
let my_theme_processedBlocks = {};
function my_theme_change_block_settings( settings, name ) {
if ( "core/gallery" === name ) {
if(!my_theme_processedBlocks[name]) {
my_theme_processedBlocks[name] = true;
return lodash.merge({}, settings, {
attributes: {
columns: { default: 5 },
}
});
}
}
return settings;
}
它可以工作,但如果我稍后将列更改为不同的数字(例如 6),它会破坏所有旧块。 它们显示“此块包含意外或无效内容”。 信息。 在控制台中我看到了这个:
Block validation: Expected attribute `class` of value `wp-block-gallery has-nested-images columns-6 columns-5`, saw `wp-block-gallery has-nested-images columns-5`.
Block validation: Block validation failed for `core/gallery`.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.