Subscribe to add-tile events

Hi everyone,

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:

<subscriber
    for="*
         zope.lifecycleevent.IObjectAddedEvent"
    handler=".events.after_created"
    />

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.

How do I do that?

well, this is an interesting question: at first I though adding a tile did not fire an event but then I found this:

sou you probably have to register against plone.tiles.interfaces.ITileType or an interface inheriting from it.

but better ask @datakurre about this.

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.

Also deleting page does not fire any tile event.

Thanks! That works for my current setup, but it will catch events for every tile (to me it's ok, I only have one in this situation).

I wonder if I can check to a specific tile.