Commit | Line | Data |
---|---|---|
42d1c64c EM |
1 | <?php |
2 | ||
3 | use Civi\Api4\WorkflowMessage; | |
4 | use Civi\WorkflowMessage\GenericWorkflowMessage; | |
5 | use Civi\WorkflowMessage\WorkflowMessageExample; | |
6 | ||
7 | /** | |
8 | * Basic contribution example for contribution templates. | |
9 | * | |
10 | * @noinspection PhpUnused | |
11 | * @noinspection UnknownInspectionInspection | |
12 | */ | |
13 | class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends WorkflowMessageExample { | |
14 | ||
15 | /** | |
16 | * Get the examples this class is able to deliver. | |
17 | */ | |
18 | public function getExamples(): iterable { | |
19 | $workflows = ['contribution_online_receipt', 'contribution_offline_receipt', 'contribution_invoice_receipt']; | |
20 | foreach ($workflows as $workflow) { | |
21 | yield [ | |
22 | 'name' => 'workflow/' . $workflow . '/' . $this->getExampleName(), | |
23 | 'title' => ts('Completed Contribution'), | |
24 | 'tags' => ['preview'], | |
25 | 'workflow' => $workflow, | |
26 | ]; | |
27 | } | |
28 | } | |
29 | ||
30 | /** | |
31 | * Build an example to use when rendering the workflow. | |
32 | * | |
33 | * @param array $example | |
34 | * | |
35 | * @throws \API_Exception | |
36 | * @throws \CRM_Core_Exception | |
37 | * @throws \Civi\API\Exception\UnauthorizedException | |
38 | */ | |
39 | public function build(array &$example): void { | |
40 | $workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first(); | |
41 | $this->setWorkflowName($workFlow['name']); | |
42 | $messageTemplate = new $workFlow['class'](); | |
43 | $this->addExampleData($messageTemplate); | |
44 | $example['data'] = $this->toArray($messageTemplate); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Add relevant example data. | |
49 | * | |
50 | * @param \CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt|\CRM_Contribute_WorkflowMessage_ContributionOnlineReceipt|\CRM_Contribute_WorkflowMessage_ContributionInvoiceReceipt $messageTemplate | |
51 | * | |
52 | * @throws \CRM_Core_Exception | |
53 | */ | |
54 | private function addExampleData(GenericWorkflowMessage $messageTemplate): void { | |
55 | $messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb')); | |
56 | $messageTemplate->setContribution(\Civi\Test::example('entity/Contribution/Euro5990/completed')); | |
57 | } | |
58 | ||
59 | } |