Actually, the Workflow module allows same state transitions, but no historical records are saved in that case.

For our project, when a node is in a certain workflow step we want to be able to load data and other things (i.e. files), saving a row in the workflow transition history.

We are working on a patch for the Workflow module that adds a configuration setting to specify if the same state transitions have to be logged in history.

Regards,
Michele

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mithenks created an issue. See original summary.

mithenks’s picture

Here is a possible implementation.
Please take a look and review it.

Regards,
Michele

johnv’s picture

Issue tags: +Needs documentation

There should be another issue with the same feature request. perhaps it is already closed. I cannot find it again.

The general code pattern is:

    $comment = $transition->getComment();
    $state_changed = ($transition->from_sid != $transition->to_sid);
    if ($state_changed || $comment) {
      // Save
    } else {
      // Skip
    }

So instead of adding a new setting, you can use the following facility:

      // The transition is allowed, but not scheduled.
      // Let other modules modify the comment. The transition (in context) contains all relevant data.
      $context = ['transition' => $this];
      \Drupal::moduleHandler()->alter('workflow_comment', $comment, $context);
      $this->setComment($comment);

by implementing function hook_workflow_comment_alter(&$comment, array &$context).
There, you can make your custom evaluations. See also the file workflow.api.php for code examples.

Perhaps this 'feature' could be added to the Documenation pages.

johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.0-rc1
Status: Needs review » Closed (won't fix)

Sorry, I have to mark this a a Won't fix. I hope the above workaround works for you.
Your patch did help me to identify the attached child issue, so thanks for that.

robertom’s picture

I johnv,

inside function hook_workflow_comment_alter(&$comment, array &$context) we can solve the problem only by adding a fake comment.

I have open another issue that should be a good path for us #2987772: Check for attached fields on WorkflowTransition::isEmpty() method