Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patch for retriveLinks on BlocksRetriever class #123

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading