-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathting_token.module
More file actions
executable file
·198 lines (185 loc) · 5.7 KB
/
ting_token.module
File metadata and controls
executable file
·198 lines (185 loc) · 5.7 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
function ting_token_preprocess_page(&$variables) {
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'drupal.form');
drupal_add_library('system', 'jquery.form');
drupal_add_library('system', 'druapl.progress');
drupal_add_library('system', 'drupal.textarea');
drupal_add_js(
array('ting_token' => array('viewMode' => variable_get('ting_token_view_mode', 'teaser'))),
'setting'
);
}
/**
* implements hook_wysiwyg_include_directory
*/
function ting_token_wysiwyg_include_directory($type) {
return $type;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function ting_token_form_ting_admin_ting_settings_alter(&$form, &$form_state, $form_id) {
$form['ting_token'] = array(
'#type' => 'fieldset',
'#title' => t('Ting token settings'),
'#tree' => FALSE,
);
$tingObj = entity_get_info('ting_object');
$options = array();
foreach($tingObj['view modes'] as $key => $value) {
$options[$key] = $value['label'];
}
$form['ting_token']['ting_token_view_mode'] = array(
'#type' => 'select',
'#title' => t('Ting token view mode'),
'#description' => t('Select the view mode tokens should display with.'),
'#options' => $options,
'#default_value' => variable_get('ting_token_view_mode', 'teaser'),
);
}
/**
* implements hook_menu
*/
function ting_token_menu() {
$items = array();
$items['ting_token/insert/nojs'] = array(
'page callback' => 'ting_token_get_insert_form',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ting_token/insert/ajax'] = array(
'delivery callback' => 'ajax_deliver'
) + $items['ting_token/insert/nojs'];
$items['ting_token/insert/nojs/%'] = array(
'page callback' => 'ting_token_get_insert_form',
'page arguments' => array(2, 3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ting_token/insert/ajax/%'] = array(
'delivery callback' => 'ajax_deliver'
) + $items['ting_token/insert/nojs/%'];
return $items;
}
/**
* Retrive the insert form.
*/
function ting_token_get_insert_form($ajax, $ids = '') {
$is_ajax = $ajax === 'ajax';
$form = drupal_get_form('ting_token_insert_form', $ids);
if ($is_ajax) {
$form = drupal_render($form);
// Generate the settings:
$settings = '';
$javascript = drupal_add_js();
if(isset($javascript['settings'], $javascript['settings']['data'])) {
$settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, ';
$settings .= drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data']));
$settings .= ');</script>';
}
die($form . $settings);
}
else {
return $form;
}
}
/**
* Insert token form
*/
function ting_token_insert_form($form, &$form_state) {
drupal_add_library('system', 'ui.dialog');
$form['#tree'] = TRUE;
if (empty($form_state['num_objects'])) {
$form_state['num_objects'] = 1;
}
$ids = null;
$args = $form_state['build_info']['args'];
if(isset($args[0])) {
$ids = explode(',', $args[0]);
if($form_state['num_objects'] == 1) {
$form_state['num_objects'] = count($ids);
}
}
$form['objects'] = array(
'#type' => 'fieldset',
'#title' => t('Ting objects'),
'#prefix' => '<div id="ting-token-fieldset-wrapper">',
'#suffix' => '</div>',
);
for($i = 0; $i < $form_state['num_objects']; $i++) {
$form['objects'][$i]['ting_object'] = array(
'#type' => 'textfield',
'#title' => t('Ting id'),
'#prefix' => '<div class="col1">',
'#suffix' => '</div>',
'#default_value' => isset($form_state['values'][$i]) ? $form_state['values'][$i]['ting_object'] : '',
);
if(isset($ids[$i])) {
$form['objects'][$i]['ting_object']['#default_value'] = $ids[$i];
}
}
$form['objects']['add_item'] = array(
'#type' => 'submit',
'#value' => t('Add another'),
'#submit' => array('ting_token_add_more_add_one'),
// See the examples in ajax_example.module for more details on the
// properties of #ajax.
'#ajax' => array(
'callback' => 'ting_token_add_more_callback',
'wrapper' => 'ting-token-fieldset-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
if ($form_state['num_objects'] > 1) {
$form['objects']['remove_item'] = array(
'#type' => 'submit',
'#value' => t('Remove one'),
'#submit' => array('ting_token_add_more_remove_one'),
'#ajax' => array(
'callback' => 'ting_token_add_more_callback',
'wrapper' => 'ting-token-fieldset-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#attributes' => array(
'class' => array('form-save-ids'),
),
);
return $form;
}
/**
* Callback for both ajax-enabled buttons.
*
* Selects and returns the fieldset with the names in it.
*/
function ting_token_add_more_callback($form, $form_state) {
return $form['objects'];
}
/**
* Submit handler for the "add-one-more" button.
*
* Increments the max counter and causes a rebuild.
*/
function ting_token_add_more_add_one($form, &$form_state) {
$form_state['num_objects']++;
$form_state['rebuild'] = TRUE;
}
/**
* Submit handler for the "remove one" button.
*
* Decrements the max counter and causes a form rebuild.
*/
function ting_token_add_more_remove_one($form, &$form_state) {
if ($form_state['num_objects'] > 1) {
$form_state['num_objects']--;
}
$form_state['rebuild'] = TRUE;
}