From 50bf705c3ad6f591a0e375713b7daf2e98f919b7 Mon Sep 17 00:00:00 2001 From: Kirk Jackson Date: Tue, 27 May 2014 05:42:03 +0100 Subject: [PATCH] CRM-14747 - Profiles - Fixed error caused by profile fields with empty labels ---------------------------------------- * CRM-14747: https://issues.civicrm.org/jira/browse/CRM-14747 --- CRM/Core/BAO/UFGroup.php | 15 ++++----------- CRM/Profile/Page/Dynamic.php | 17 ++++++++--------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 6899680046..cd7a474c12 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -958,7 +958,6 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $multipleFields = array('url'); - $nullIndex = $nullValueIndex = ' '; //start of code to set the default values foreach ($fields as $name => $field) { @@ -972,18 +971,12 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { continue; } + // Create a unique, non-empty index for each field. $index = $field['title']; - //handle for the label not set for the field - if (empty($field['title'])) { - $index = $nullIndex; - $nullIndex .= $nullIndex; - } + if ($index === '') $index = ' '; + while (array_key_exists($index, $values)) + $index .= ' '; - //handle the case to avoid re-write where the profile field labels are the same - if (array_key_exists($index, $values)) { - $index .= $nullValueIndex; - $nullValueIndex .= $nullValueIndex; - } $params[$index] = $values[$index] = ''; $customFieldName = NULL; // hack for CRM-665 diff --git a/CRM/Profile/Page/Dynamic.php b/CRM/Profile/Page/Dynamic.php index f37b42731a..08b3bcb246 100644 --- a/CRM/Profile/Page/Dynamic.php +++ b/CRM/Profile/Page/Dynamic.php @@ -321,16 +321,15 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { $profileFields = array(); $labels = array(); - //CRM-14338 - $nullValueIndex = ' '; foreach ($fields as $name => $field) { - if ( isset($labels[$field['title']]) ) { - $labels[$field['title'].$nullValueIndex] = preg_replace('/\s+|\W+/', '_', $name); - $nullValueIndex .= $nullValueIndex; - } - else { - $labels[$field['title']] = preg_replace('/\s+|\W+/', '_', $name); - } + //CRM-14338 + // Create a unique, non-empty index for each field. + $index = $field['title']; + if ($index === '') $index = ' '; + while (array_key_exists($index, $labels)) + $index .= ' '; + + $labels[$index] = preg_replace('/\s+|\W+/', '_', $name); } foreach ($values as $title => $value) { -- 2.25.1