diff --git a/src/plone/restapi/services/blocktypes/__init__.py b/src/plone/restapi/services/blocktypes/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/plone/restapi/services/blocktypes/configure.zcml b/src/plone/restapi/services/blocktypes/configure.zcml new file mode 100644 index 0000000000..56f2127305 --- /dev/null +++ b/src/plone/restapi/services/blocktypes/configure.zcml @@ -0,0 +1,15 @@ + + + + + diff --git a/src/plone/restapi/services/blocktypes/get.py b/src/plone/restapi/services/blocktypes/get.py new file mode 100644 index 0000000000..5e08aa5de2 --- /dev/null +++ b/src/plone/restapi/services/blocktypes/get.py @@ -0,0 +1,31 @@ +from plone import api +from plone.restapi.services import Service +from collections import Counter +from plone.restapi.behaviors import IBlocks +from plone.restapi.blocks import visit_blocks + + +class BlockTypesGet(Service): + def reply(self): + catalog = api.portal.get_tool(name="portal_catalog") + request_body = self.request.form + result = {} + + if request_body.get("blocktypes") != "": + blocktypes = request_body.get("blocktypes").split(",") + + for blocktype in blocktypes: + brains = catalog(object_provides=IBlocks.__identifier__) + result[blocktype] = Counter() + + for brain in brains: + obj = brain.getObject() + url = brain.getPath() # or .getURL() + title = obj.title + result[blocktype][title] = Counter() + + for block in visit_blocks(obj, obj.blocks): + if block["@type"] == blocktype: + result[blocktype][title].update({url: 1}) + + return result diff --git a/src/plone/restapi/services/configure.zcml b/src/plone/restapi/services/configure.zcml index 1f56801bd1..69599a67fa 100644 --- a/src/plone/restapi/services/configure.zcml +++ b/src/plone/restapi/services/configure.zcml @@ -13,6 +13,7 @@ +