Problem/Motivation

On Drupal 10.6, viewing an entity with a workflow field fatals:

Error: Call to undefined method Drupal\node\Entity\Node::getOriginal()
in Drupal\workflow\Entity\WorkflowManager::getOriginal()
(line 221 of modules/contrib/workflow/src/Entity/WorkflowManager.php)

#3607490 (b6fc7f3b) replaced the method_exists() guard in WorkflowManager::getOriginal() with:

version_compare(\Drupal::VERSION, '10.2', '>=')

EntityInterface::getOriginal() was introduced in Drupal 11.2, not 10.2 (the @todo removed in that same commit says so). On any core from 10.2 to 11.1 the comparison passes and the 11.2-only method is called, producing the fatal above.

Confirmed on 2.1.x-dev at 24cf252.

Ruled out custom code as the cause: no site module calls WorkflowManager::getOriginal() or getOriginal() on an entity. Site code accesses $node->original (property form, valid on 10.6) only inside hook_node_presave(). Only one copy of WorkflowManager.php exists in the codebase.

Steps to reproduce

  1. Drupal 10.6, workflow 2.1.x-dev (24cf252)
  2. Attach a workflow field to a content type
  3. View a node of that type

I have not verified this on a stock display. On this site the field is rendered by a custom formatter that uses the workflow_transition view builder, which is presumably how WorkflowManager::getOriginal() is reached on view. The version_compare bug is independent of the call path, so the fix applies regardless of what reaches the method.

Proposed resolution

Correct the version string:

version_compare(\Drupal::VERSION, '11.2', '>=')

Note \Drupal::VERSION is '11.2.x-dev' on dev branches, which version_compare treats as lower than '11.2'. DeprecationHelper::backwardsCompatibleCall() normalizes that case and is already used elsewhere in this module (workflow_access forms, for node_access_needs_rebuild()), so it may be the better fit:

DeprecationHelper::backwardsCompatibleCall(
  \Drupal::VERSION,
  '11.2.0',
  fn() => $entity->getOriginal(),
  fn() => $entity->original ?? NULL,
);

Remaining tasks

Patch, review, commit.

Environment

Drupal core: 10.6

Workflow: 2.1.x-dev (24cf252)

Using: Workflow Field (workflow-type field on node; workflow_node not enabled). Core workflows module also enabled, content moderation not in play.

Comments

kkaya created an issue. See original summary.

  • johnv committed d3a1fac7 on 2.1.x
    Issue #3622115: Wrong version in WorkflowManager::getOriginal() guard —...
johnv’s picture

Version: 2.1.x-dev » 2.1.12
Status: Active » Fixed

Oh thanks. That is a problem, since it is also in the wild in new version 2.1.12

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.