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

Conversation

colemanw
Copy link
Member

Overview

Fixes civicrm/org.civicrm.contactlayout#58
Sets greeting options in a profile based on the actual contact type being edited, if applicable.

Before

Contact type was determined based on the profile type, even when editing an existing contact.

After

When editing an existing contact, contact type is determined from that contact.

@civibot
Copy link

civibot bot commented Jul 19, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor

So are we confident the form id would always be the contact id here?

@ryanlrobinson
Copy link

Works in my test, the same scenario that prompted filing the issue.

@colemanw
Copy link
Member Author

@eileenmcnaughton err, no I'm not confident of that. In fact, I notice that there is a $contactId param that should be getting passed to this function, but is not. And (maddeningly) in other contexts values are being passed to that param like activity_id, contribution_id etc. So we can't rely on that!

@colemanw
Copy link
Member Author

Ok I've checked some more. This function is really screwy. We can't use the $contactId param because that's actually used for setting the field id. So second best is to kind of hack it in like this. I've updated the PR to only act when the profile is of type "Contact" which should be safer.

) {
$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

@eileenmcnaughton eileenmcnaughton merged commit 2bb6bb8 into civicrm:master Jul 21, 2019
@eileenmcnaughton eileenmcnaughton deleted the Set branch July 21, 2019 22:44
@eileenmcnaughton
Copy link
Contributor

This feels like a VERY small step on our general expectation that we should do some cleanup when touching toxic functions - #14853 but it does remove something that was blocking more cleanup

@colemanw colemanw restored the Set branch September 3, 2019 17:33
@colemanw colemanw deleted the Set branch January 30, 2020 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Household Greetings in Profiles
3 participants