From b626491174d610f404151994e8577573026efa0a Mon Sep 17 00:00:00 2001 From: andreiggr Date: Tue, 4 Oct 2022 13:32:19 +0300 Subject: [PATCH] use custom renderblocks until slate integration --- .../components/theme/View/RenderBlocks.jsx | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/customizations/volto/components/theme/View/RenderBlocks.jsx diff --git a/src/customizations/volto/components/theme/View/RenderBlocks.jsx b/src/customizations/volto/components/theme/View/RenderBlocks.jsx new file mode 100644 index 0000000..148c996 --- /dev/null +++ b/src/customizations/volto/components/theme/View/RenderBlocks.jsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { getBaseUrl, applyBlockDefaults } from '@plone/volto/helpers'; +import { defineMessages, injectIntl } from 'react-intl'; +import { map } from 'lodash'; +import { + getBlocksFieldname, + getBlocksLayoutFieldname, + hasBlocksData, +} from '@plone/volto/helpers'; +import StyleWrapper from '@plone/volto/components/manage/Blocks/Block/StyleWrapper'; +import config from '@plone/volto/registry'; + +const messages = defineMessages({ + unknownBlock: { + id: 'Unknown Block', + defaultMessage: 'Unknown Block {block}', + }, +}); + +const RenderBlocks = (props) => { + const { content, intl, location, metadata } = props; + const blocksFieldname = getBlocksFieldname(content); + const blocksLayoutFieldname = getBlocksLayoutFieldname(content); + const blocksConfig = props.blocksConfig || config.blocks.blocksConfig; + const CustomTag = props.as || React.Fragment; + + return hasBlocksData(content) ? ( + + {map(content[blocksLayoutFieldname].items, (block) => { + const Block = + blocksConfig[content[blocksFieldname]?.[block]?.['@type']]?.view; + + const blockData = applyBlockDefaults({ + data: content[blocksFieldname][block], + intl, + metadata, + properties: content, + }); + + return Block ? ( + + + + ) : ( +
+ {intl.formatMessage(messages.unknownBlock, { + block: content[blocksFieldname]?.[block]?.['@type'], + })} +
+ ); + })} +
+ ) : ( + '' + ); +}; + +export default injectIntl(RenderBlocks);