Skip to content

Commit

Permalink
add patch for retriveLinks on BlocksRetriever class (#123)
Browse files Browse the repository at this point in the history
* add patch for retriveLinks on BlocksRetriever class

* isort
  • Loading branch information
eikichi18 authored Nov 29, 2024
1 parent 5d94385 commit 4d0f752
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
36 changes: 19 additions & 17 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
/>

<monkey:patch
original="__call__"
replacement=".monkey.plone_restapi_slateblocklinksretriever_call"
class="plone.restapi.blocks_linkintegrity.SlateBlockLinksRetriever"
description="Fix default of get methon on dict"
original="retrieveLinks"
replacement=".monkey.plone_restapi_blocks_linkintegrity_blocksretriever_retrieveLinks"
class="plone.restapi.blocks_linkintegrity.BlocksRetriever"
description="Add check on block"
preserveOriginal="True"
/>

Expand Down

0 comments on commit 4d0f752

Please sign in to comment.