From b8218aeec76a791c8dfddaf02a03194b244dd12f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 22 Jun 2023 16:30:04 -0700 Subject: [PATCH] WorkflowMessage - Add getWorkflowName() and getGroupName() --- Civi/Test/WorkflowMessageTestTrait.php | 1 + .../Traits/ReflectiveWorkflowTrait.php | 14 ++++++++++++++ Civi/WorkflowMessage/WorkflowMessageInterface.php | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/Civi/Test/WorkflowMessageTestTrait.php b/Civi/Test/WorkflowMessageTestTrait.php index 8adf4e5038..6ddbe3f75d 100644 --- a/Civi/Test/WorkflowMessageTestTrait.php +++ b/Civi/Test/WorkflowMessageTestTrait.php @@ -71,6 +71,7 @@ trait WorkflowMessageTestTrait { if ($prefix === NULL) { $prefix = sprintf('[%s] ', $this->getWorkflowName()); } + $this->assertEquals($refInstance->getWorkflowName(), $cmpInstance->getWorkflowName(), "{$prefix}Should have same workflow name)"); $this->assertEquals($refInstance->export('tplParams'), $cmpInstance->export('tplParams'), "{$prefix}Should have same export(tplParams)"); $this->assertEquals($refInstance->export('tokenContext'), $cmpInstance->export('tokenContext'), "{$prefix}should have same export(tokenContext)"); $this->assertEquals($refInstance->export('envelope'), $cmpInstance->export('envelope'), "{$prefix}Should have same export(envelope)"); diff --git a/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php b/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php index fd2fa3920d..f768cc2d9d 100644 --- a/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php +++ b/Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php @@ -39,6 +39,20 @@ use Civi\Api4\Utils\ReflectionUtils; */ trait ReflectiveWorkflowTrait { + public function getWorkflowName(): ?string { + return $this->_extras['envelope']['workflow'] ?? \CRM_Utils_Constant::value(static::CLASS . '::WORKFLOW'); + } + + /** + * @return string|null + * @deprecated + * It is not recommended that new things depend on the group-name. However, the plumbing still + * passes-through the group-name. + */ + public function getGroupName(): ?string { + return $this->_extras['envelope']['groupName'] ?? \CRM_Utils_Constant::value(static::CLASS . '::GROUP'); + } + /** * The extras are an open-ended list of fields that will be passed-through to * tpl, tokenContext, etc. This is the storage of last-resort for imported diff --git a/Civi/WorkflowMessage/WorkflowMessageInterface.php b/Civi/WorkflowMessage/WorkflowMessageInterface.php index c3d4438ce8..8bf9156e6f 100644 --- a/Civi/WorkflowMessage/WorkflowMessageInterface.php +++ b/Civi/WorkflowMessage/WorkflowMessageInterface.php @@ -13,6 +13,11 @@ namespace Civi\WorkflowMessage; interface WorkflowMessageInterface { + /** + * @return string + */ + public function getWorkflowName(): ?string; + /** * @return \Civi\WorkflowMessage\FieldSpec[] * A list of field-specs that are used in the given format, keyed by their name in that format. -- 2.25.1