Skip to content
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

dev/drupal#72 fix display of profiles on events to use front end titles #14958

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public static function getListingFields(
*
* @return array
* The fields that belong to this ufgroup(s)
* @throws \Exception
*
* @throws \CRM_Core_Exception
*/
public static function getFields(
$id,
Expand Down Expand Up @@ -366,7 +367,7 @@ public static function getFields(
}

if (empty($fields) && !$validGroup) {
CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.',
throw new CRM_Core_Exception(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.',
[1 => implode(',', $profileIds)]
));
}
Expand Down
12 changes: 7 additions & 5 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,10 @@ public static function buildCustomDisplay(
* Formatted array of key value.
*
* @param array $profileFields
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) {
if ($gid) {
Expand All @@ -1446,11 +1450,9 @@ public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$
$fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD);
}

foreach ($fields as $v) {
if (!empty($v['groupTitle'])) {
$groupTitle['groupTitle'] = $v['groupTitle'];
break;
}
if (!empty($fields)) {
$profile = civicrm_api3('UFGroup', 'getsingle', ['id' => $gid, ['return' => ['title', 'frontend_title']]]);
$groupTitle['groupTitle'] = $profile['frontend_title'] ?? $profile['title'];
}

$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
Expand Down
10 changes: 6 additions & 4 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1217,11 +1217,13 @@ public static function updateContactFields($contactID, $params, $fields, &$form)
}

/**
* Assign Profiles.
* Assign Profiles to the template.
*
* @param CRM_Core_Form $form
* @param CRM_Event_Form_Registration_Confirm $form
*
* @throws \Exception
*/
public static function assignProfiles(&$form) {
public static function assignProfiles($form) {
$participantParams = $form->_params;
$formattedValues = $profileFields = [];
$count = 1;
Expand All @@ -1234,7 +1236,7 @@ public static function assignProfiles(&$form) {
$prefix1 = '';
$prefix2 = '';
}
if ($participantValue != 'skip') {
if ($participantValue !== 'skip') {
//get the customPre profile info
if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) {
$values = $groupName = [];
Expand Down
1 change: 1 addition & 0 deletions api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
* Array to be passed to function.
*
* @throws CiviCRM_API3_Exception
*
* @return array
*/
function civicrm_api3($entity, $action, $params = []) {
Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {

use CRMTraits_Profile_ProfileTrait;

public function setUp() {
$this->useTransaction(TRUE);
parent::setUp();
Expand Down Expand Up @@ -351,4 +353,35 @@ public function testOnlineRegNoPrice() {
$this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
}

/**
* Test form profile assignment.
*
* @throws \CRM_Core_Exception
* @throws \Exception
*/
public function testAssignProfiles() {
$event = $this->eventCreate();
$this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);

/* @var \CRM_Event_Form_Registration_Confirm $form */
$form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
$form->set('params', [[]]);
$form->set('id', $event['id']);
$form->set('values', [
'event' => $event['values'][$event['id']],
'location' => [],
'custom_pre_id' => $this->ids['UFGroup']['our profile'],
]);
$form->preProcess();

CRM_Event_Form_Registration_Confirm::assignProfiles($form);

$smarty = CRM_Core_Smarty::singleton();
$tplVar = $smarty->get_template_vars();
$this->assertEquals([
'CustomPre' => ['First Name' => NULL],
'CustomPreGroupTitle' => 'Public title',
], $tplVar['primaryParticipantProfile']);
}

}
79 changes: 79 additions & 0 deletions tests/phpunit/CRMTraits/Profile/ProfileTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Trait PriceSetTrait
*
* Trait for working with Price Sets in tests
*/
trait CRMTraits_Profile_ProfileTrait {

/**
* Add a profile to a contribution page.
*
* @param array $joinParams
* Must contain entity_id at minimum.
* @param array $ufGroupParams
*/
protected function createJoinedProfile($joinParams, $ufGroupParams = []) {
$this->createProfile($ufGroupParams);
$joinParams = array_merge([
'uf_group_id' => 'our profile',
'entity_table' => 'civicrm_contribution_page',
'weight' => 1,
], $joinParams);
if (empty($joinParams['module'])) {
$joinParams['module'] = $joinParams['entity_table'] === 'civicrm_event' ? 'CiviEvent' : 'CiviContribute';
}
if ($joinParams['module'] !== 'CiviContribute' && empty($joinParams['module_data'])) {
$params['module_data'] = [$joinParams['module'] => []];
}
$this->callAPISuccess('UFJoin', 'create', $joinParams);
}

/**
* Create a profile.
*
* @param $ufGroupParams
*/
protected function createProfile($ufGroupParams) {
$profile = $this->callAPISuccess('UFGroup', 'create', array_merge([
'group_type' => 'Contact',
'title' => 'Back end title',
'frontend_title' => 'Public title',
'name' => 'our profile',

], $ufGroupParams));
$this->ids['UFGroup'][$profile['values'][$profile['id']]['name']] = $profile['id'];

$this->callAPISuccess('UFField', 'create', [
'uf_group_id' => $profile['id'],
'field_name' => 'first_name',
]);
}

}