Merge branch 'impove_default_profile_behaviour'

This commit is contained in:
Jens Schuppe 2024-04-05 13:27:34 +02:00
commit b480d87ed7
4 changed files with 31 additions and 24 deletions

View file

@ -600,25 +600,28 @@ class CRM_Twingle_Profile {
* @param string $project_id
*
* @return CRM_Twingle_Profile
* @throws \CRM_Twingle_Exceptions_ProfileException
* @throws \Civi\Core\Exception\DBQueryException
*/
public static function getProfileForProject($project_id) {
$profiles = self::getProfiles();
$default_profile = NULL;
foreach ($profiles as $profile) {
if ($profile->matches($project_id)) {
return $profile;
}
if ($profile->is_default()) {
$default_profile = $profile;
}
}
// If none matches, use the default profile.
if (isset($profiles['default'])) {
return $profiles['default'];
if (!empty($default_profile)) {
return $default_profile;
}
else {
throw new ProfileException(
'Could not find default profile',
ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND
);
throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND);
}
}