private function AdminForm::buildGrantTab in Webform CiviCRM Integration 8.5
Grant settings FIXME: This is nearly the same code as buildCaseTab. More utilities and less boilerplate needed.
1 call to AdminForm::buildGrantTab()
- AdminForm::buildForm in src/
AdminForm.php - Build admin form for civicrm tab of a webform
File
- src/
AdminForm.php, line 1270 - Webform CiviCRM module's admin form.
Class
- AdminForm
- @file Webform CiviCRM module's admin form.
Namespace
Drupal\webform_civicrmCode
private function buildGrantTab() {
$utils = \Drupal::service('webform_civicrm.utils');
$types = $utils
->wf_crm_apivalues('grant', 'getoptions', [
'field' => 'grant_type_id',
]);
if (!$types) {
return;
}
$this->form['grantTab'] = [
'#type' => 'details',
'#title' => t('Grants'),
'#group' => 'webform_civicrm',
'#attributes' => [
'class' => [
'civi-icon-grant',
],
],
];
$this->form['grantTab']["grant_number_of_grant"] = [
'#type' => 'select',
'#title' => t('Number of Grants'),
'#default_value' => $num = wf_crm_aval($this->data, "grant:number_of_grant", 0),
'#options' => range(0, $this->sets['grant']['max_instances']),
'#prefix' => '<div class="number-of">',
'#suffix' => '</div>',
];
$this
->addAjaxItem("grantTab", "grant_number_of_grant", "grant");
for ($n = 1; $n <= $num; ++$n) {
$fs = "grant_grant_{$n}_fieldset";
$this->form['grantTab']['grant'][$fs] = [
'#type' => 'fieldset',
'#title' => t('Grant :num', [
':num' => $n,
]),
'wrap' => [
'#weight' => 9,
],
];
$this->form['grantTab']['grant'][$fs]["grant_{$n}_settings_existing_grant_status"] = [
'#type' => 'select',
'#title' => t('Update Existing Grant'),
'#options' => [
'' => '- ' . t('None') . ' -',
] + $utils
->wf_crm_apivalues('grant', 'getoptions', [
'field' => 'status_id',
]),
'#default_value' => wf_crm_aval($this->data, "grant:{$n}:existing_grant_status", []),
'#multiple' => TRUE,
];
$this
->help($this->form['grantTab']['grant'][$fs]["grant_{$n}_settings_existing_grant_status"], 'existing_grant_status');
$grant_type = wf_crm_aval($this->data, "grant:{$n}:grant:1:grant_type_id");
foreach ($this->sets as $sid => $set) {
if ($set['entity_type'] == 'grant' && (!$grant_type || empty($set['sub_types']) || in_array($grant_type, $set['sub_types']))) {
$fs1 = "grant_grant_{$n}_fieldset_{$sid}";
if ($sid == 'grant') {
$pos =& $this->form['grantTab']['grant'][$fs];
}
else {
$pos =& $this->form['grantTab']['grant'][$fs]['wrap'];
}
$pos[$fs1] = [
'#type' => 'fieldset',
'#title' => $set['label'],
'#attributes' => [
'id' => $fs1,
'class' => [
'web-civi-checkbox-set',
],
],
'js_select' => $this
->addToggle($fs1),
];
$this
->addDynamicCustomSetting($pos[$fs1], $sid, 'grant', $n);
if (isset($set['fields'])) {
foreach ($set['fields'] as $fid => $field) {
$fid = "civicrm_{$n}_grant_1_{$fid}";
$pos[$fs1][$fid] = $this
->addItem($fid, $field);
}
}
}
}
$this
->addAjaxItem("grantTab:grant:{$fs}:grant_grant_{$n}_fieldset_grant", "civicrm_{$n}_grant_1_grant_grant_type_id", "..:wrap");
}
}