-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign profileID to template in UFNotify, add example #29441
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,74 @@ | ||
<?php | ||
|
||
use Civi\Api4\UFField; | ||
use Civi\Api4\UFGroup; | ||
use Civi\Api4\WorkflowMessage; | ||
use Civi\Test; | ||
use Civi\WorkflowMessage\WorkflowMessageExample; | ||
|
||
/** | ||
* Basic profile example. | ||
* | ||
* @noinspection PhpUnused | ||
* @noinspection UnknownInspectionInspection | ||
*/ | ||
class CRM_Core_WorkflowMessage_Profile_Profile extends WorkflowMessageExample { | ||
|
||
/** | ||
* Get the examples this class is able to deliver. | ||
*/ | ||
public function getExamples(): iterable { | ||
$workflows = ['uf_notify']; | ||
foreach ($workflows as $workflow) { | ||
yield [ | ||
'name' => 'workflow/' . $workflow . '/general', | ||
'title' => ts('Profile Notification'), | ||
'tags' => ['preview'], | ||
'workflow' => $workflow, | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* Build an example to use when rendering the workflow. | ||
* | ||
* @param array $example | ||
* | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
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); | ||
$example['data'] = $this->toArray($messageTemplate); | ||
} | ||
|
||
/** | ||
* Add relevant example data. | ||
* | ||
* @param \CRM_Core_WorkflowMessage_UFNotify $messageTemplate | ||
* @param array $example | ||
* | ||
* @throws \CRM_Core_Exception | ||
* @throws \Civi\API\Exception\UnauthorizedException | ||
*/ | ||
private function addExampleData(\CRM_Core_WorkflowMessage_UFNotify $messageTemplate, $example): void { | ||
$contact = Test::example('entity/Contact/Barb'); | ||
$messageTemplate->setContact($contact); | ||
$profile = UFGroup::get(FALSE)->setLimit(1)->execute()->first(); | ||
$fields = UFField::get(FALSE)->addWhere('id', '=', $profile['id'])->execute(); | ||
$values = []; | ||
foreach ($fields as $field) { | ||
if (isset($contact[$field['field_name']])) { | ||
$values[$field['label']] = $contact[$field['field_name']]; | ||
} | ||
else { | ||
$values[$field['label']] = ts('User entered field'); | ||
} | ||
} | ||
$messageTemplate->setProfileID($profile['id']); | ||
$messageTemplate->setProfileFields($values); | ||
} | ||
|
||
} |
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,86 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
use Civi\WorkflowMessage\GenericWorkflowMessage; | ||
|
||
/** | ||
* Receipt sent when someone receives a copy of profile that has been filled out. | ||
* | ||
* @method int getProfileID() | ||
* @method $this setProfileID(int $profileID) | ||
* @method array getProfileFields() | ||
* @method $this setProfileFields(array $profileFields) | ||
* | ||
* @support template-only | ||
* | ||
* @see CRM_Core_BAO_UFGroup::commonSendMail | ||
*/ | ||
class CRM_Core_WorkflowMessage_UFNotify extends GenericWorkflowMessage { | ||
public const WORKFLOW = 'uf_notify'; | ||
|
||
/** | ||
* @var int | ||
* | ||
* @scope tplParams | ||
*/ | ||
protected $profileID; | ||
|
||
/** | ||
* @var array | ||
* | ||
* @scope tplParams as values | ||
*/ | ||
protected $profileFields; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @scope tplParams | ||
*/ | ||
protected $contactLink; | ||
|
||
public function getContactLink(): string { | ||
return CRM_Utils_System::url('civicrm/contact/view', | ||
"reset=1&cid=" . $this->getContactID(), | ||
TRUE, NULL, FALSE, FALSE, TRUE | ||
); | ||
} | ||
|
||
/** | ||
* @var string | ||
* | ||
* @scope tplParams as grouptitle | ||
*/ | ||
protected $groupTitle; | ||
|
||
public function getGroupTitle(): string { | ||
return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->getProfileID(), 'frontend_title'); | ||
} | ||
|
||
/** | ||
* @var string | ||
* | ||
* @scope tplParams | ||
*/ | ||
protected $userDisplayName; | ||
|
||
public function getUserDisplayName(): string { | ||
$loggedInUser = CRM_Core_Session::getLoggedInContactID(); | ||
if (!$loggedInUser) { | ||
return ''; | ||
} | ||
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', | ||
$loggedInUser, | ||
'display_name' | ||
); | ||
} | ||
|
||
} |
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
{$grouptitle} {ts 1=$displayName}Submitted by %1{/ts} - {contact.display_name} | ||
{$grouptitle} {ts 1=$userDisplayName}Submitted by %1{/ts} - {contact.display_name} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got error because my profile had missing frontend_title
TypeError: CRM_Core_WorkflowMessage_UFNotify::getGroupTitle(): Return value must be of type string, null returned in CRM_Core_WorkflowMessage_UFNotify->getGroupTitle() (line 65 of /Users/pradeep/Sites/drupal7/sites/all/modules/civicrm/CRM/Core/WorkflowMessage/UFNotify.php).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using
CRM_Core_BAO_UFGroup::getFrontEndTitle($this->getProfileID());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pradpnayak did you test this by backporting it - in 5.72 frontend_title should be a required field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eileenmcnaughton
My bad, tested by upgrading to 5.71 beta. The frontend title is not updated with the title field and the field is required through UI.