Пример #1
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = PloneFactoriesMenu.getMenuItems(self, context, request)

        # No menu customization if the product is not installed
        if not ICustomMenuFactoryLayer.providedBy(request):
            return results
        
        portal_url = getToolByName(context, 'portal_url')

        # First of all, get the real context of the menu
        if IFolder.providedBy(context):
            folder = context
        elif isFolderOrFolderDefaultPage(context, request):
            folder = aq_parent(aq_inner(context))
        else:
            # don't know how to handle this
            folder = context

        data = {'context': context, 'portal_url': portal_url, 'container': folder}

        # If folder can't be annotable, do nothing
        # uncommon but may happen for old stuff like PloneGazette
        if not queryAdapter(folder, interface=IAnnotations):
            return results

        try:
            m_provider = ICustomFactoryMenuProvider(folder)
        except TypeError:
            # For any adaptation problem
            return results
        
        results = m_provider.getMenuCustomization(data, results)

        # Re-sort
        results.sort(lambda x, y: cmp(x['title'],y['title']))

        mtool = getToolByName(context, 'portal_membership')
        if not mtool.isAnonymousUser() and mtool.getAuthenticatedMember().has_permission('Customize menu: factories', folder):
            context_url = folder.absolute_url()
            results.append({'title'       : _(u'custommenu_manage_title', default=_(u'Customize menu\u2026')),
                            'description' : _(u'custommenu_manage_description', default=_(u'Manage custom elements of this menu')),
                            'action'      : context_url+'/@@customize-factoriesmenu',
                            'selected'    : False,
                            'icon'        : None,
                            'submenu'     : None,
                            'extra'       : {'separator': 'actionSeparator', 'id': 'customize-factoriesmenu', 'class': 'customize-menu'},
                            })
        return results
Пример #2
0
    def getCustomMenuResults(self):
        data = self._get_data()

        # If folder can't be annotable, do nothing
        # uncommon but may happen for old stuff like PloneGazette
        if not queryAdapter(data['container'], interface=IAnnotations):
            return None

        try:
            m_provider = ICustomFactoryMenuProvider(data['container'])
        except TypeError:
            # For any adaptation problem
            return None
        
        itemsToAdd = self._itemsToAdd()
        if len(itemsToAdd) == 1:
            fti = itemsToAdd[0][1]
            return m_provider.getSingleEntryMenuCustomization(data, fti)
        return None