This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use custom renderblocks until slate integration
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/customizations/volto/components/theme/View/RenderBlocks.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |