Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
use custom renderblocks until slate integration
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Oct 4, 2022
1 parent 164c0db commit b626491
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/customizations/volto/components/theme/View/RenderBlocks.jsx
Original file line number Diff line number Diff line change
@@ -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) ? (
<CustomTag>
{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 ? (
<StyleWrapper key={block} {...props} id={block} data={blockData}>
<Block
id={block}
metadata={metadata}
properties={content}
data={blockData}
path={getBaseUrl(location?.pathname || '')}
blocksConfig={blocksConfig}
/>
</StyleWrapper>
) : (
<div key={block}>
{intl.formatMessage(messages.unknownBlock, {
block: content[blocksFieldname]?.[block]?.['@type'],
})}
</div>
);
})}
</CustomTag>
) : (
''
);
};

export default injectIntl(RenderBlocks);

0 comments on commit b626491

Please sign in to comment.