Can not activate discussions on Plone Dexterity types (folderish)
Asked Answered
S

4

6

I have been working on a dexterity based plone application. I have created a couple of new types. This is what I did to activate comments on a specific dexterity content type named "activity_report":

In Plone Control Panel

In the Discussion section I enabled the following:

  • globally enable comments
  • enable anonymous comments

In the Types Section I chose the "Activity Report" type from the drop down and enabled the "Allow comments" option.

On the file system

In the FTI file activityreport.xml:

<property name="allow_discussion">True</property>

I have restarted the instance and even reinstalled the product, but I can not activate the comments section in the dexterity type.

It is worth mentioning that a standard type (ex. Page) can have the discussion module activated.

Is there something I am missing?

Schoenfelder answered 1/5, 2012 at 19:13 Comment(1)
I think my problem is also related to the fact that my content type is folderish. How do I allow discussion on a folderish type?Schoenfelder
M
3

plone.app.discussion currently disables commenting for all containers (see https://dev.plone.org/ticket/11245 for discussion).

I used a monkey patch like the following in one project to short-circuit the normal check and make sure that commenting was enabled for my folderish content type:

from Acquisition import aq_inner
from Products.highcountrynews.content.interfaces import IHCNNewsArticle
from plone.app.discussion.conversation import Conversation
old_enabled = Conversation.enabled
def enabled(self):
    parent = aq_inner(self.__parent__)
    if parent.portal_type == 'my_portal_type':
        return True
    return old_enabled(self)
Conversation.enabled = enabled

where 'my_portal_type' is, of course, the portal_type you want commenting enabled for.

Maurine answered 2/5, 2012 at 0:19 Comment(1)
Thanks David! This looks like the solution I will adopt. I am also considering turning the types into simple documents. In my case, the only advantage using folderish types would have been to keep related documents together in the container.Schoenfelder
C
2

The David response is not accurate. The class to be monkeypatched is plone.app.discussion.browser.conversation.ConversationView :

from Acquisition import aq_inner
from plone.app.discussion.browser.conversation import ConversationView
old_enabled = ConversationView.enabled

def enabled(self):
    parent = aq_inner(self.__parent__)
    if parent.portal_type == 'My_type':
        return True
    return old_enabled(self)

It works for Plone 4.2 at least. However, thanks David for the hint.

Cathodoluminescence answered 4/7, 2012 at 10:44 Comment(0)
M
2

As David and Victor already pointed out, you can just override the enable method of the conversation class. I would recommend using the following approach which is a bit cleaner than monkey patching the conversation class:

https://github.com/plone/plone.app.discussion/blob/master/docs/source/howtos/howto_override_enable_conversation.txt

I also added support for dexterity types to plone.app.discussion recently, so as soon as there is a new release you won't need to customize the conversation class any longer:

https://github.com/plone/plone.app.discussion/commit/0e587a7d8536125acdd3bd385e880b60d6aec28e

Note that this method supports commenting ON folderish objects. There is no support to enable/disable commenting for objects INSIDE a folderish object yet.

In case you want to be able to switch on/off commenting with a behavior field/widget:

https://github.com/plone/plone.app.dexterity/commit/0573df4f265a39da9efae44e605e3815729457d7

This will hopefully make it into the next plone.app.dexterity release as well.

Monolith answered 5/7, 2012 at 10:44 Comment(2)
Nice solution as all the changes are outside any plone package eggs. The "howto_override_enable_conversation.txt" mostly worked for me. Before "if context.allow_discussion is not None" I had to check if the attribute exists in context (or added a try, catch block).Exodontics
@RyanAnderson would you mind changing the howto and doing a pull request so I can update the docs?Monolith
O
1

I solved in configure.zcml:

<interface interface="Products.CMFPlone.interfaces.INonStructuralFolder" />

<class class="Products.PloneHelpCenter.types.Definition.HelpCenterDefinition">
  <implements interface="Products.CMFPlone.interfaces.INonStructuralFolder" />
</class>

UPDATE: this is not a good idea. I had problems with missing Add menu for each content type having this fix.

Oppose answered 24/6, 2015 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.