From a43fdcb497ed77f147536d14d8457a7ef298313a Mon Sep 17 00:00:00 2001 From: John Voskuilen <john.voskuilen@sapito.nl> Date: Wed, 12 Mar 2025 00:54:14 +0100 Subject: [PATCH] Issue #3511999: Introduce class WorkflowTargetEntity --- modules/workflow_access/workflow_access.module | 4 +--- src/Entity/WorkflowTargetEntity.php | 17 ++++------------- src/Hook/WorkflowEntityHooks.php | 3 +-- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/modules/workflow_access/workflow_access.module b/modules/workflow_access/workflow_access.module index a2de08c5..009621f4 100644 --- a/modules/workflow_access/workflow_access.module +++ b/modules/workflow_access/workflow_access.module @@ -124,9 +124,7 @@ function workflow_access_user_role_update(EntityInterface $entity) { // Attend user to Rebuild data, because the weight of a role // is the key for workflow_Access. /** @var \Drupal\user\RoleInterface $entity */ - $targetEntity = new WorkflowTargetEntity($entity); - $original_entity = $targetEntity->getOriginal(); - + $original_entity = WorkflowTargetEntity::getOriginal($entity); if ($entity->getWeight() != $original_entity->getWeight()) { // Role's weight has changed. node_access_needs_rebuild(TRUE); diff --git a/src/Entity/WorkflowTargetEntity.php b/src/Entity/WorkflowTargetEntity.php index 32a8e3b3..367d756f 100644 --- a/src/Entity/WorkflowTargetEntity.php +++ b/src/Entity/WorkflowTargetEntity.php @@ -12,15 +12,6 @@ use Drupal\Core\Entity\EntityInterface; */ class WorkflowTargetEntity { - /** - * The wrapped entity, probably the transition->getTargetEntity(). - * - * This property will be set and used during the saving process. - * - * @var EntityInterface - */ - protected EntityInterface $targetEntity; - /** * {@inheritdoc} */ @@ -37,10 +28,10 @@ class WorkflowTargetEntity { * @see EntityInterface::getOriginal() * @see https://www.drupal.org/node/3295826 */ - public function getOriginal() { - return method_exists($this->targetEntity, 'getOriginal') - ? $this->targetEntity->getOriginal() - : $this->targetEntity->original ?? NULL; + public static function getOriginal(EntityInterface $entity) { + return method_exists($entity, 'getOriginal') + ? $entity->getOriginal() + : $enity->original ?? NULL; } /** diff --git a/src/Hook/WorkflowEntityHooks.php b/src/Hook/WorkflowEntityHooks.php index b67cf4cd..0e210544 100644 --- a/src/Hook/WorkflowEntityHooks.php +++ b/src/Hook/WorkflowEntityHooks.php @@ -359,8 +359,7 @@ class WorkflowEntityHooks { return; } - $targetEntity = new WorkflowTargetEntity($entity); - $original_entity = $targetEntity->getOriginal(); + $original_entity = WorkflowTargetEntity::getOriginal($entity); foreach ($field_names as $field_name => $label) { /** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $transition */ // @todo Transition is created in widget or WorkflowTransitionForm. -- GitLab