diff --git a/src/plone/restapi/services/blocktypes/get.py b/src/plone/restapi/services/blocktypes/get.py index c4f942e5c7..5e08aa5de2 100644 --- a/src/plone/restapi/services/blocktypes/get.py +++ b/src/plone/restapi/services/blocktypes/get.py @@ -1,7 +1,8 @@ from plone import api from plone.restapi.services import Service from collections import Counter -from plone.dexterity.content import get_assignable +from plone.restapi.behaviors import IBlocks +from plone.restapi.blocks import visit_blocks class BlockTypesGet(Service): @@ -14,26 +15,17 @@ def reply(self): blocktypes = request_body.get("blocktypes").split(",") for blocktype in blocktypes: - brains = catalog.searchResults(block_types=blocktype) + brains = catalog(object_provides=IBlocks.__identifier__) result[blocktype] = Counter() for brain in brains: obj = brain.getObject() - assignable = get_assignable(obj) + url = brain.getPath() # or .getURL() + title = obj.title + result[blocktype][title] = Counter() - hasBlocksBehavior = bool( - { - behavior - for behavior in assignable.enumerateBehaviors() - if behavior.name == "volto.blocks" - } - ) - - if hasBlocksBehavior: - url = brain.getURL() # or brain.getPath() - - for block in obj.blocks.values(): - if block["@type"] == blocktype: - result[blocktype].update({url: 1}) + for block in visit_blocks(obj, obj.blocks): + if block["@type"] == blocktype: + result[blocktype][title].update({url: 1}) return result