Show error messages for missing configuration values
This commit is contained in:
parent
a91fbd0c20
commit
313d2f648f
2 changed files with 106 additions and 32 deletions
|
@ -562,10 +562,26 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
||||||
foreach ($profile_data as $element_name => $value) {
|
foreach ($profile_data as $element_name => $value) {
|
||||||
$defaults[$element_name] = $value;
|
$defaults[$element_name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// backwards compatibility, see issue #27
|
// backwards compatibility, see issue #27
|
||||||
if (!isset($profile_data['campaign_targets'])) {
|
if (!isset($profile_data['campaign_targets'])) {
|
||||||
$defaults['campaign_targets'] = ['contribution', 'contact'];
|
$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;
|
return $defaults;
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,45 +462,103 @@ class CRM_Twingle_Profile {
|
||||||
/**
|
/**
|
||||||
* Returns an array of attributes allowed for a profile.
|
* Returns an array of attributes allowed for a profile.
|
||||||
*
|
*
|
||||||
* @return array<string>
|
* @return array<string>|array<string, bool>
|
||||||
*/
|
*/
|
||||||
public static function allowedAttributes() {
|
public static function allowedAttributes(bool $asMetadata = FALSE) {
|
||||||
return array_merge(
|
$attributes = array_merge(
|
||||||
[
|
[
|
||||||
'selector',
|
'selector' => [
|
||||||
'xcm_profile',
|
'label' => E::ts('Project IDs'),
|
||||||
'location_type_id',
|
'required' => TRUE,
|
||||||
'location_type_id_organisation',
|
],
|
||||||
'financial_type_id',
|
'xcm_profile' => ['required' => FALSE],
|
||||||
'financial_type_id_recur',
|
'location_type_id' => [
|
||||||
'sepa_creditor_id',
|
'label' => E::ts('Location type'),
|
||||||
'gender_male',
|
'required' => TRUE,
|
||||||
'gender_female',
|
],
|
||||||
'gender_other',
|
'location_type_id_organisation' => [
|
||||||
'prefix_male',
|
'label' => E::ts('Location type for organisations'),
|
||||||
'prefix_female',
|
'required' => TRUE,
|
||||||
'prefix_other',
|
],
|
||||||
'newsletter_groups',
|
'financial_type_id' => [
|
||||||
'postinfo_groups',
|
'label' => E::ts('Financial type'),
|
||||||
'donation_receipt_groups',
|
'required' => TRUE,
|
||||||
'campaign',
|
],
|
||||||
'campaign_targets',
|
'financial_type_id_recur' => [
|
||||||
'contribution_source',
|
'label' => E::ts('Financial type (recurring)'),
|
||||||
'custom_field_mapping',
|
'required' => TRUE,
|
||||||
'membership_type_id',
|
],
|
||||||
'membership_type_id_recur',
|
'sepa_creditor_id' => [
|
||||||
'membership_postprocess_call',
|
'label' => E::ts('CiviSEPA creditor'),
|
||||||
'newsletter_double_opt_in',
|
'required' => CRM_Twingle_Submission::civiSepaEnabled(),
|
||||||
'required_address_components',
|
],
|
||||||
|
'gender_male' => [
|
||||||
|
'label' => E::ts('Gender option for submitted value "male"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'gender_female' => [
|
||||||
|
'label' => E::ts('Gender option for submitted value "female"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'gender_other' => [
|
||||||
|
'label' => E::ts('Gender option for submitted value "other"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'prefix_male' => [
|
||||||
|
'label' => E::ts('Prefix option for submitted value "male"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'prefix_female' => [
|
||||||
|
'label' => E::ts('Prefix option for submitted value "female"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'prefix_other' => [
|
||||||
|
'label' => E::ts('Prefix option for submitted value "other"'),
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
'newsletter_groups' => ['required' => FALSE],
|
||||||
|
'postinfo_groups' => ['required' => FALSE],
|
||||||
|
'donation_receipt_groups' => ['required' => FALSE],
|
||||||
|
'campaign' => ['required' => FALSE],
|
||||||
|
'campaign_targets' => ['required' => FALSE],
|
||||||
|
'contribution_source' => ['required' => FALSE],
|
||||||
|
'custom_field_mapping' => ['required' => FALSE],
|
||||||
|
'membership_type_id' => ['required' => FALSE],
|
||||||
|
'membership_type_id_recur' => ['required' => FALSE],
|
||||||
|
'membership_postprocess_call' => ['required' => FALSE],
|
||||||
|
'newsletter_double_opt_in' => ['required' => FALSE],
|
||||||
|
'required_address_components' => ['required' => FALSE],
|
||||||
],
|
],
|
||||||
// Add payment methods.
|
// Add payment methods.
|
||||||
|
array_combine(
|
||||||
array_keys(static::paymentInstruments()),
|
array_keys(static::paymentInstruments()),
|
||||||
|
array_map(
|
||||||
|
function ($value) {
|
||||||
|
return [
|
||||||
|
'label' => $value,
|
||||||
|
'required' => TRUE,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
static::paymentInstruments()
|
||||||
|
)),
|
||||||
|
|
||||||
// Add contribution status for all payment methods.
|
// Add contribution status for all payment methods.
|
||||||
|
array_combine(
|
||||||
array_map(function($attribute) {
|
array_map(function($attribute) {
|
||||||
return $attribute . '_status';
|
return $attribute . '_status';
|
||||||
}, array_keys(static::paymentInstruments()))
|
}, array_keys(static::paymentInstruments())),
|
||||||
|
array_map(
|
||||||
|
function($value) {
|
||||||
|
return [
|
||||||
|
'label' => $value . ' - ' . E::ts('Contribution Status'),
|
||||||
|
'required' => TRUE,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
static::paymentInstruments()
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return $asMetadata ? $attributes : array_keys($attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue