Countable error when creating a membership batch (if org ID is not 1)
Overview
When a client creates a batch to add memberships, they get this error:
Warning: Undefined array key 1 in CRM_Core_BAO_UFGroup::buildProfile() (line 1934 of /app/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php). TypeError: count(): Argument #1 (closed) ($value) must be of type Countable|array, null given in CRM_Core_BAO_UFGroup::buildProfile() (line 1934 of /app/sites/all/modules/civicrm/CRM/Core/BAO/UFGroup.php).
The relevant code:
if (isset($types[1]) && count($types[1]) > 1) {
$types[1] = $select + $types[1];
}
They're on CiviCRM 5.59.1 with PHP 8+.
It's checking for membership types that are related to an organization contact but only if the contact ID is 1. If contact ID is not 1 then it's trying to count on an empty array. We can either check if it's an array before counting or maybe make it smarter: check for membership types regardless of contact ID.