Skip to content

Fix editing custom fields on certain CiviCRM versions

omar_compucorp requested to merge omar_compucorp/civirules:customedit into master

On CiviCRM 5.51.3 (haven't tested it on other CiviCRM versions, but it does not seem to affect 5.72.alpha1 version), If you add a custom group and fields set without clearing the site cache, and then you tried to edit any of the cuustom fields, the following error is thrown:

|php|http://localhost/civicrm/contact/view?reset=1&cid=248|1||TypeError: civicrm_api3(): Argument #1 (closed) ($entity) must be of type string, null given, called in /var/www/default/htdocs/httpdocs/sites/all/modules/contrib/civicrm/ext/civirules/CRM/Civirules/Utils/PreData.php on line 115 in civicrm_api3()).

This error goes away if you clear CiviCRM cache, and it seems to happen because Civirules caches the list of custom group, which is later used in getCustomGroupById() method to retrieve any custom group, but any newly added custom field will not be added to the cache yet unless you clear the cache, which results in the above error.

What I did here is just adding a safeguard that tries to retrieve the custom group using API if it is not already available in the cache, thus users can still edit custom fields even if they forgot to clear the cache.

Merge request reports

Loading