So, i'm using de the default p.a.tiles @@add-tile view to add tiles to a Plone site root.
I've also subscribed to IObjectAddedEvent to perform some actions after the tile is created, like so:
Everything is working as it should, except I want to subscribe to that specific tile. Since i'm subscribing to *, the code will run everytime anyting is added . I tried to use the interface on which the tile was based, but that didn't work.
The context of ObjectAddedEvent is the context object, not the actual tile. The '*' won't match the tile.
You could check inside the after_created function if the added object match the correct interface.
I think it is plone.tiles.interfaces.ITile.
This would be something like:
from plone.tiles.interfaces import ITile
def after_created(obj, event):
if ITile.providedBy(obj):
# Do stuff with tile
```
I don’t know the purpose of tile object events. They were there before me. I suspect they were for tile counter, which was removed already in the early versions.
Also there used to be pseudo tiles (html tiles baked directly into content layout), which did not fire any events, but I believe that nowadays all default tiles do fire.
Yet, it’s good to know that they cannot be trusted when drafting is enabled (the behavior is enabled by default), because tile events fire already when tiles are created or deleted during drafting. And canceling draft does NOT fire any tile events.