Show error messages for missing configuration values

This commit is contained in:
Jens Schuppe 2024-04-05 14:29:56 +02:00
parent a91fbd0c20
commit 313d2f648f
2 changed files with 106 additions and 32 deletions

View file

@ -562,10 +562,26 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
foreach ($profile_data as $element_name => $value) {
$defaults[$element_name] = $value;
}
// backwards compatibility, see issue #27
if (!isset($profile_data['campaign_targets'])) {
$defaults['campaign_targets'] = ['contribution', 'contact'];
}
// Show warning when there is configuration missing for required fields.
$requiredConfig = CRM_Twingle_Profile::allowedAttributes(TRUE);
foreach ($requiredConfig as $key => $metadata) {
if (!isset($profile_data[$key]) && $metadata['required']) {
CRM_Core_Session::setStatus(
E::ts(
'The required configuration option "%1" has no value. Saving the profile might set this option to a possibly unwanted default value.',
[1 => $metadata['label'] ?? $key]
),
E::ts('Error'),
'error'
);
}
}
}
return $defaults;
}