Custom field values not updating with APIv4 update action on Mailing entities
Overview
When adding Mailing entities to the cg_extend_objects
option group for them to be extendable with custom fields, those custom fields will not be updated with \Civi\Api4\Mailing::update()
, whereas with APIv3 this was working.
Reproduction steps
-
civicrm_api3('OptionValue', 'create', array( 'option_group_id' => 'cg_extend_objects', 'label' => 'Mailing', 'value' => 'Mailing', 'name' => 'civicrm_mailing', 'is_reserved' => 1, ));
- Add a custom field to the Mailing entity (ex.
custom_group.custom_field
,custom_789
) - Create a mailing (ex. ID
123
) -
Mailing::update(FALSE) ->addWhere('id', '=', 123) ->addValue('custom_group.custom_field', 456) ->execute();
Current behaviour
The custom field is not being updated to the value 456
.
If you do the same with
civicrm_api3('Mailing', 'create', array(
'id' => 123,
'custom_789' => 456,
));
the custom field will be updated to the value 456
.
Expected behaviour
The custom field should have been updated to the value 456
.
Environment information
A real-world scenario can be found in the de.systopia.mailboxmailing
extension which uses a custom field on Mailing entities for tracking whether bounce notifications have been sent, see here.
Comments
Of course, Mailing entities are not meant to be extended by custom fields in Core, but since the update
action is using generic code, I can't see why this shouldn't work. Also, as doing the same with APIv3 works, this could be considered a regression. Also, this might apply to other entities. I suspect it's about the entity BAO not reporting custom fields attached to it and thus the API not updating them.