[#4] (wip) Process custom fields parameter
This commit is contained in:
parent
4537ac540a
commit
73481fb7ed
3 changed files with 78 additions and 0 deletions
|
@ -69,6 +69,20 @@ class CRM_Twingle_Profile {
|
|||
return in_array($project_id, $project_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* The profile's configured custom field mapping
|
||||
*/
|
||||
public function getCustomFieldMapping() {
|
||||
$custom_field_mapping = array();
|
||||
if (!empty($custom_field_definition = $this->getAttribute('custom_field_mapping'))) {
|
||||
foreach (preg_split('/\r\n|\r|\n/', $custom_field_definition, -1, PREG_SPLIT_NO_EMPTY) as $twingle_field_name => $custom_field_name) {
|
||||
$custom_field_mapping[$twingle_field_name] = $custom_field_name;
|
||||
}
|
||||
}
|
||||
return $custom_field_mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all data attributes of the profile.
|
||||
*
|
||||
|
@ -191,6 +205,7 @@ class CRM_Twingle_Profile {
|
|||
'donation_receipt_groups',
|
||||
'campaign',
|
||||
'contribution_source',
|
||||
'custom_field_mapping',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -250,6 +265,7 @@ class CRM_Twingle_Profile {
|
|||
'donation_receipt_groups' => NULL,
|
||||
'campaign' => NULL,
|
||||
'contribution_source' => NULL,
|
||||
'custom_field_mapping' => NULL,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,16 @@ class CRM_Twingle_Submission {
|
|||
}
|
||||
$params['gender_id'] = $gender_id;
|
||||
}
|
||||
|
||||
// Validate custom fields parameter, if given.
|
||||
if (!empty($params['custom_fields'])) {
|
||||
if (!is_array($custom_fields = json_decode($params['custom_fields'], TRUE))) {
|
||||
throw new CiviCRM_API3_Exception(
|
||||
E::ts('Invalid format for custom fields.'),
|
||||
'invalid_format'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue