Fix api handling of OptionValue defaults
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 8 Nov 2022 23:41:34 +0000 (12:41 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 9 Nov 2022 23:04:33 +0000 (12:04 +1300)
commit1ce347af618fd015bc1e5cbe76afe718b2a430f3
treee2b22d3cc1c0756ce5f62ddbab19cbdbe429e324
parentb664cdddf218e9d3e391a49571af3f155460c23e
Fix api handling of OptionValue defaults

Overview
----------------------------------------
Fix api handling of OptionValue defaults

Before
----------------------------------------
Some option values (greetings, from_email_address) have
more than one default. For from_email_address it is per domain
and for the others it is per 'filter' (aka contact_type).

The special handling for greetings relies on the form layer - updating
a greeting for 'Individual' and passing 'is_default' will
unset 'is_default' for Household greetings.

For from_email_address the form layer magic-param is set but ultimately
has no bearing as there is duplicate handling in the bao layer

After
----------------------------------------
The default handling is done in the BAO layer & removed from the
form layer

Technical Details
----------------------------------------
I moved the handling to after-update because values are more guarantee there. I
did this by excluding the id from the update query (also prevents flappy updates).
I didn't move all the way to the post hook because I wasn't sure about the interaction
with cache flushing etc (that already happen after save in create) but that could be considered.
CRM/Admin/Form/Options.php
CRM/Core/BAO/OptionValue.php
tests/phpunit/CRM/Core/BAO/OptionValueTest.php