WorkflowMessage - Add getWorkflowName() and getGroupName()
authorTim Otten <totten@civicrm.org>
Thu, 22 Jun 2023 23:30:04 +0000 (16:30 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 23 Jun 2023 05:01:41 +0000 (22:01 -0700)
Civi/Test/WorkflowMessageTestTrait.php
Civi/WorkflowMessage/Traits/ReflectiveWorkflowTrait.php
Civi/WorkflowMessage/WorkflowMessageInterface.php

index 8adf4e5038e9fec3bc46dd2246e74e21e8bbd088..6ddbe3f75d3fec593a0451c778823f49728e431e 100644 (file)
@@ -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)");
index fd2fa3920df243c36ae4894955974416562d0347..f768cc2d9dec5434544154755191be0e79333985 100644 (file)
@@ -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
index c3d4438ce84bfb70ecc13e0f18851398ce70aa3d..8bf9156e6f88613ac8f8791b37d4ae57aa37bd1e 100644 (file)
@@ -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.