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

CRM-21180: Inline changes to custom fields aren't reflected in custom greetings + CRM-21474 add support for setting non-required fields to 'null' #11364

Merged
merged 3 commits into from
Dec 4, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Dec 4, 2017

Overview

Reconciled fixes affecting contact greetings code:

  1. in various cases, changes to custom fields are not immediately reflected in greetings, even if the greetings contain custom field references (e.g., {contact.custom_1}).
  2. allow setting greetings to NULL
    Both WIP: CRM-21180: Inline changes to custom fields aren't reflected in custom greetings #11095 and https://github.com/civicrm/civicrm-core/compare/master...eileenmcnaughton:pseudo?expand=1 were working on the same code area & this is a reconciliation of the changes in both

Before

  1. Lack of immediate change is especially visible in the Summary tab of a contact record.
    Steps to reproduce:

Note the system ID of an existing custom field. In this example we'll use Most Important Issue, custom field ID=1, options: Education; Environment; Social Justice.
Find any existing contact and set a value in the custom field, e.g., "Education"
Edit a contact's "Addressee" field to "Customized", with the value "{contact.custom_1}" and save the contact; note that the Addressee field now says "Education".
Change the value of this custom field via the appropriate inline editing or tab for the custom field group; alternatively, use the CustomValue.create API like so:
cv api CustomValue.create sequential=1 entity_id=N entity_table="civicrm_contact" custom_1="Env"
NOTE: This repro recipe will not work if you change this field value by using the "Edit" button for the contact (i.e., by navigating to to /civicrm/contact/add?reset=1&action=update&cid=[N]); or by using the Contact.create API)
Observe that the Addressee field value is NOT updated to reflect the new custom field value.

  1. Cannot set a greeting to NULL using api

After

  1. Repeating the steps above, in the last step, the Addressee field value IS updated to reflect the new custom field value.
  2. It is possible in general for non-required pseudoconstant fields and specifically (and tested) for greeting fields to be set to 'null' resulting in an update to NULL

Technical Details

2 new functions introduced:
CRM_Contact_BAO_Contact::ensureGreetingParamsAreSet() - this is called earlier in create so we know that for BOTH updates & creates the fields have been set, if they should be. This prevents a NULL field being overwritten.
CRM_Contact_BAO_Contact::updateGreetingsOnTokenFieldChange() - checks whether the fields that are changed are used in the tokens & if so processes an update.

Comments


twomice and others added 2 commits December 4, 2017 20:16
…n custom greetings.

Includes unit test.

Toward CRM-21180: Better static var handling.

Toward CRM-21180: removed static vars; removed unused method parameters.

CRM-21180 add unit test for custom field being set in address

CRM-21180 Inline changes to custom fields aren't reflected in custom greetings

This incorporates Allan's work to cause custom fields to be updated
when a custom value is updated. These have been reconciled with the changes to allow
greeting fields to be set to null per CRM-21474

m
When a field is not required in the database the 'null' should be pass through the pseudoconstant validation.

Note the unit test on this is failing because the BAO is not respecting setting null. Follow up patch
@eileenmcnaughton eileenmcnaughton changed the title Ps1 CRM-21180: Inline changes to custom fields aren't reflected in custom greetings + CRM-21474 add support for setting non-required fields to 'null' Dec 4, 2017
The pseudoConstant was against the wrong field
@eileenmcnaughton
Copy link
Contributor Author

@twomice see what you think of this - incorporates your changes plus the related one I was working on

@twomice
Copy link
Contributor

twomice commented Dec 4, 2017

This is great @eileenmcnaughton The code generally makes sense -- especially CRM_Contact_BAO_Contact_Utils::getTokensRequiredForContactGreetings() and CRM_Contact_BAO_Contact::updateGreetingsOnTokenFieldChange(). I tested locally and confirm this code solves the problem described in the JIRA ticket.

@eileenmcnaughton
Copy link
Contributor Author

@twomice I am hoping to make those used more broadly to reduce lookup. @colemanw are you OK to merge this - will replace #11095

@@ -1069,6 +1069,10 @@ static function &fields() {
'entity' => 'Contact',
'bao' => 'CRM_Contact_BAO_Contact',
'localizable' => 0,
'pseudoconstant' => array(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pseudoconstant was against the wrong field!

@colemanw colemanw merged commit d08c994 into civicrm:master Dec 4, 2017
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21180: Inline changes to custom fields aren't reflected in custom greetings + CRM-21474 add support for setting non-required fields to 'null'
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.

4 participants