How to override the Plone display menu for the contents of a particular case?

To get a one-time view in the Plone folder, I do something like this (not all the code):

In configure.zcml :

 <!-- Marker interface. Set this on the folder through the ZMI interfaces tab. --> <interface interface=".interfaces.IMySpecialFolder" /> 

In browser/configure.zcml :

 <!-- Special case view. Set as the folder view through the ZMI properties tab (layout property). --> <browser:page for="..interfaces.IMySpecialFolder" name="special" template="special.pt" permission="zope2.View" /> 

This works fine, but I would like to manage the folder display menu to only display my special view. I can add it, and it only appears in my marked folder, but I need to change ATFolder FTI to the whole site.

In browser/configure.zcml :

 <include package="plone.app.contentmenu" /> <browser:menuItem for="..interfaces.IMySpecialFolder" menu="plone_displayviews" title="Special view" action="@@special" description="Special case folder view" /> 

In profiles/default/types/Folder.xml :

 <?xml version="1.0"?> <object name="Folder"> <property name="view_methods" purge="False"> <element value="special"/> </property> </object> 

Of course, I cannot delete the existing browsing methods available without affecting every folder on the site.

Is there a way to make this a one-time menu display without changing the type of FTI content?

In fact, it seems this problem has been resolved before. p4a.z2utils patches CMFDynamicViewFTI to get a list of available views from the IDynamicallyViewable adapter IDynamicallyViewable . ( dateable.chronos uses this mechanism for its folder calendar views). So my question is:

Is there a way to make this a one-time menu display without changing the type of FTI content and without correcting Plone?

+6
source share
3 answers

Answering my own question, I realized that the easiest way to get one-time folder views is to follow the template. Plone itself is used in the Members : PythonScript index_html , causing a custom view, for example,

 member_search=context.restrictedTraverse('member_search_form') return member_search() 

Products.CMFPlone illustrates how to configure such PythonScript using the GenericSetup import handler .

In retrospect, I understand that I don't need the marker interface in my interrogation scenario. There is also no need to answer here.

Please note that this solution does not cause the "folder display menu to list only my special window view", as I asked, but completely removes the on-screen menu. I'm fine with that.

+1
source

The plone display menu designer uses ISelectableBrowserDefault to get available options on the display menu (see http://dev.plone.org/plone/browser/plone.app.contentmenu/trunk/plone/app/contentmenu/menu.py#L220 )

So, I think (but I have not tried this) that if you define an adapter for a more specific interface (in your case IMySpecialFolder ) that Products.CMFDynamicViewFTI.interface.ISelectableBrowserDefault provides, it should work.

The adapter must have the methods needed for plone.app.contentmenu.menu.DisplayMenu above.

+3
source

One way you could solve this is to use traversalhook to register menu items or, in this case, unregister menu items or register menu items with conditions that do not display them. Using the bypass hook, you can use the marker interface to happen only in a specific folder, subsection, or page. You can see where we implemented the similar code here.

https://github.com/collective/collective.listingviews/blob/master/src/collective/listingviews/browser/views/controlpanel.py#L105

In this case, we just wanted to dynamically register new display menu items based on the control panel configuration.

0
source

Source: https://habr.com/ru/post/890005/


All Articles