-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharer_toolbar.forms.inc
More file actions
120 lines (98 loc) · 3.92 KB
/
sharer_toolbar.forms.inc
File metadata and controls
120 lines (98 loc) · 3.92 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @file sharer_toolbar.forms.inc
* Forms configuration
*/
/**
* Sharer toolbar configuration form.
*/
function sharer_toolbar_config_form($form, &$form_state) {
module_load_include('inc', 'sharer_toolbar');
// Sharer toolbar title
$form['sharer_toolbar_title'] = array(
'#type' => 'textfield',
'#title' => t('Sharer toolbar title'),
'#description' => t('Set this value in english, and translate it using !link.', array('!link' => l(t('translatable strings'), 'admin/config/regional/translate/translate'))),
'#default_value' => variable_get('sharer_toolbar_title', 'Share'),
);
// Make sharers sortable
$form['sharers']['#tree'] = TRUE;
// List all available sharers
$sharers = _sharer_toolbar_get_ordered_available_sharers();
$sharers_configuration = variable_get('sharer_toolbar_sharers_configuration', array());
foreach ($sharers as $delta => $sharer) {
$sid = $sharer['sid'];
$sharer_conf = (isset($sharers_configuration[$sid])) ? $sharers_configuration[$sid] : array();
// Checkbox to activate or not sharer.
$form['sharers'][$sid]['status'] = array(
'#type' => 'checkbox',
'#default_value' => (isset($sharer_conf['status'])) ? $sharer_conf['status'] : 0,
);
// Textfield to hold sharer name.
$form['sharers'][$sid]['name'] = array(
'#type' => 'textfield',
'#default_value' => (isset($sharer_conf['name'])) ? $sharer_conf['name'] : $sharer['name'],
);
// Textfield to hold sharer icon class.
$icon_value = (isset($sharer_conf['icon_class'])) ? $sharer_conf['icon_class'] : $sharer['icon_class'];
$form['sharers'][$sid]['icon_class'] = array(
'#type' => 'textfield',
'#default_value' => $icon_value,
'#field_prefix' => '<i class="' . $icon_value . '"></i>',
);
// Textfield to hold sharer label.
$form['sharers'][$sid]['label'] = array(
'#type' => 'textfield',
'#default_value' => (isset($sharer_conf['label'])) ? $sharer_conf['label'] : $sharer['label'],
);
// Invisible field, but contains sort info (weights).
$form['sharers'][$sid]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#title_display' => 'invisible',
'#default_value' => $delta,
);
}
// Submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Sharer toolbar configuration form submit.
*/
function sharer_toolbar_config_form_submit($form, &$form_state) {
$sharers_order = array();
$sharers_configuration = array();
// Save sharer toolbar title
variable_set('sharer_toolbar_title', $form_state['values']['sharer_toolbar_title']);
// Get available sharers and submitted values to compare them
$available_sharers = _sharer_toolbar_get_available_sharers();
$submitted_sharers = $form_state['values']['sharers'];
// Iterate on orders to store informations
foreach ($submitted_sharers as $sid => $submitted_sharer) {
// Store weight
$sharers_order[$submitted_sharer['weight']] = $sid;
// Store status
$sharers_configuration[$sid] = array(
'status' => $submitted_sharer['status'],
);
// And store configuration if different from default
if ($submitted_sharer['name'] != $available_sharers[$sid]['name']) {
$sharers_configuration[$sid]['name'] = $submitted_sharer['name'];
}
if ($submitted_sharer['icon_class'] != $available_sharers[$sid]['icon_class']) {
$sharers_configuration[$sid]['icon_class'] = $submitted_sharer['icon_class'];
}
if ($submitted_sharer['label'] != $available_sharers[$sid]['label']) {
$sharers_configuration[$sid]['label'] = $submitted_sharer['label'];
}
}
// Save values
variable_set('sharer_toolbar_sharers_order', $sharers_order);
variable_set('sharer_toolbar_sharers_configuration', $sharers_configuration);
// Confirmation
drupal_set_message(t('Sharer toolbar configuration has been saved.'));
}