diff --git a/news/88.bugfix b/news/88.bugfix new file mode 100644 index 00000000..7dfc2995 --- /dev/null +++ b/news/88.bugfix @@ -0,0 +1 @@ +Fixed mishandling of dynamic form label updates - New Comment & Thread @rohnsha0 \ No newline at end of file diff --git a/plone/app/discussion/browser/comments.pt b/plone/app/discussion/browser/comments.pt index 291512eb..a3ae67e2 100644 --- a/plone/app/discussion/browser/comments.pt +++ b/plone/app/discussion/browser/comments.pt @@ -288,9 +288,18 @@
+ + + + diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 0de2ab03..7a146339 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -53,6 +53,27 @@ "transformed into clickable links.", ) +# New reply descriptions +COMMENT_DESCRIPTION_PLAIN_TEXT_REPLY = _( + "comment_description_plain_text_reply", + default="You can reply to this comment by filling out the form below. " + "Plain text formatting.", +) + +COMMENT_DESCRIPTION_MARKDOWN_REPLY = _( + "comment_description_markdown_reply", + default="You can reply to this comment by filling out the form below. " + "Plain text formatting. You can use the Markdown syntax for " + "links and images.", +) + +COMMENT_DESCRIPTION_INTELLIGENT_TEXT_REPLY = _( + "comment_description_intelligent_text_reply", + default="You can reply to this comment by filling out the form below. " + "Plain text formatting. Web and email addresses are " + "transformed into clickable links.", +) + COMMENT_DESCRIPTION_MODERATION_ENABLED = _( "comment_description_moderation_enabled", default="Comments are moderated.", @@ -62,7 +83,15 @@ class CommentForm(extensible.ExtensibleForm, form.Form): ignoreContext = True # don't use context to get widget data id = None - label = _("Add a comment") + + @property + def label(self): + """Dynamic label based on whether this is a reply or new comment.""" + if self.is_reply(): + return _("Reply here (this thread)") + else: + return _("Add a new comment") + fields = field.Fields(IComment).omit( "portal_type", "__parent__", @@ -79,6 +108,11 @@ class CommentForm(extensible.ExtensibleForm, form.Form): # See https://github.com/plone/Products.CMFPlone/issues/3623 enable_autofocus = False + def is_reply(self): + """Check if this form is being used to reply to an existing comment.""" + in_reply_to = self.request.get("form.widgets.in_reply_to", None) + return bool(in_reply_to) + def updateFields(self): super().updateFields() self.fields["user_notification"].widgetFactory = SingleCheckBoxFieldWidget @@ -383,7 +417,7 @@ def comment_transform_message(self): registry = queryUtility(IRegistry) settings = registry.forInterface(IDiscussionSettings, check=False) - # text transform setting + # text transform setting - always use new comment descriptions for main form if settings.text_transform == "text/x-web-intelligent": message = translate( Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT), context=self.request @@ -417,6 +451,50 @@ def comment_transform_message(self): return message + def get_reply_transform_message(self): + """Returns the description for reply forms, + dependent on the text_transform setting and the comment moderation + workflow in the discussion control panel. + """ + context = aq_inner(self.context) + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings, check=False) + + # text transform setting - use reply descriptions + if settings.text_transform == "text/x-web-intelligent": + message = translate( + Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT_REPLY), + context=self.request, + ) + elif settings.text_transform == "text/x-web-markdown": + message = translate( + Message(COMMENT_DESCRIPTION_MARKDOWN_REPLY), context=self.request + ) + else: + message = translate( + Message(COMMENT_DESCRIPTION_PLAIN_TEXT_REPLY), context=self.request + ) + + # comment workflow + wftool = getToolByName(context, "portal_workflow", None) + workflow_chain = wftool.getChainForPortalType("Discussion Item") + if workflow_chain: + comment_workflow = workflow_chain[0] + comment_workflow = wftool[comment_workflow] + # check if the current workflow implements a pending state. If this + # is true comments are moderated + if "pending" in comment_workflow.states: + message = ( + message + + " " + + translate( + Message(COMMENT_DESCRIPTION_MODERATION_ENABLED), + context=self.request, + ) + ) + + return message + def has_replies(self, workflow_actions=False): """Returns true if there are replies.""" if self.get_replies(workflow_actions) is not None: