Problem/Motivation

Can comments, scheduling etc. be switched on/off, depending on from/to state and user role?

Case #4: I need to be able to NOT allow comments on a post until/unless it is in a certain state. Typical case is pre-published states - wouldn't want people (i think actually it is just the creator, but still) posting comments until it reaches published state

Case #15: I have workflow field on a task node. A supervisor can create tasks for users and can set it to pending approval but only a mderator can approve/reject these tasks. However, if the moderator rejects a task, only then I want to restrict him/her to enter workflow comment so that it will help other mods to track why a task was rejected. It can be applied to other workflows as well.

Steps to reproduce

Proposed resolution

#10: Rules, trigger on the state to toggle comment on / comment off on the node.
#14: Disable comments in nodes depingnig on specific taxonomy terms
#16: The Webform Workflow project has such a feature. We can borrow from that.
#22: The following workflow-specific modules do the same (which should work with workflow_node):
- https://www.drupal.org/project/workflow_fields
- https://www.drupal.org/project/wf_required_fields
#24: The following generic modules do the same (which would work with workflow_field):
- https://www.drupal.org/project/conditional_fields
- https://www.drupal.org/project/field_conditional_state
#25: Join #2639372: Set entity fields to hidden/view/edit/required based upon workflow state for the D8-plans
#29: Allowing the requirement of a comment field to be granular to transition - not (only) to state.
Example Transition Configuration
Creation -> Draft | Not Required
Draft -> Review | Not Required
Review -> Reject | Required
Reject -> Review | Not Required
Review -> Approved | Not Required
#32: Actually a very valuable reason to have the widget is, e.g. for and application flow the button would be "Apply now" or submit which can be nicely controlled with workflow and transition lables. But not having this breaks this idea totally. I think it must always be shown.
#33: [...] on some states, the transition should happen with comments mandatory and on remaining states, the comment field itself should not be visible. (per state, or perhaps even per role.)
#35: Apparently, the one-state button is not wanted, when the comment is not visible: ""When a user does not have any more transitions available, the block "Workflow Transition form" contain a "Update workflow" button that, when pushed, does nothing. Could it be removed?
#36: "You do need the (options) widget to add comments when you are in an endstate. (That may be the end state for some users, but not for others.)
Use case 1: When the current user only has the "save" action available (ie the "same state" -> "same state" transition) the button for that action does not appear.
Use case 2: The normal comment form disappears when there are no transitions available for the current user. I got users who cant change the workflow state but they can react on comments.

#18: Since Drupal version D7.8 (hence, also in Drupal version 8.0), the following hooks appear:
hook_field_widget_form_alter, hook_field_widget_WIDGET_TYPE_form_alter
which are deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use hook_field_widget_single_element_form_alter instead.

This is far more easy then the already existing
hook_form_alter, hook_form_FORM_ID_alter, hook_form_BASE_FORM_ID_alter, since all relevant data is already at hand.

Remaining tasks

In the past, maintainer was not very sharp on the sue case of each contributor.
Standard WorkflowTranstiionForm is:
- with widget (select/radios/dropdown, but many contributors use special case of 'Actionbuttons'.
- with comment field - this may be hidden/optional/required as per rol, or state (=pre) or even transition (=post)
- with attached field - text, number or file upload (which needs special treatment, since it does not work out-of-the-box)

- #10: Add a script using Rules;
- #14, #16: Add functionality in code, borrowed from Webform Workflow;
- #18: provide a nice submodule implementing:
-- a UX/DX appending the workflow(_admin)_ui submodule
-- the hook_field_widget_WIDGET_TYPE_form_alter hook for widget 'workflow_default', using one of the hooks in workflow.api.php. You will also find a.o.:
-- hook_form_workflow_transition_form_alter(), hook_form_alter(), hook_field_attach_form()

Caveat: At the moment (version 7.x-2.5 and 8.x-1.x) , there is no uniform way for Widgets on Entity forms, and the Workflow Transition Form. The WTF does not call a widget, but adds an element. So we need hook_field_widget_WIDGET_TYPE_form_alter AND hook_form_workflow_transition_form_alter
This needs work.

User interface changes

API changes

Data model changes

#36: The following patch contains 2 changes: https://www.drupal.org/files/issues/workflow-button_not_available-259631...
-

 // (If user has only 1 workflow option, there are no Action buttons.)
    $options = $to_sid_widget['#options'] ?? [];
    if (count($options) <= 1) {

-

// The easiest case first: more then one option: always show form.
    if ($count > 1) {return;}

Original report by Flying Drupalist

Can states be given to comments?

Comments

Flying Drupalist’s picture

Hi, I would really appreciate it if someone could help me. Thanks!

jvandyk’s picture

Category: support » feature

States cannot be given to comments with the current version of workflow. But it is an interesting feature, and worth including in the future.

Flying Drupalist’s picture

Thanks! :)

liquidcms’s picture

not sure what you are asking; but is it the same as this:

i need to be able to NOT allow comments on a post until/unless it is in a certain state - hard to believe that isn't here now; so maybe i am just missing it somewhere.

typical case is pre-published states - wouldn't want people (i think actually it is just the creator, but still) posting comments until it reaches published state

Encarte’s picture

So, just like there are options to read or edit nodes for each state, there would be options to read or post comments for each state on the workflow settings...

stinky’s picture

I'm trying to do the same thing. I have a node with workflow permissions set to view only, but I want the viewer to be able to submit comments. Is this really not possible?

jvandyk’s picture

It sounds like what you want is a trigger that runs an action when a workflow transitions happens; the action sets the node's comment settings. That is different than the feature requested in the original post.

hawleyal’s picture

subscribing

cindyr’s picture

Another vote here for allowing comments to be assigned to a state - certain roles have access to view/submit comments dependent on the state. Please?

Bastlynn’s picture

Status: Active » Closed (won't fix)

For version 1 of this request: Comments are not nodes. Use node_comment and then yes.

For version 2 of this request: Rules, trigger on the state to toggle comment on / comment off on the node.

johnv’s picture

Title: Comment States? » Disable/Enable comment based on State?
Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: Code » Workflow Access: Misc
Issue summary: View changes
Status: Closed (won't fix) » Closed (works as designed)

re-assigning this feature request.
See the following issue for using hook_workflow to change the comment state. As Bastlynn stated, this can be achieved with Rules, too,
#895106: Extended workflow access: permission to post comments or edit specific cck fields.

matt.rad’s picture

@johnv & Bastlynn: I would like to do this too. I have been looking around in Rules to see how to toggle the comment form on and off, but it is not apparent to me. Where will I find this? Thanks.

johnv’s picture

@matt.rad, try the new hooks of version 2.5 . See workflow.api.php for new documentation.

matt.rad’s picture

For others interested, this was the post that helped me figure out how to do this with Rules.

http://drupal.stackexchange.com/questions/13937/disable-comments-in-node...

najamfzl’s picture

I want a "conditional workflow comment" feature (see case below), not sure if this is what op wanted. If it isn't, do tell me so I can open another feature request. It would be great to have comment as a separate field so that it can be shown conditionally using Conditional Fields module. Please excuse me if it sound odd since I am strictly a mediocre site builder and know very little about code.

Case: I have workflow field on a task node. A supervisor can create tasks for users and can set it to pending approval but only a mderator can approve/reject these tasks. However, if the moderator rejects a task, only then I want to restrict him/her to enter workflow comment so that it will help other mods to track why a task was rejected. It can be applied to other workflows as well.

johnv’s picture

Component: Workflow Access: Misc » Code
Issue summary: View changes
Status: Closed (works as designed) » Active

Reopening, since this keeps popping up.
The Webform Workflow project has such a feature. We can borrow from that.

Marking #2585055: Workflow Comment depending on State as duplicate.

johnv’s picture

Title: Disable/Enable comment based on State? » Disable/Enable comment based on State/Role?
johnv’s picture

Title: Disable/Enable comment based on State/Role? » Customize the Widget (Disable/Enable comment, schedule, etc.) based on State/Role?
Version: 7.x-2.x-dev » 8.x-1.x-dev
Component: Code » Documentation
Category: Feature request » Task
Issue summary: View changes

Since Drupal version D7.8 (hence, also in Drupal version 8.0), the following hooks appear:
hook_field_widget_form_alter
hook_field_widget_WIDGET_TYPE_form_alter

This is far more easy then the already existing
hook_form_alter, hook_form_FORM_ID_alter, hook_form_BASE_FORM_ID_alter, since all relevant data is already at hand.

Volunteers may provide a submodule implementing:
- a nice UX/DX appending the workflow(_admin)_ui submodule
- the hook_field_widget_WIDGET_TYPE_form_alter() hook for widget 'workflow_default'.

At the moment (version 7.x-2.5 and 8.x-1.x) , there is no uniform way for Widgets on Entity forms, and the Workflow Transition Form. The WTF does not call a widget, but adds an element.
This needs work.

  • johnv committed 4940b8c on 8.x-1.x
    Issue #318325: Add hook_widget_form_alter to workflow.api.php and...

  • johnv committed 0dc5cc4 on 7.x-2.x
    Issue #318325: Add hook_widget_form_alter to workflow.api.php
    
johnv’s picture

Issue summary: View changes
johnv’s picture

Title: Customize the Widget (Disable/Enable comment, schedule, etc.) based on State/Role? » [Meta] Customize the Widget based on State/Role
Issue summary: View changes
johnv’s picture

Category: Task » Feature request
johnv’s picture

Issue summary: View changes

Since Drupal 7.14 and 8.0.0, the State API is available. It is used ins the following generic (not workflow-specific) contrib modules:
- https://www.drupal.org/project/conditional_fields
- https://www.drupal.org/project/field_conditional_state

In #2639372: Set entity fields to hidden/view/edit/required based upon workflow state , the plans for this functionality in D8 is discussed. Join that issue!

delacosta456’s picture

hi
another possibility for the Case #4 can be done using the Fools Rules module
hope it will help

johnv’s picture

Title: [Meta] Customize the Widget based on State/Role » [Meta] Display/hide/require the Widget subfields based on State/Role
fishfree’s picture

+1 pls.

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

Added info from #2616882: Make Comment Requirement Configurable per Transition:

[...] allowing the requirement of a comment field to be granular to transition.

Example Transition Configuration
Creation -> Draft | Not Required
Draft -> Review | Not Required
Review -> Reject | Required
Reject -> Review | Not Required
Review -> Approved | Not Required
My reasoning is that some transitions require context. [...] Anyone who is REJECTING content should also provide a comment which may include reason for rejection and needed revisions for approval. In this example users would be forced to comment on 4 other transitions just to enforce that one need. [...] I see this as adding an additional field (comment_required) to workflow_transitions table.

johnv’s picture

Title: [Meta] Display/hide/require the Widget subfields based on State/Role » [META] Display/hide/require the Widget subfields based on State/Role
Version: 8.x-1.x-dev » 2.1.x-dev
johnv’s picture

Issue summary: View changes
johnv’s picture

From #2948377: Do not hide widget when having only one option

Actually a very valuable reason to have the widget is, e.g. for and application flow the button would be "Apply now" or submit which can be nicely controlled with workflow and transition lables. But not having this breaks this idea totally. I think it must always be shown.

johnv’s picture

Issue summary: View changes

From #2850103: Display/hide/require the Comment subfield based on state
"I have a situation where on some states, the transition should happen with comments mandatory and on remaining states, the comment field itself should not be visible."

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

From #2701119: WorkflowTransitionForm contains action "Update workflow" when no transitions are available to the user

"When a user does not have any more transitions available, the block "Workflow Transition form" contain a "Update workflow" button that, when pushed, does nothing. Could it be removed?

johnv’s picture

johnv’s picture

Related issues:
johnv’s picture