Skip to content
Snippets Groups Projects
Commit d0b58293 authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

#2814 Fix profile edit to use messagetemplate:render

If the api were merged I would have used that - but this adds the test & when can test converting
to the api when it is merged. It gets the hard lifting of this conversion out of the way
parent e56a41aa
No related branches found
No related tags found
No related merge requests found
......@@ -243,6 +243,9 @@ SELECT module,is_reserved
/**
* Process the user submitted custom data values.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function postProcess() {
parent::postProcess();
......@@ -287,20 +290,11 @@ SELECT module,is_reserved
$url = CRM_Utils_System::url('civicrm/profile/view', $urlParams);
}
else {
// Replace tokens from post URL
$contactParams = [
'contact_id' => $this->_id,
'version' => 3,
];
$contact = civicrm_api('contact', 'get', $contactParams);
$contact = reset($contact['values']);
$dummyMail = new CRM_Mailing_BAO_Mailing();
$dummyMail->body_text = $this->_postURL;
$tokens = $dummyMail->getTokens();
$url = CRM_Utils_Token::replaceContactTokens($this->_postURL, $contact, FALSE, CRM_Utils_Array::value('text', $tokens));
$url = CRM_Core_BAO_MessageTemplate::renderTemplate([
'messageTemplate' => ['msg_text' => $this->_postURL],
'contactId' => $this->_id,
'disableSmarty' => TRUE,
])['text'];
}
$session->replaceUserContext($url);
......
<?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\Api4\UFJoin;
/**
* Test class for CRM_Price_BAO_PriceSet.
* @group headless
*/
class CRM_Profile_Form_EditTest extends CiviUnitTestCase {
public function tearDown(): void {
$this->quickCleanup(['civicrm_uf_field', 'civicrm_uf_group']);
parent::tearDown();
}
/**
* Test the url on the profile edit form renders tokens
*
* @throws \API_Exception
*/
public function testProfileUrl(): void {
$profileID = Civi\Api4\UFGroup::create(FALSE)->setValues([
'post_URL' => 'civicrm/{contact.display_name}',
'title' => 'title',
])->execute()->first()['id'];
UFJoin::create(FALSE)->setValues([
'module' => 'Profile',
'uf_group_id' => $profileID,
])->execute();
$this->uFFieldCreate(['uf_group_id' => $profileID]);
$id = $this->individualCreate();
$form = $this->getFormObject('CRM_Profile_Form_Edit');
$form->set('gid', $profileID);
$form->set('id', $id);
$form->buildForm();
$form->postProcess();
$this->assertEquals('civicrm/Mr. Anthony Anderson II', CRM_Core_Session::singleton()->popUserContext());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment