-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22636 from eileenmcnaughton/exampley
Add basic contribution example base for contribution workflows
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.ex.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
use Civi\Api4\WorkflowMessage; | ||
use Civi\WorkflowMessage\GenericWorkflowMessage; | ||
use Civi\WorkflowMessage\WorkflowMessageExample; | ||
|
||
/** | ||
* Basic contribution example for contribution templates. | ||
* | ||
* @noinspection PhpUnused | ||
* @noinspection UnknownInspectionInspection | ||
*/ | ||
class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends WorkflowMessageExample { | ||
|
||
/** | ||
* Get the examples this class is able to deliver. | ||
*/ | ||
public function getExamples(): iterable { | ||
$workflows = ['contribution_online_receipt', 'contribution_offline_receipt', 'contribution_invoice_receipt']; | ||
foreach ($workflows as $workflow) { | ||
yield [ | ||
'name' => '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')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters