Browse files

First look if our context supports tiles then write annotations in it

  • Loading branch information...
1 parent 6996db3 commit f41e8ca842dedef3a069d06b8222aabc0083ba55 @ericof ericof committed Nov 7, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 plone/app/tiles/browser/
@@ -4,13 +4,16 @@
from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent
from zope.event import notify
+from zope.component import getMultiAdapter
from zope.traversing.browser.absoluteurl import absoluteURL
from Products.statusmessages.interfaces import IStatusMessage
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.tiles.interfaces import ITileDataManager
+from import ILayoutAware
from import TileForm
from import getEditTileURL, appendJSONData
from import MessageFactory as _
@@ -51,8 +54,19 @@ def handleAdd(self, action):
typeName = self.tileType.__name__
+ context = self.context
+ # Look up if our context supports tiles, if not
+ # pick default view instead
+ if not ILayoutAware(context, None):
+ default_page_view = getMultiAdapter((context, self.request),
+ name='default_page')
+ default_page = default_page_view.getDefaultPage()
+ context = default_page and context[default_page] or context
+ context = ILayoutAware(context, None)
# Traverse to a new tile in the context, with no data
- tile = self.context.restrictedTraverse(
+ tile = context.restrictedTraverse(
'@@%s/%s' % (typeName, self.tileId,))
dataManager = ITileDataManager(tile)

5 comments on commit f41e8ca


Hey -- this commit breaks our application where we are using without (we have our own code to render the tiles). I don't think checking for ILayoutAware is a good check...our app doesn't store layouts via ILayoutAware, but simply has hardcoded references to tiles in some custom templates.

What was the problem that this was attempting to solve? Maybe I can think of another solution.

Or alternatively... we are not actually using tile add forms. We're just editing existing tiles. So as long as this was made conditional so it doesn't fail when is absent, that would solve my problem.


I don't understand why the default page is being used here. @ericof, can you explain the rationale for using that?

ericof commented on f41e8ca Dec 28, 2011

If you used a Deco page as default item in a container (a Plone site, for instance) when you added tiles they would end up being written on the container not on the Deco page.

I decided to use the ILayoutAware to check if the context was the right place to write the annotation after talking to @davisagli or @robgietema at the sprint.


I just checked, and even without this change that is no longer a problem now that I added the missing tag in 4d0c92a ... so I am going to revert this change to avoid the dependency on

ericof commented on f41e8ca Dec 29, 2011

It seems a good solution ;-)

Please sign in to comment.