Declaring a Mosaic tile programmatically

Hello,

At the moment, we can put a Rapido block in a tile, but it is done via a generic Rapido tile, and in the settings we enter manually the Rapido block path. It is nice but we would prefer to be able to provide directly our own specific tiles from Rapido (for instance, I create a block named "Hello World", and I get a new tile named "Hello World" in the Mosaic menu).

It implies to be able to declare a new tile programmatically. And that's something Juan Pablo started at the Boston sprint.

Here is what we do:

  • we provide an adapter named according the block id:
    provideAdapter(RapidoDynamicTile, (Interface, Interface), IBasicTile, name=id)

  • we create the registry records:
    prefix = 'plone.app.mosaic.app_tiles.rapido_dynamic_tile_' + id registry = getUtility(IRegistry) registry.registerInterface(ITile, prefix=prefix) registry[prefix + '.name'] = unicode(id) registry[prefix + '.category'] = u'advanced' registry[prefix + '.tile_type'] = u'app' registry[prefix + '.settings'] = False etc...

(our code is here: https://github.com/collective/rapido.plone/blob/ploneconf2016-sprint-rapido/src/rapido/plone/handlers.py#L52 )

It does add our new tile in the Mosaic menu.
But when we try to use it, it does not work:

  • first I get a GET to @@add-tile/demo2 (demo2 is my block id), which works fine,
  • then I get a 404 error on the POST to the same @@add-tile/demo2

So something is missing in our declaration but I do not know what (and I do not have any error in the server log). I tried to pdb in plone.app.tiles browser/traversal.py but I do not see any problem.

Any hints?

Check tile directive in plone.tiles. I think a named tile utility is missing.

It's very Ploneish design:

  • Each first class tile must be registered as a named ZCA utility. The utility mostly registers some tile metadata like name, schema and permissions. Why not just registry entry? Because plone.tiles was designed to work independently from plone.registry (very Plonish design).

  • Each tile must have a view to render the tile. The tile directive registers the default view, but browser:page (or similar adapter) could be used to register e.g. content type specific views.

  • Finally, Mosaic requires its own registry registration for making tile visible in Mosaic menu. And that registration is crazy verbose, probably because of ambitious Deco legacy.

In addition, there used to be one more registry setting in plone.app.tile for defining available tiles, but that should be deprecated in the latest plone.app.tiles major release (but still requires with the previous ones, or plone.app.tiles' forms won't work.

Actually the declaration was ok, but when the tile type is "app", then we always make a POST when adding the tile:


which only works if the tile has a schema.

So basically schema is mandatory when using an app tile.