[Meta] Display/hide/require the Widget subfields based on State/Role

Created on 7 October 2008, about 17 years ago
Updated 6 November 2023, almost 2 years ago

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.

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 🌱 Set entity fields to hidden/view/edit/required based upon workflow state Active for the D8-plans
#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

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

- #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.

Original report by Flying Drupalist

Feature request
Status

Active

Version

1.0

Component

Documentation

Created by

🇺🇸United States Flying Drupalist

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024