function webform_civicrm_civicrm_pre in Webform CiviCRM Integration 8.5
Same name and namespace in other branches
- 7.5 webform_civicrm.module \webform_civicrm_civicrm_pre()
- 7.4 webform_civicrm.module \webform_civicrm_civicrm_pre()
Implementation of hook_civicrm_pre()
Handles enabling/disabling of custom fields
Parameters
string $op:
string $objectName:
integer $id:
array $params:
File
- ./
webform_civicrm.module, line 928 - Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts
Code
function webform_civicrm_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == 'edit' && $objectName == 'CustomField') {
// Run only if is_active is set, i.e. custom field is being enabled/disabled
if (isset($params['is_active'])) {
$statusToSet = $params['is_active'];
$queryParams = [
'sequential' => 1,
'return' => "custom_group_id, is_active",
'id' => $id,
'options' => [
'limit' => 1,
],
];
$result = civicrm_api3('CustomField', 'get', $queryParams);
// run only if this field already exist in db to make sure we donot run it for create op
if ($result['count'] == 1) {
$admin_form = \Drupal::service('webform_civicrm.admin_form');
$previousStatus = $result['values'][0]['is_active'];
$customGroupId = $result['values'][0]['custom_group_id'];
if ($statusToSet == FALSE && $previousStatus == TRUE) {
$opName = 'disable';
}
else {
$opName = 'enable';
}
if (isset($opName)) {
$admin_form::handleDynamicCustomField($opName, $id, $customGroupId);
}
}
}
}
}