From 42d1c64c9a8dacd0dc100a7480e98cbd8de2f652 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 27 Jan 2022 15:39:01 +1300 Subject: [PATCH] Add basic contribution example base for contribution workflows The examples have very little exposed tokens so not much is visible - but it is a start.... Note the Contribution tokens, unlike contact, don't take input of already loaded data - which is a todo to improve this --- .../Contribution/BasicContribution.ex.php | 59 +++++++++++++++++++ .../WorkflowMessageExample.php | 20 +++++++ 2 files changed, 79 insertions(+) create mode 100644 CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.ex.php diff --git a/CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.ex.php b/CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.ex.php new file mode 100644 index 000000000000..23c035710532 --- /dev/null +++ b/CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.ex.php @@ -0,0 +1,59 @@ + 'workflow/' . $workflow . '/' . $this->getExampleName(), + 'title' => ts('Completed Contribution'), + 'tags' => ['preview'], + 'workflow' => $workflow, + ]; + } + } + + /** + * Build an example to use when rendering the workflow. + * + * @param array $example + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + public function build(array &$example): void { + $workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first(); + $this->setWorkflowName($workFlow['name']); + $messageTemplate = new $workFlow['class'](); + $this->addExampleData($messageTemplate); + $example['data'] = $this->toArray($messageTemplate); + } + + /** + * Add relevant example data. + * + * @param \CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt|\CRM_Contribute_WorkflowMessage_ContributionOnlineReceipt|\CRM_Contribute_WorkflowMessage_ContributionInvoiceReceipt $messageTemplate + * + * @throws \CRM_Core_Exception + */ + private function addExampleData(GenericWorkflowMessage $messageTemplate): void { + $messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb')); + $messageTemplate->setContribution(\Civi\Test::example('entity/Contribution/Euro5990/completed')); + } + +} diff --git a/Civi/WorkflowMessage/WorkflowMessageExample.php b/Civi/WorkflowMessage/WorkflowMessageExample.php index 40aead12b4a1..9b04daeb9ebd 100644 --- a/Civi/WorkflowMessage/WorkflowMessageExample.php +++ b/Civi/WorkflowMessage/WorkflowMessageExample.php @@ -40,6 +40,17 @@ abstract class WorkflowMessageExample implements ExampleDataInterface { */ protected $wfName; + /** + * Set the workflow name. + * + * The workflow name is the value in civicrm_message_template.workflow. + * + * @param string $workflowName + */ + public function setWorkflowName(string $workflowName): void { + $this->wfName = $workflowName; + } + /** * Name for this example specifically. * @@ -47,6 +58,15 @@ abstract class WorkflowMessageExample implements ExampleDataInterface { */ protected $exName; + /** + * Get the example name. + * + * @return string + */ + public function getExampleName(): string { + return $this->exName; + } + /** * WorkflowMessageExample constructor. */