- 🇧🇪Belgium vodde83
I can confirm that the solution by @ras-ben does indeed fix the issue. I also agree that this shouldn't be required, as the 'Draft' option before the fix was completely unusable.
However, I did update the fix slightly to this:
/** * Implements hook_form_BASE_FORM_ID_alter() for Node Forms. * * Fix an issue with previewing moderated Nodes, due to the moderation state not * being properly relayed. * * @see https://www.drupal.org/project/workflow_buttons/issues/3155336 */ function MY_MODULE_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id): void { // No need to do anything if the 'Preview' action is not available. if (!array_key_exists('preview', $form['actions'])) { return; } /** @var \Drupal\node\NodeForm $node_form */ $node_form = $form_state->getFormObject(); $node = $node_form->getEntity(); // If the Node is a moderated one, relay the current moderation state to the // 'Preview' action. if ($moderation_state = $node->get('moderation_state')->getString()) { $form['actions']['preview']['#moderation_state'] = $moderation_state; } }
- Status changed to RTBC
over 1 year ago 7:07am 21 September 2023 - 🇮🇳India shubham_jain
Hi @vodde83, I confirm that the solution provided by you solves the issue and is much better approach. So, moving it to the RTBC.
- Status changed to Needs work
over 1 year ago 9:04am 22 September 2023 - 🇩🇰Denmark ras-ben Copenhagen
A review comment:
if ($moderation_state = $node->get('moderation_state')->getString()) {
What if the node doesnt have 'moderation_state'? Then, you'll be doing ->getString() on null.
- 🇧🇪Belgium vodde83
True that @ras-ben, an additional check
$node->hasField('moderation_state')
would be even better. - 🇯🇵Japan ultrabob Japan
Would the correct patch for this module be to update workflow_buttons/src/Plugin/Field/FieldWidget/WorkflowButtonsWidget.php->processActions to set a default moderation state for preview if it exists, rather than doing a form alter?
- 🇯🇵Japan ultrabob Japan
@mlncn if you have a thought on the best approach, I'd be happy to take a crack at this.
- 🇪🇪Estonia mikkmiggur
I created a patch for this module based on the #5 code.
-
mlncn →
committed 6a86da6f on 8.x-1.x authored by
mikkmiggur →
Issue #3155336 by mikkmiggur, ultrabob, wlbryant, ras-ben, vodde83,...
-
mlncn →
committed 6a86da6f on 8.x-1.x authored by
mikkmiggur →
- Status changed to Fixed
about 1 year ago 2:22am 13 December 2023 - 🇺🇸United States mlncn Minneapolis, MN, USA
Thank you mikkmiggur, ultrabob, wlbryant, ras-ben, vodde83, and shubham_jain for your work on this!
Fix applied.
Automatically closed - issue fixed for 2 weeks with no activity.