Skip to content

Instantly share code, notes, and snippets.

@tiberiuichim
Last active May 5, 2020 15:24
Show Gist options
  • Save tiberiuichim/3a052a6634c97adabeea363b45f2aa3b to your computer and use it in GitHub Desktop.
Save tiberiuichim/3a052a6634c97adabeea363b45f2aa3b to your computer and use it in GitHub Desktop.

Registration of adapter:

  <subscriber factory=".blocks.TextBlockConverter" provides="plone.restapi.interfaces.IBlockDeserializer" />

What it looks like:

@implementer(IBlockDeserializer)
@adapter(IBlocks, IBrowserRequest)
class TextBlockConverter(object):
    order = 100
    block_field_name = "text"
    
    def __call__(self):
       ""

How they are discovered:

zope.component.subscribers([self.context, self.request], IBlockDeserializer)
@tiberiuichim
Copy link
Author

tiberiuichim commented May 5, 2020

The alternative is to declare them the same:

@implementer(IBlockDeserializer)
@adapter(IBlocks, IBrowserRequest)
class TextBlockConverter(object):
    order = 100
    block_field_name = "text"
    
    def __call__(self):
       ""

But to register with a unique name that doesn't match anything else (or there's a ZCA conflict):

<adapter factory=".blocks.TextBlockConverter" name="something-unique" />

They would be discovered as:

for name_ignored, adapter in getAdapters((self.context, self.request), IBlockDeserializer):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment