admin管理员组文章数量:1122832
Hey folks So Im pretty new to this react + php in wordpress and I found one article where it showed how to extend a core block, which works fine for group and some basic block but When i tried to extend some settings of core/navigation it starts behaving weird and dont actually add the class in FE based on newly added/updated attributes further i did some debugging and it looks like editor only reads core/navigation and not its nested child which I'm guessing is core/navigation-link when i use
addFilter("blocks.getSaveContent.extraProps");
So here is the whole snippet which explain what I'm trying to do.
function addaddRadiusSliderAttrToNavLink(settings, name) {
// this works fine and it extends the settings
if (typeof settings.attributes !== "undefined") {
if (
name == "core/navigation-link" ||
) {
settings.attributes = Object.assign(settings.attributes, {
borderRadius: {
type: "number",
},
});
}
}
return settings;
}
addFilter(
"blocks.registerBlockType",
"awp/add-border-radius",
addaddRadiusSliderAttrToNavLink
);
// works fine and updates attributes
const addRadiusSliderToNavigationLink = createHigherOrderComponent(
(BlockEdit) => {
return (props) => {
return (
<>
<Fragment>
<BlockEdit {...props} />
{props.isSelected &&
(props.name == "core/navigation-link" ) && (
<InspectorControls>
<PanelBody
title={__("Border setting", "awp")}
initialOpen={false}
>
<RangeControl
label={__("Set Border Radius", "awhitepixel")}
value={props.attributes.borderRadius}
onChange={(val) => {
props.setAttributes({
borderRadius: val,
});
}}
min={0}
max={8}
beforeIcon="format-image"
allowReset={true}
resetFallbackValue={7}
withInputField={false}
/>
</PanelBody>
</InspectorControls>
)}
</Fragment>
</>
);
};
},
"addRadiusSliderToNavigationLink"
);
addFilter(
"editor.BlockEdit",
"awp/group-advanced-control",
addRadiusSliderToNavigationLink
);
Issue is here in below function
const applyRadiusSliderToNavigationLink = (
extraProps,
blockType,
attributes
) => {
if (
blockType.name == "core/navigation-link"
) {
// Apply your class logic to navigation-list block
const { borderRadius} = attributes;
extraProps.className = classnames(extraProps.className, {
"border-radius-": borderRadius,
});
}
return extraProps;
};
addFilter(
"blocks.getSaveContent.extraProps",
"awp/group-apply-responsive-class",
applyRadiusSliderToNavigationLink
);
本文标签: javascriptExtend WordPress Gutenberg corenavigationlink
版权声明:本文标题:javascript - Extend WordPress Gutenberg corenavigation-link 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300888a1930983.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论