diff --git a/src/redturtle/volto/adapters/blocks_linkintegrity_blocksfield.py b/src/redturtle/volto/adapters/blocks_linkintegrity_blocksfield.py index 4fbf911..4fce912 100644 --- a/src/redturtle/volto/adapters/blocks_linkintegrity_blocksfield.py +++ b/src/redturtle/volto/adapters/blocks_linkintegrity_blocksfield.py @@ -34,7 +34,6 @@ def retrieveLinks(self): context=self.context, portal_type=self.context.portal_type ) schemas = [i for i in additional_schema] + [schema] - links = set() for schema in schemas: for name, field in getFieldsInOrder(schema): if isinstance(field, RichText): diff --git a/src/redturtle/volto/monkey.py b/src/redturtle/volto/monkey.py index 6b1d663..b3739d6 100644 --- a/src/redturtle/volto/monkey.py +++ b/src/redturtle/volto/monkey.py @@ -8,7 +8,9 @@ from plone.event.interfaces import IEventAccessor from plone.event.interfaces import IRecurrenceSupport from plone.event.recurrence import recurrence_sequence_ical -from plone.restapi.deserializer.blocks import iterate_children +from plone.restapi.blocks import iter_block_transform_handlers +from plone.restapi.blocks import visit_blocks +from plone.restapi.interfaces import IBlockFieldLinkIntegrityRetriever # from plone.event.utils import pydt from Products.CMFPlone.interfaces import IConstrainTypes @@ -196,22 +198,22 @@ def search_for_similar(*args, **kwargs): return [] -def plone_restapi_slateblocklinksretriever_call(self, block): +def plone_restapi_blocks_linkintegrity_blocksretriever_retrieveLinks(self): """ - plone.restapi.blocks_linkintegrity.SlateBlockLinksRetriever.__call__ patch - Add default to get at line 208 + plone.restapi.blocks_linkintegrity.BlocksRetriever.retrieveLinks patch + Add check on block """ - value = (block or {}).get(self.field, []) - children = iterate_children(value or []) - - for child in children: - node_type = child.get("type", "") - if node_type: - handler = getattr(self, f"handle_{node_type}", None) - if handler: - value = handler(child) - if value: - self.links.append(value) - - return self.links + links = set() + blocks = getattr(self.context, "blocks", {}) + if not blocks: + return links + for block in visit_blocks(self.context, blocks): + if not isinstance(block, dict): + continue + + for handler in iter_block_transform_handlers( + self.context, block, IBlockFieldLinkIntegrityRetriever + ): + links |= set(handler(block)) + return links diff --git a/src/redturtle/volto/monkey.zcml b/src/redturtle/volto/monkey.zcml index 763ed32..60786fa 100644 --- a/src/redturtle/volto/monkey.zcml +++ b/src/redturtle/volto/monkey.zcml @@ -59,10 +59,10 @@ />