public static function AdminForm::addFieldset in Webform CiviCRM Integration 8.5
Create a fieldset around an entity if it doesn't already exist
Parameters
int $c:
array $field:
array $enabled:
array $settings:
string $ent:
bool $allow_create:
1 call to AdminForm::addFieldset()
- AdminForm::insertComponent in src/
AdminForm.php - Add a CiviCRM field to a webform
File
- src/
AdminForm.php, line 2314 - Webform CiviCRM module's admin form.
Class
- AdminForm
- @file Webform CiviCRM module's admin form.
Namespace
Drupal\webform_civicrmCode
public static function addFieldset($c, &$field, &$enabled, $settings, $ent = 'contact', $allow_create = FALSE) {
$utils = \Drupal::service('webform_civicrm.utils');
$type = in_array($ent, self::$fieldset_entities, TRUE) ? $ent : 'contact';
// Custom fields are placed in fieldsets by group (for contact fields only)
if ($type === 'contact' && strpos($field['form_key'], '_custom_') !== FALSE) {
$sid = explode('_custom', $field['form_key']);
$sid = $sid[0] . '_fieldset';
$customGroupKey = explode('_', $field['form_key'])[4];
$allow_create = $isCustom = TRUE;
}
else {
$sid = "civicrm_{$c}_{$type}_1_fieldset_fieldset";
}
if ($allow_create && !empty($settings['create_fieldsets']) && !isset($enabled[$sid])) {
$new_set = [
// There is no nid.
// 'nid' => $field['nid'],
'form_key' => $sid,
'type' => 'fieldset',
];
$sets = $utils
->wf_crm_get_fields('sets');
if ($type == 'billing_1_number_of_billing') {
$new_set['parent'] = 'contribution_pagebreak';
}
if (isset($isCustom, $customGroupKey)) {
$new_set['title'] = $sets[$customGroupKey]['label'];
// @todo We cannot define a default weight.
// $new_set['weight'] = 200 + (array_search($type, self::$fieldset_entities, TRUE) * 10 + $c);
}
elseif ($type === 'contact') {
$new_set['title'] = $utils
->wf_crm_contact_label($c, $settings['data']);
}
else {
$new_set['title'] = $sets[$type]['label'] . ($c > 1 ? " {$c}" : '');
// @todo We cannot define a default weight.
// $new_set['weight'] = 200 + (array_search($type, self::$fieldset_entities, TRUE) * 10 + $c);
}
$webform_element_manager = \Drupal::getContainer()
->get('plugin.manager.webform.element');
$element_plugin = $webform_element_manager
->getElementInstance([
'#type' => $new_set['type'],
]);
$new_set = array_merge($element_plugin
->getDefaultProperties(), $new_set);
$enabled[$sid] = $new_set;
}
return $sid;
}