Extra Workflow fields don't work as of v1.8

Created on 23 April 2025, 4 days ago

There's a problem with extra workflow fields: as of v1.8 they aren't working properly anymore, v2.0 has the same problem.

I have a defined workflow 'subdossier' on a node bundle subdossier, and there are extra fields created on "/admin/config/workflow/workflow/subdossier/fields". I can fill in those fields on the node view form of a subdossier instance , and when I change workflow state at the same time, I can see the values of the extra fields filled in in the updated node view afterwards.

But when I go to the node edit form for that specific instance afterwards, the values are not "pre-filled"/"filled in" anymore as of v1.8. When I revert only the workflow module between v1.7 and v1.8/v2.0 it works/doesn't work. So it's something in workflow that broke from v1.7 to v1.8 (and it's still broken in v2.0).

I can't put my finger on where exactly it breaks, because that Drupal site does some extremely complex workflow processing, but it breaks somewhere in the workflow module. For now I just reverted to workflow v1.7 and all is ok again.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @sboden
  • Some more information, I'm still debugging.

    I have a node bundle subdossier that has a workflow subdossier, and that workflow has some extra fields. These fields pop up on the subdossier node view form depending on the chosen "to workflow" with some manual conditional hook alter forms.

    There's a field "field_amount_paid_back" that exists both on the workflow and on the subdossier node bundle. And in the presave hook of the WorkflowTransition the field is copied from Workflow to node bundle with following function:

      public static function presave_transition_paid_back(EntityInterface $entity) {
        $subdossier = $entity->getTargetEntity();
        \Drupal::logger('SBO_INFO')->info('Starting presave_transition_paid_back - Subdossier ID: @id, Label: @label', [
          '@id' => $subdossier->id(),
          '@label' => $subdossier->label(),
        ]);
        
        $subdossier->field_amount_paid_back->value = $entity->field_amount_paid_back->value;
        \Drupal::logger('SBO_INFO')->info('Setting field_amount_paid_back to @value for subdossier @label', [
          '@value' => $subdossier->field_amount_paid_back->value,
          '@label' => $subdossier->label(),
        ]);
      }
    

    I added some extra logging... read from bottom to top (it's from "Recents logs")

      7    24/Apr 12:57   SBO_INFO   Info       Setting field_amount_paid_back to 112 for subdossier 2020CCP003262-C
      6    24/Apr 12:57   SBO_INFO   Info       Starting presave_transition_paid_back - Subdossier ID: 688488, Label:                                        
     2020CCP003262-C
      5    24/Apr 12:57   SBO_INFO   Info       Workflow transition presave - Bundle: subdossier, From: subdossier_paid,
                                                To: subdossier_paid_back
      4    24/Apr 12:57   SBO_INFO   Info       Entering entity_presave for
      3    24/Apr 12:57   SBO_INFO   Info       Node presave - Bundle: subdossier, ID: 688488, Label: 2020CCP003262-C
      2    24/Apr 12:57   SBO_INFO   Info       Entering entity_presave for 2020CCP003262-C
      1    24/Apr 12:57   SBO_INFO   Info       Entering node_presave for 2020CCP003262-C
    

    This happens when I press "Change workflow" on the node view form of subdossier 2020CCP003262-C. It enters the presave for the node, the entity presave is entered. Then the workflow transition presave is entered (the one without label above). And then finally that one field is copied from workflow to node bundle.

    The results:
    - When using workflow v1.7 the field_amount_paid_back is saved correctly on the node bundle.
    - When using workflow v1.8 or higher the field_amount_paid_back is not saved on the node bundle.

    However in both cases the flow is the same according to my debug logging statements. In v1.8 and higher the field is copied from workflow to node bundle, but the node bundle doesn't seem to get saved anymore. In v1.7 for some reason the node bundle is still saved after the presave from workflow transition is executed.

    The only thing different is the version of the workflow module.

  • Found it in v1.8.

    When I add following to workflow.entity.inc:

    /**
     * Implements hook_entity_presave().
     *
     * @param \Drupal\Core\Entity\EntityInterface $entity
     *   An EntityInterface object.
     */
    function workflow_entity_presave(EntityInterface $entity) {
      if (!$entity->isNew()) {
       // Avoid a double call by hook_entity_presave and hook_entity_insert.
       _workflow_execute_transitions($entity);
      }
    }
    

    Then the functionality reverts to the v1.7 behaviour.

  • Patches attached revert the behaviour back to the way v1.7 behaved for saving target entities (in a sneaky way). I have a patch for workflow 1.8 and workflow 2.0

    If possible I would like to have them reviewed and published as workflow version 1.8.1 and 2.0.1. It is breaking behaviour, but it's actually reintroducing the way v1.7 worked. The main change is reintroducing the presave hook.

    The way I see it, no project is yet using workflow v2.0 (it's too new). Most projects are on workflow v1.7, maybe tried to upgrade to v1.8 but reverted because of the changed behaviour, I did as well.

    If you have a project using workflow in a simple way, workflow v1.8 would work as is, the new patch is probably not going to break anything. When you have a project using workflow in a complex way, these patches will revert saving behaviour of the target entity of a workflow transition as that was done in workflow v1.7

Production build 0.71.5 2024