-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcivicrm_entity.admin_form.inc
92 lines (79 loc) · 2.97 KB
/
civicrm_entity.admin_form.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @file
* CiviCRM Entity admin settings form callbacks
*/
/**
* Settings form callback function
*
* @param $form
* @param $form_state
* @return mixed
*/
function civicrm_entity_admin_settings_form($form, &$form_state) {
$available_entities = _civicrm_entity_available_entities();
$config = config('civicrm_entity.settings');
$options = array();
foreach ($available_entities as $entity_type => $api_entity) {
$options[$entity_type] = ucwords(str_replace('_', ' ', $api_entity));
}
$default_value = $config->get('admin_enabled_entities');
$form['random_options'] = [
'#type' => 'fieldset',
'#title' => 'Options',
'#description' => 'Various uncategorized options.',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$contact_label = $config->get('contact_label_format');
$form['random_options']['contact_label'] = [
'#type' => 'select',
'#title' => 'Contact Entity Label',
'#description' => 'Select formatting for the civicrm_contact entity label. Legacy, is the default logic before addition of this setting.',
'#options' => [
'legacy' => 'Legacy',
'display_name' => 'Display Name only',
'display_name_email' => 'Display Name + email',
'display_name_phone' => 'Display Name + phone',
'display_name_im' => 'Display Name + IM',
],
'#default_value' => $contact_label,
];
$form['civicrm_entity_admin_enabled_entities'] = array(
'#type' => 'fieldset',
'#title' => 'Enabled Entities',
'#description' => 'Check all CiviCRM API entities that you would like to expose as Drupal entity types. If a checkbox is disabled, it is because a submodule requires it.' . "<br/>" .' This page does not check for existing Drupal Rules, Views, or 3rd party modules using CiviCRM entity types. Ask your web consultant if unsure.',
'#collapsible' => FALSE,
'#tree' => TRUE,
);
foreach ($options as $backdrop_entity_type => $entity_type_label) {
$form['civicrm_entity_admin_enabled_entities'][$backdrop_entity_type] = array(
'#type' => 'checkbox',
'#title' => $entity_type_label,
'#default_value' => !empty($default_value[$backdrop_entity_type]) ? 1 : 0,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
);
return $form;
}
/**
* Form submit callback for the CiviCRM Entity admin config page
*
* @param $form
* @param $form_state
*/
function civicrm_entity_admin_settings_form_submit($form, $form_state) {
$config = config('civicrm_entity.settings');
// Clear caches at start, to prevent them corrupting by the changes
backdrop_flush_all_caches();
$settings = array();
foreach ($form_state['values']['civicrm_entity_admin_enabled_entities'] as $backdrop_entity_type => $value) {
$settings[$backdrop_entity_type] = !empty($value) ? $backdrop_entity_type : 0;
}
$config->set('contact_label_format', $form_state['values']['contact_label']);
$config->set('admin_enabled_entities', $settings);
$config->save();
}