Merge branch 'dev' into main
This commit is contained in:
commit
841028a435
4 changed files with 50 additions and 20 deletions
|
@ -205,15 +205,40 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
|
||||
try {
|
||||
foreach ($options as $key => $value) {
|
||||
$result[] = civicrm_api3(
|
||||
|
||||
$option_value_exists = civicrm_api3(
|
||||
'OptionValue',
|
||||
'create',
|
||||
'get',
|
||||
[
|
||||
'sequential' => 1,
|
||||
'option_group_id' => $option_group_id,
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
]
|
||||
);
|
||||
|
||||
// If the option value does not yet exist, create it
|
||||
if ($option_value_exists['count'] == 0) {
|
||||
$result[] = civicrm_api3(
|
||||
'OptionValue',
|
||||
'create',
|
||||
[
|
||||
'option_group_id' => $option_group_id,
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
]
|
||||
);
|
||||
}
|
||||
// If the option value already exist, update it
|
||||
else {
|
||||
$result[] = civicrm_api3(
|
||||
'OptionValue',
|
||||
'create',
|
||||
[
|
||||
'id' => $option_value_exists['values'][0]['id'],
|
||||
'label' => $value,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (CiviCRM_API3_Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
|
|
|
@ -158,7 +158,7 @@ class CRM_TwingleCampaign_BAO_OptionValue {
|
|||
// If a specific option value is required
|
||||
try {
|
||||
$option_value = civicrm_api3(
|
||||
'CustomValue',
|
||||
'OptionValue',
|
||||
'get',
|
||||
[
|
||||
'sequential' => 1,
|
||||
|
|
|
@ -31,6 +31,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
|||
'one_time',
|
||||
];
|
||||
|
||||
// All fields for hex color codes
|
||||
const colorFields = [
|
||||
'design_background_color',
|
||||
'design_primary_color',
|
||||
'design_font_color',
|
||||
];
|
||||
|
||||
/**
|
||||
* ## TwingleProject constructor
|
||||
*
|
||||
|
@ -143,11 +150,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
|||
*/
|
||||
private function strToInt(array &$values) {
|
||||
foreach ($values as $key => $value) {
|
||||
if (ctype_digit($value)) {
|
||||
$values[$key] = intval($value);
|
||||
}
|
||||
elseif (is_array($value)) {
|
||||
$this->strToInt($values[$key]);
|
||||
if (!in_array($key, self::colorFields)) {
|
||||
if (ctype_digit($value)) {
|
||||
$values[$key] = intval($value);
|
||||
}
|
||||
elseif (is_array($value)) {
|
||||
$this->strToInt($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,21 +307,18 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
|||
}
|
||||
|
||||
// Validate hexadecimal color fields
|
||||
$colorFields =
|
||||
[
|
||||
'design_background_color',
|
||||
'design_primary_color',
|
||||
'design_font_color',
|
||||
];
|
||||
foreach ($colorFields as $colorField) {
|
||||
foreach (self::colorFields as $colorField) {
|
||||
if (
|
||||
!empty($this->values['project_options'][$colorField]) &&
|
||||
(
|
||||
!empty($this->values['project_options'][$colorField]) ||
|
||||
$this->values['project_options'][$colorField] === "0"
|
||||
) &&
|
||||
(
|
||||
!(
|
||||
ctype_xdigit($this->values['project_options'][$colorField]) ||
|
||||
is_integer($this->values['project_options'][$colorField])
|
||||
) ||
|
||||
strlen((string) $this->values['project_options'][$colorField]) > 6
|
||||
strlen((string) $this->values['project_options'][$colorField]) != 6
|
||||
)
|
||||
) {
|
||||
$valid = FALSE;
|
||||
|
|
|
@ -411,8 +411,7 @@ function _validateAndSendInput($id, $campaign_type_id): bool {
|
|||
CRM_Core_Session::setStatus(
|
||||
$errorMessage,
|
||||
E::ts("Input validation failed"),
|
||||
error,
|
||||
[unique => TRUE]
|
||||
error
|
||||
);
|
||||
// Validation failed
|
||||
return FALSE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue