From d43d0639ff74a59d080f2a0ecf2d005406116f3d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 19 Jul 2019 15:36:17 -0400 Subject: [PATCH] Set profile greeting fields based on actual contact type --- CRM/Core/BAO/UFGroup.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 98b606568869..2ea7bbd575a7 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -2014,31 +2014,21 @@ public static function buildProfile( $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE)); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { - //add email greeting, postal greeting, addressee, CRM-4575 - $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); + // Get contact type for greeting selector + $gId = $form->get('gid') ?: CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); - if (empty($profileType) || in_array($profileType, array( - 'Contact', - 'Contribution', - 'Participant', - 'Membership', - )) - ) { - $profileType = 'Individual'; + if (!$profileType || in_array($profileType, ['Contact', 'Contribution', 'Participant', 'Membership'])) { + $profileType = ($profileType == 'Contact' && $form->get('id')) ? CRM_Contact_BAO_Contact::getContactType($form->get('id')) : 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } - $greeting = array( + $greeting = [ 'contact_type' => $profileType, 'greeting_type' => $fieldName, - ); - $form->add('select', $name, $title, - array( - '' => ts('- select -'), - ) + CRM_Core_PseudoConstant::greeting($greeting), $required - ); + ]; + $form->add('select', $name, $title, ['' => ts('- select -')] + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE