def getMenuItems(self, obj, request):
        """Return menu item entries in a TAL-friendly form."""
        context_state = getMultiAdapter((obj, request), name='plone_context_state')
        isDefaultPage = context_state.is_default_page()

        parent = None

        folder = None
        context = None

        # If this is a default page, also get menu items relative to the parent
        if isDefaultPage:
            parent = utils.parent(obj)
            folder = ISelectableBrowserDefault(parent, None)

        context = ISelectableBrowserDefault(obj, None)

        folderResults = self._getMenuItemsForContext(folder, request)

        contextResults = []
        if isDefaultPage or context_state.is_structural_folder():
            contextResults = self._getMenuItemsForContext(context, request)

        results = []
        if len(folderResults) > 0 and len(contextResults) > 0:
            results.append({ 'title'       : _(u'label_current_folder_add', default=u'Add in Folder'),
                             'description' : '',
                             'action'      : None,
                             'selected'    : False,
                             'icon'        : None,
                             'extra'       : {'id': 'folderHeader', 'separator': 'actionSeparator', 'class': ''},
                             'submenu'     : None,
                             })
            results.extend(folderResults)
            results.append({ 'title'       : _(u'label_current_item_add', default=u'Add in Item'),
                             'description' : '',
                             'action'      : None,
                             'selected'    : False,
                             'icon'        : None,
                             'extra'       : {'id': 'contextHeader', 'separator': 'actionSeparator', 'class': ''},
                             'submenu'     : None,
                             })
            results.extend(contextResults)

        else:
            results.extend(folderResults)
            results.extend(contextResults)

        return results
 def test_isMixedIn(self):
     self.failUnless(isinstance(self.af, BrowserDefaultMixin),
                     "ISelectableBrowserDefault was not mixed in to ATFolder")
     self.failUnless(ZopeTwoISelectableBrowserDefault.isImplementedBy(self.af),
                     "ISelectableBrowserDefault not implemented by ATFolder instance")
     self.failUnless(ISelectableBrowserDefault.providedBy(self.af),
                     "ISelectableBrowserDefault not implemented by ATFolder instance")
Beispiel #3
0
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            if not pathkey:
                yield item
                continue

            layoutkey = self.layoutkey(*item.keys())[0]
            defaultpagekey = self.defaultpagekey(*item.keys())[0]

            path = item[pathkey]

            obj = traverse(self.context, str(path).lstrip('/'), None)
            if obj is None:
                yield item
                continue

            if not ISelectableBrowserDefault.providedBy(obj):
                yield item
                continue

            if layoutkey:
                layout = item[layoutkey]
                if layout:
                    obj.setLayout(str(layout))

            if defaultpagekey:
                defaultpage = item[defaultpagekey]
                if defaultpage:
                    obj.setDefaultPage(str(defaultpage))

            yield item
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            if not pathkey:
                yield item; continue

            layoutkey = self.layoutkey(*item.keys())[0]
            defaultpagekey = self.defaultpagekey(*item.keys())[0]

            path = item[pathkey]

            obj = traverse(self.context, str(path).lstrip('/'), None)
            if obj is None:
                yield item; continue

            if not ISelectableBrowserDefault.providedBy(obj):
                yield item; continue

            if layoutkey:
                layout = item[layoutkey]
                if layout:
                    obj.setLayout(layout)

            if defaultpagekey:
                defaultpage = item[defaultpagekey]
                if defaultpage:
                    obj.setDefaultPage(defaultpage)

            yield item
def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
    """Process the schema looking for data in the form."""
    is_new_object = self.checkCreationFlag()
    
    BaseObject.processForm(self, data, metadata, REQUEST, values)
    if config.AUTO_NOTIFY_CANONICAL_UPDATE:
        if self.isCanonical():
            self.invalidateTranslations()

    if self._at_rename_after_creation and is_new_object:
        new_id = self._renameAfterCreation(check_auto_id=not not self.REQUEST.form.get('id'))
    else:
        new_id = None

    if shasattr(self, '_lp_default_page'):
        delattr(self, '_lp_default_page')
        language = self.getLanguage()
        canonical = self.getCanonical()
        parent = aq_parent(aq_inner(self))
        if ITranslatable.providedBy(parent):
            if not parent.hasTranslation(language):
                parent.addTranslation(language)
                translation_parent = parent.getTranslation(language)
                translation_parent.processForm(
                        values=dict(title=self.Title()))
                translation_parent.setDescription(self.Description())
                parent = translation_parent

            if ISelectableBrowserDefault.providedBy(parent) and new_id:
                parent.setDefaultPage(new_id)

        
    if shasattr(self, '_lp_outdated'):
        delattr(self, '_lp_outdated')
 def test_isMixedIn(self):
     self.assertTrue(isinstance(self.af, BrowserDefaultMixin),
                     "ISelectableBrowserDefault was not mixed in to ATFolder")
     self.assertTrue(ZopeTwoISelectableBrowserDefault.providedBy(self.af),
                     "ISelectableBrowserDefault not implemented by ATFolder instance")
     self.assertTrue(ISelectableBrowserDefault.providedBy(self.af),
                     "ISelectableBrowserDefault not implemented by ATFolder instance")
Beispiel #7
0
def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
    """Process the schema looking for data in the form."""
    is_new_object = self.checkCreationFlag()

    BaseObject.processForm(self, data, metadata, REQUEST, values)
    if config.AUTO_NOTIFY_CANONICAL_UPDATE:
        if self.isCanonical():
            self.invalidateTranslations()

    if self._at_rename_after_creation and is_new_object:
        new_id = self._renameAfterCreation(
            check_auto_id=not not self.REQUEST.form.get('id'))
    else:
        new_id = None

    if shasattr(self, '_lp_default_page'):
        delattr(self, '_lp_default_page')
        language = self.getLanguage()
        canonical = self.getCanonical()
        parent = aq_parent(aq_inner(self))
        if ITranslatable.providedBy(parent):
            if not parent.hasTranslation(language):
                parent.addTranslation(language)
                translation_parent = parent.getTranslation(language)
                translation_parent.processForm(values=dict(title=self.Title()))
                translation_parent.setDescription(self.Description())
                parent = translation_parent

            if ISelectableBrowserDefault.providedBy(parent) and new_id:
                parent.setDefaultPage(new_id)

    if shasattr(self, '_lp_outdated'):
        delattr(self, '_lp_outdated')
    def available(self):
        if self.disabled():
            return False

        isDefaultPage = self.context_state.is_default_page()

        folder = None
        context = None

        folderLayouts = []
        contextLayouts = []

        # If this is a default page, also get menu items relative to the parent
        if isDefaultPage:
            folder = ISelectableBrowserDefault(utils.parent(self.context), None)

        context = ISelectableBrowserDefault(self.context, None)

        folderLayouts = []
        folderCanSetLayout = False
        folderCanSetDefaultPage = False

        if folder is not None:
            folderLayouts = folder.getAvailableLayouts()
            folderCanSetLayout = folder.canSetLayout()
            folderCanSetDefaultPage = folder.canSetDefaultPage()

        contextLayouts = []
        contextCanSetLayout = False
        contextCanSetDefaultPage = False

        if context is not None:
            contextLayouts = context.getAvailableLayouts()
            contextCanSetLayout = context.canSetLayout()
            contextCanSetDefaultPage = context.canSetDefaultPage()

        # Show the menu if we either can set a default-page, or we have more
        # than one layout to choose from.
        if (folderCanSetDefaultPage) or \
           (folderCanSetLayout and len(folderLayouts) > 1) or \
           (folder is None and contextCanSetDefaultPage) or \
           (contextCanSetLayout and len(contextLayouts) > 1):
            return True
        else:
            return False
 def getTargetObjectLayout(self, target):
     """
     Returns target object 'view' action page template
     """
     if ISelectableBrowserDefault.providedBy(target):
         return target.getLayout()
     else:
         view = target.getTypeInfo().getActionById('view')
         # If view action is view, try to guess correct template
         if view == 'view':
             view = target.portal_type.lower() + '_view'
         return view
    def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
        """Process the schema looking for data in the form."""
        is_new_object = self.checkCreationFlag()
        BaseObject.processForm(self,
                               data=data,
                               metadata=metadata,
                               REQUEST=REQUEST,
                               values=values)
        # LP specific bits
        if config.AUTO_NOTIFY_CANONICAL_UPDATE:
            if self.isCanonical():
                self.invalidateTranslations()

        # Check if an explicit id has been passed
        explicit_id = False
        if REQUEST is None:
            REQUEST = getattr(self, 'REQUEST', None)

        if REQUEST is not None:
            if 'id' in REQUEST.form and REQUEST.form.get('id'):
                explicit_id = True

        if values is not None:
            if 'id' in values and values.get('id'):
                explicit_id = True

        if (is_new_object and not explicit_id
                and self._at_rename_after_creation):
            # Renames an object like its normalized title
            self._renameAfterCreation(check_auto_id=True)

        if shasattr(self, '_lp_default_page'):
            delattr(self, '_lp_default_page')
            language = self.Language()
            parent = aq_parent(aq_inner(self))
            if ITranslatable.providedBy(parent) and parent.Language() != '':
                if not parent.hasTranslation(language):
                    parent.addTranslation(language)
                    translation_parent = parent.getTranslation(language)
                    translation_parent.processForm(values=dict(
                        title=self.Title()))
                    translation_parent.setDescription(self.Description())
                    parent = translation_parent

                if ISelectableBrowserDefault.providedBy(parent):
                    parent.setDefaultPage(self.getId())

        if shasattr(self, '_lp_outdated'):
            delattr(self, '_lp_outdated')
Beispiel #11
0
    def available(self):
        if self.disabled():
            return False

        isDefaultPage = self.context_state.is_default_page()

        folder = None
        context = None

        folderLayouts = []
        contextLayouts = []

        # If this is a default page, also get menu items relative to the parent
        if isDefaultPage:
            folder = ISelectableBrowserDefault(utils.parent(self.context),
                                               None)

        context = ISelectableBrowserDefault(self.context, None)

        folderLayouts = []
        folderCanSetLayout = False
        folderCanSetDefaultPage = False

        if folder is not None:
            folderLayouts = folder.getAvailableLayouts()
            folderCanSetLayout = folder.canSetLayout()
            folderCanSetDefaultPage = folder.canSetDefaultPage()

        contextLayouts = []
        contextCanSetLayout = False
        contextCanSetDefaultPage = False

        if context is not None:
            contextLayouts = context.getAvailableLayouts()
            contextCanSetLayout = context.canSetLayout()
            contextCanSetDefaultPage = context.canSetDefaultPage()

        # Show the menu if we either can set a default-page, or we have more
        # than one layout to choose from.
        if (folderCanSetDefaultPage) or \
           (folderCanSetLayout and len(folderLayouts) > 1) or \
           (folder is None and contextCanSetDefaultPage) or \
           (contextCanSetLayout and len(contextLayouts) > 1):
            return True
        else:
            return False
Beispiel #12
0
 def contentBody(self):
     context = aq_inner(self.context)
     if ISelectableBrowserDefault.providedBy(context):
         layout = context.getLayout()
     else:
         portal_types = getMultiAdapter((context, self.request),
                                        name=u'plone_tools').types()
         type_info = portal_types.getTypeInfo(context)
         try:
             view_action = type_info.getActionInfo('object/view')
             layout = (view_action['url'].split('/')[-1] or
                       getattr(type_info, 'default_view', 'view'))
         except:
             logger.error("No layout available for %s", context.absolute_url())
             # We can't have a layout
             return False
     return context.restrictedTraverse(layout).macros.get('main', False)
    def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
        """Process the schema looking for data in the form."""
        is_new_object = self.checkCreationFlag()
        BaseObject.processForm(self, data=data, metadata=metadata,
                               REQUEST=REQUEST, values=values)
        # LP specific bits
        if config.AUTO_NOTIFY_CANONICAL_UPDATE:
            if self.isCanonical():
                self.invalidateTranslations()

        # Check if an explicit id has been passed
        explicit_id = False
        if REQUEST is None:
            REQUEST = getattr(self, 'REQUEST', None)

        if REQUEST is not None:
            if 'id' in REQUEST.form and REQUEST.form.get('id'):
                explicit_id = True

        if values is not None:
            if 'id' in values and values.get('id'):
                explicit_id = True

        if (is_new_object and not explicit_id and
            self._at_rename_after_creation):
            # Renames an object like its normalized title
            self._renameAfterCreation(check_auto_id=True)

        if shasattr(self, '_lp_default_page'):
            delattr(self, '_lp_default_page')
            language = self.Language()
            parent = aq_parent(aq_inner(self))
            if ITranslatable.providedBy(parent) and parent.Language() != '':
                if not parent.hasTranslation(language):
                    parent.addTranslation(language)
                    translation_parent = parent.getTranslation(language)
                    translation_parent.processForm(
                            values=dict(title=self.Title()))
                    translation_parent.setDescription(self.Description())
                    parent = translation_parent

                if ISelectableBrowserDefault.providedBy(parent):
                    parent.setDefaultPage(self.getId())

        if shasattr(self, '_lp_outdated'):
            delattr(self, '_lp_outdated')
Beispiel #14
0
 def contentBody(self):
     context = aq_inner(self.context)
     if ISelectableBrowserDefault.providedBy(context):
         layout = context.getLayout()
     else:
         portal_types = getMultiAdapter((context, self.request),
                                        name=u'plone_tools').types()
         type_info = portal_types.getTypeInfo(context)
         try:
             view_action = type_info.getActionInfo('object/view')
             layout = (view_action['url'].split('/')[-1]
                       or getattr(type_info, 'default_view', 'view'))
         except:
             logger.error("No layout available for %s",
                          context.absolute_url())
             # We can't have a layout
             return False
     return context.restrictedTraverse(layout).macros.get('main', False)
    def targetMainMacro(self):
        """The macro that renders the central stuff of the body,
        or False if no"""

        target = self.getAlias()
        if ISelectableBrowserDefault.providedBy(target):
            layout = target.getLayout()
        else:
            portal_types = getMultiAdapter((self, self.REQUEST),
                                            name=u'plone_tools').types()
            type_info = portal_types.getTypeInfo(target)
            try:
                view_action = type_info.getActionInfo('object/view')
                layout = view_action['url'].split('/')[-1] or \
                                getattr(type_info, 'default_view', 'view')
            except:
                # We can't have a layout
                return False
        return target.restrictedTraverse(layout).macros.get('main', False)
Beispiel #16
0
    def getMenuItems(self, obj, request):
        """Return menu item entries in a TAL-friendly form."""
        results = []

        context_state = getMultiAdapter((obj, request), name='plone_context_state')
        isDefaultPage = context_state.is_default_page()

        parent = None

        folder = None
        context = None

        folderLayouts = []
        contextLayouts = []

        # If this is a default page, also get menu items relative to the parent
        if isDefaultPage:
            parent = utils.parent(obj)
            folder = ISelectableBrowserDefault(parent, None)

        context = ISelectableBrowserDefault(obj, None)

        folderLayouts = []
        folderCanSetLayout = False
        folderCanSetDefaultPage = False

        if folder is not None:
            folderLayouts = folder.getAvailableLayouts()
            folderCanSetLayout = folder.canSetLayout()
            folderCanSetDefaultPage = folder.canSetDefaultPage()

        contextLayouts = []
        contextCanSetLayout = False
        contextCanSetDefaultPage = False

        if context is not None:
            contextLayouts = context.getAvailableLayouts()
            contextCanSetLayout = context.canSetLayout()
            contextCanSetDefaultPage = context.canSetDefaultPage()

        # Short circuit if neither folder nor object will provide us with
        # items
        if not (folderCanSetLayout or folderCanSetDefaultPage or \
                contextCanSetLayout or contextCanSetDefaultPage):
            return []

        # Only show the block "Folder display" and "Item display" separators if
        # they are necessars
        useSeparators = False
        if folderCanSetLayout or folderCanSetDefaultPage:
            if (contextCanSetLayout and len(contextLayouts) > 1) or \
                contextCanSetDefaultPage:
                useSeparators = True

        # 1. If this is a default-page, first render folder options
        if folder is not None:
            folderUrl = parent.absolute_url()

            if useSeparators:
                results.append({ 'title'       : _(u'label_current_folder_views', default=u'Folder display'),
                                 'description' : '',
                                 'action'      : None,
                                 'selected'    : False,
                                 'icon'        : None,
                                 'extra'       : {'id': 'folderHeader', 'separator': 'actionSeparator', 'class': ''},
                                 'submenu'     : None,
                                 })

            if folderCanSetLayout:
                for id, title in folderLayouts:
                    results.append({ 'title'       : title,
                                     'description' : '',
                                     'action'      : '%s/selectViewTemplate?templateId=%s' % (folderUrl, id,),
                                     'selected'    : False,
                                     'icon'        : None,
                                     'extra'       : {'id': 'folder-' + id, 'separator': None, 'class': ''},
                                     'submenu'     : None,
                                     })
            # Display the selected item (i.e. the context)
            results.append({ 'title'       : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : escape(_safe_unicode(obj.Title()))}),
                             'description' : '',
                             'action'      : None,
                             'selected'    : True,
                             'icon'        : None,
                             'extra'       : {'id': 'folderDefaultPageDisplay', 'separator': 'actionSeparator', 'class': 'actionMenuSelected'},
                             'submenu'     : None,
                             })
            # Let the user change the selection
            if folderCanSetDefaultPage:
                results.append({ 'title'       : _(u'label_change_default_item', default=u'Change content item as default view...'),
                                 'description' : _(u'title_change_default_view_item', default=u'Change the item used as default view in this folder'),
                                 'action'      : '%s/select_default_page' % (folderUrl,),
                                 'selected'    : False,
                                 'icon'        : None,
                                 'extra'       : {'id': 'folderChangeDefaultPage', 'separator': 'actionSeparator', 'class': ''},
                                 'submenu'     : None,
                                 })

        # 2. Render context options
        if context is not None:
            contextUrl = obj.absolute_url()
            selected = context.getLayout()
            defaultPage = context.getDefaultPage()
            layouts = context.getAvailableLayouts()

            if useSeparators:
                results.append({ 'title'       : _(u'label_current_item_views', default=u'Item display'),
                                 'description' : '',
                                 'action'      : None,
                                 'selected'    : False,
                                 'icon'        : None,
                                 'extra'       : {'id': 'contextHeader', 'separator': 'actionSeparator', 'class': ''},
                                 'submenu'     : None,
                                 })

            # If context is a default-page in a folder, that folder's views will
            # be shown. Only show context views if there are any to show.

            showLayouts = False
            if not isDefaultPage:
                showLayouts = True
            elif len(layouts) > 1:
                showLayouts = True

            if showLayouts and contextCanSetLayout:
                for id, title in contextLayouts:
                    is_selected = (defaultPage is None and id == selected)
                    results.append({ 'title'       : title,
                                     'description' : '',
                                     'action'      : '%s/selectViewTemplate?templateId=%s' % (contextUrl, id,),
                                     'selected'    : is_selected,
                                     'icon'        : None,
                                     'extra'       : {'id': id, 'separator': None, 'class': is_selected and 'actionMenuSelected' or ''},
                                     'submenu'     : None,
                                     })

            # Allow setting / changing the default-page, unless this is a
            # default-page in a parent folder.
            if not INonStructuralFolder.providedBy(obj):
                if defaultPage is None:
                    if contextCanSetDefaultPage:
                        results.append({ 'title'       : _(u'label_choose_item', default=u'Select a content item\nas default view...'),
                                         'description' : _(u'title_select_default_view_item', default=u'Select an item to be used as default view in this folder...'),
                                         'action'      : '%s/select_default_page' % (contextUrl,),
                                         'selected'    : False,
                                         'icon'        : None,
                                         'extra'       : {'id': 'contextSetDefaultPage', 'separator': 'actionSeparator', 'class': ''},
                                         'submenu'     : None,
                                         })
                else:
                    defaultPageObj = getattr(obj, defaultPage, None)
                    defaultPageTitle = u""
                    if defaultPageObj is not None:
                        if hasattr(aq_base(defaultPageObj), 'Title'):
                            defaultPageTitle = defaultPageObj.Title()
                        else:
                            defaultPageTitle = getattr(aq_base(defaultPageObj), 'title', u'')

                    results.append({ 'title'       : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : escape(_safe_unicode(defaultPageTitle))}),
                                     'description' : '',
                                     'action'      : None,
                                     'selected'    : True,
                                     'icon'        : None,
                                     'extra'       : {'id': 'contextDefaultPageDisplay', 'separator': 'actionSeparator', 'class': ''},
                                     'submenu'     : None,
                                     })
                    if contextCanSetDefaultPage:
                        results.append({ 'title'       : _(u'label_change_item', default=u'Change content item\nas default view...'),
                                         'description' : _(u'title_change_default_view_item', default=u'Change the item used as default view in this folder'),
                                         'action'      : '%s/select_default_page' % (contextUrl,),
                                         'selected'    : False,
                                         'icon'        : None,
                                         'extra'       : {'id': 'contextChangeDefaultPage', 'separator': 'actionSeparator', 'class': ''},
                                         'submenu'     : None,
                                         })

        return results
Beispiel #17
0
    def getMenuItems(self, obj, request):
        """Return menu item entries in a TAL-friendly form."""
        results = []

        context_state = getMultiAdapter((obj, request),
                                        name='plone_context_state')
        isDefaultPage = context_state.is_default_page()

        parent = None

        folder = None
        context = None

        folderLayouts = []
        contextLayouts = []

        # If this is a default page, also get menu items relative to the parent
        if isDefaultPage:
            parent = utils.parent(obj)
            folder = ISelectableBrowserDefault(parent, None)

        context = ISelectableBrowserDefault(obj, None)

        folderLayouts = []
        folderCanSetLayout = False
        folderCanSetDefaultPage = False

        if folder is not None:
            folderLayouts = folder.getAvailableLayouts()
            folderCanSetLayout = folder.canSetLayout()
            folderCanSetDefaultPage = folder.canSetDefaultPage()

        contextLayouts = []
        contextCanSetLayout = False
        contextCanSetDefaultPage = False

        if context is not None:
            contextLayouts = context.getAvailableLayouts()
            contextCanSetLayout = context.canSetLayout()
            contextCanSetDefaultPage = context.canSetDefaultPage()

        # Short circuit if neither folder nor object will provide us with
        # items
        if not (folderCanSetLayout or folderCanSetDefaultPage or \
                contextCanSetLayout or contextCanSetDefaultPage):
            return []

        # Only show the block "Folder display" and "Item display" separators if
        # they are necessars
        useSeparators = False
        if folderCanSetLayout or folderCanSetDefaultPage:
            if (contextCanSetLayout and len(contextLayouts) > 1) or \
                contextCanSetDefaultPage:
                useSeparators = True

        # 1. If this is a default-page, first render folder options
        if folder is not None:
            folderUrl = parent.absolute_url()

            if useSeparators:
                results.append({
                    'title': _(u'label_current_folder_views',
                                default=u'Folder display'),
                    'description': '',
                    'action': None,
                    'selected': False,
                    'icon': None,
                    'extra': {'id': 'folderHeader',
                              'separator': 'actionSeparator',
                              'class': ''},
                    'submenu': None,
                })

            if folderCanSetLayout:
                for id, title in folderLayouts:
                    results.append({
                        'title': title,
                        'description': '',
                        'action': '%s/selectViewTemplate?templateId=%s' % (
                            folderUrl, id,),
                        'selected': False,
                        'icon': None,
                        'extra': {
                            'id': 'folder-' + id,
                            'separator': None,
                            'class': ''},
                        'submenu': None,
                    })
            # Display the selected item (i.e. the context)
            results.append({
                'title': _(u'label_item_selected',
                    default=u'Item: ${contentitem}',
                    mapping={'contentitem': escape(
                                _safe_unicode(obj.Title()))}),
                'description': '',
                'action': None,
                'selected': True,
                'icon': None,
                'extra': {
                    'id': 'folderDefaultPageDisplay',
                    'separator': 'actionSeparator',
                    'class': 'actionMenuSelected'},
                'submenu': None,
                })
            # Let the user change the selection
            if folderCanSetDefaultPage:
                results.append({
                    'title': _(u'label_change_default_item',
                        default=u'Change content item as default view...'),
                    'description': _(u'title_change_default_view_item',
                        default=u'Change the item used as default view in '
                                u'this folder'),
                    'action': '%s/select_default_page' % (folderUrl,),
                    'selected': False,
                    'icon': None,
                    'extra': {
                        'id': 'folderChangeDefaultPage',
                        'separator': 'actionSeparator',
                        'class': ''},
                    'submenu': None,
                })

        # 2. Render context options
        if context is not None:
            contextUrl = obj.absolute_url()
            selected = context.getLayout()
            defaultPage = context.getDefaultPage()
            layouts = context.getAvailableLayouts()

            if useSeparators:
                results.append({
                    'title': _(u'label_current_item_views',
                                default=u'Item display'),
                    'description': '',
                    'action': None,
                    'selected': False,
                    'icon': None,
                    'extra': {
                        'id': 'contextHeader',
                        'separator': 'actionSeparator',
                        'class': ''},
                    'submenu': None,
                })

            # If context is a default-page in a folder, that folder's views
            # will be shown. Only show context views if there are any to show.

            showLayouts = False
            if not isDefaultPage:
                showLayouts = True
            elif len(layouts) > 1:
                showLayouts = True

            if showLayouts and contextCanSetLayout:
                for id, title in contextLayouts:
                    is_selected = (defaultPage is None and id == selected)
                    results.append({
                        'title': title,
                        'description': '',
                        'action': '%s/selectViewTemplate?templateId=%s' % (
                            contextUrl, id,),
                        'selected': is_selected,
                        'icon': None,
                        'extra': {
                            'id': 'plone-contentmenu-display-' + id,
                            'separator': None,
                            'class': is_selected and 'actionMenuSelected' or ''
                            },
                        'submenu': None,
                    })

            # Allow setting / changing the default-page, unless this is a
            # default-page in a parent folder.
            if not INonStructuralFolder.providedBy(obj):
                if defaultPage is None:
                    if contextCanSetDefaultPage:
                        results.append({
                            'title': _(u'label_choose_item',
                                default=u'Select a content item\n'
                                        u'as default view...'),
                            'description':
                                _(u'title_select_default_view_item',
                                    default=u'Select an item to be used as '
                                            u'default view in this folder...'),
                            'action': '%s/select_default_page' % (contextUrl,),
                            'selected': False,
                            'icon': None,
                            'extra': {
                                'id': 'contextSetDefaultPage',
                                'separator': 'actionSeparator',
                                'class': ''},
                            'submenu': None,
                            })
                else:
                    defaultPageObj = getattr(obj, defaultPage, None)
                    defaultPageTitle = u""
                    if defaultPageObj is not None:
                        if hasattr(aq_base(defaultPageObj), 'Title'):
                            defaultPageTitle = defaultPageObj.Title()
                        else:
                            defaultPageTitle = getattr(aq_base(defaultPageObj),
                                                       'title', u'')

                    results.append({
                        'title': _(u'label_item_selected',
                            default=u'Item: ${contentitem}',
                            mapping={'contentitem': escape(_safe_unicode(
                                defaultPageTitle))}),
                        'description': '',
                        'action': None,
                        'selected': True,
                        'icon': None,
                        'extra': {
                            'id': 'contextDefaultPageDisplay',
                            'separator': 'actionSeparator',
                            'class': ''},
                        'submenu': None,
                    })
                    if contextCanSetDefaultPage:
                        results.append({
                            'title': _(u'label_change_item',
                                default=u'Change content item\nas '
                                        u'default view...'),
                            'description': _(u'title_change_default_view_item',
                                default=u'Change the item used as default '
                                        u'view in this folder'),
                            'action': '%s/select_default_page' % (contextUrl,),
                            'selected': False,
                            'icon': None,
                            'extra': {
                                'id': 'contextChangeDefaultPage',
                                'separator': 'actionSeparator',
                                'class': ''},
                            'submenu': None,
                            })

        return results