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

Set profile greeting fields based on actual contact type #14845

Merged
merged 1 commit into from
Jul 21, 2019
Merged
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
24 changes: 7 additions & 17 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - I feel like I would probably extract the 'inids' of this function (below the part where $name is determined) and create a sub-function called buildNamedProfile & we could probably restore sanity here.

I did find some reasons to give me enough comfort to merge this though

  1. Later in the external_identifier part I see a clear assumption that $form->get('id') would be the contact ID
      $form->add('text', $name, $title, $attributes, $required);
      $contID = $contactId;
      if (!$contID) {
        $contID = $form->get('id');
      }
      $form->addRule($name,
        ts('External ID already exists in Database.'),
        'objectExists',
        array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')
      );
    }
  1. On reflection this parameter is ONLY used for the greeting types so the risk is fairly contained.

  2. this needs cleaning up but step one is probably just to reformat the file otherwise it's gonna be a pain

}
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
Expand Down