admin管理员组文章数量:1123945
I'm the author of the Falang multilanguage plugin for wordpress (/), trying to add a feature allowing site admins to translate their site from inside the gutenberg bloc editor
I have already make this with Elementor/Divi/Yootheme/WPbakery
The principle is to dynamically add some attributes you have to translate like input text/content/image depending of the block type
- The content for the heading block
- The image and alt text for the image block
- ...
For this i use the filter getSaveElement from #gutenberg/packages/blocks/src/api/serializer.js
The serializer.js funtion has this signature
export function getSaveElement(blockTypeOrName,attributes,innerBlocks = [])
in the serializer the filter i used but the innerBlocks are not in the parameters
return applyFilters('blocks.getSaveElement',element,blockType,attributes);
my Filter getSaveElement parse the attribute for each languages and i store the render
All work fine for simple blocks but for block like core/list-item it doesn't , probably due to the innerBlocks not set correctly (not set an empty array is used)
Here is a part of the function use for the getSaveElement Filter (call saveContentOrg function)
function saveContentOrg( element, blockType, attributes ) {
.....//logic code here
Object.values(langues)
.forEach((langue) => {
let locAttributes = {...attributes}
attribs_to_change_content.forEach(attr => {
let encodedValue = attributes[attr + langue.js_locale];
if (encodedValue) {
locAttributes[attr] = decode64(encodedValue)
}
})
if (blockType.name != 'core/list-item'){
var localised_content = blockType.save({attributes: locAttributes, innerBlocks: []})
} else {
//var localised_content = '<li>'+attributes['content']+'</li>'
}
if (localised_content) {
attributes["render" + langue.js_locale] = encode64(renderToString(localised_content))
}
})
// return the element wrapped in a div
return element;
}
My question is, is there a way to get the innerBlocks of the getSaveElement from the serailized.js in the 'blocks.getSaveElement',
Thanks a lot. Stéphane
本文标签: plugin developmentBlock Editor Filter getSaveElement and innerBlocks
版权声明:本文标题:plugin development - Block Editor: Filter getSaveElement and innerBlocks 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736607027a1945352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论