1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* token insert module.
|
5 |
|
|
*/
|
6 |
|
|
function token_insert_text_element_info_alter(&$types) {
|
7 |
|
|
if (user_access('use token insert')) {
|
8 |
|
|
$types['textarea']['#post_render'][] = 'token_insert_text_post_render';
|
9 |
|
|
$types['textfield']['#post_render'][] = 'token_insert_text_post_render';
|
10 |
|
|
}
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
function token_insert_text_form_alter(&$form, &$form_state, $form_id) {
|
15 |
|
|
if ($form_id == 'field_ui_field_edit_form' && user_access('administer token insert settings')) {
|
16 |
|
|
$entity = $form['#instance']['entity_type'];
|
17 |
|
|
$bundle = $form['#instance']['bundle'];
|
18 |
|
|
$field = $form['#instance']['field_name'];
|
19 |
|
|
$form['token_insert'] = array(
|
20 |
|
|
'#title' => t('Token Insert'),
|
21 |
|
|
'#type' => 'fieldset',
|
22 |
|
|
'#collapsible' => FALSE,
|
23 |
|
|
);
|
24 |
|
|
|
25 |
|
|
$form['token_insert']['use_for_token_insert'] = array(
|
26 |
|
|
'#type' => 'checkbox',
|
27 |
|
|
'#title' => t('Use Token Insert for this field'),
|
28 |
|
|
//variable_get('token_insert_content_type_*typename*_*fieldname*, 0)
|
29 |
|
|
'#default_value' => variable_get('token_insert_' . $entity . '_' . $bundle . '_' . $field, 0),
|
30 |
|
|
'#description' => t('If selected Token Insert will be available for this field'),
|
31 |
|
|
);
|
32 |
|
|
|
33 |
|
|
$form['#submit'][] = 'token_insert_text_add_bundle';
|
34 |
|
|
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
function token_insert_text_add_bundle($form, &$form_state) {
|
39 |
|
|
$entity = $form['#instance']['entity_type'];
|
40 |
|
|
$bundle = $form['#instance']['bundle'];
|
41 |
|
|
$field = $form['#instance']['field_name'];
|
42 |
|
|
variable_set('token_insert_' . $entity . '_' . $bundle . '_' . $field, $form_state['values']['use_for_token_insert']);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
function token_insert_text_post_render($content, $element) {
|
46 |
|
|
if (isset($element['#entity_type']) && isset($element['#bundle'])) {
|
47 |
|
|
if (variable_get('token_insert_' . $element['#entity_type'] . '_' . $element['#bundle'] . '_' . $element['#field_name'], 0) == 1) {
|
48 |
|
|
$content = _token_insert_add_token_insert($content, $element);
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
if (isset($element['#token_insert']) && $element['#token_insert']) {
|
52 |
|
|
$content = _token_insert_add_token_insert($content, $element);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
return $content;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
function _token_insert_add_token_insert($content, $element) {
|
59 |
5721e759
|
Assos Assos
|
$contentarray = token_insert_text_table($element);
|
60 |
|
|
$content .= drupal_render($contentarray);
|
61 |
85ad3d82
|
Assos Assos
|
return $content;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
5721e759
|
Assos Assos
|
function token_insert_text_table($element) {
|
65 |
85ad3d82
|
Assos Assos
|
$form = array();
|
66 |
|
|
if (isset($element['#title'])) {
|
67 |
5721e759
|
Assos Assos
|
$name = md5(print_r($element, TRUE));
|
68 |
|
|
$table_id = drupal_html_id("token-insert-text-table-$name");
|
69 |
|
|
$name = md5(print_r($element, TRUE));
|
70 |
|
|
$settings = array(
|
71 |
|
|
'token_insert' => array(
|
72 |
|
|
'tables' => array(
|
73 |
|
|
$table_id => $element['#id'],
|
74 |
|
|
),
|
75 |
85ad3d82
|
Assos Assos
|
),
|
76 |
|
|
);
|
77 |
5721e759
|
Assos Assos
|
$form['token_insert_text_table_wrapper'] = array(
|
78 |
|
|
'#type' => 'container',
|
79 |
85ad3d82
|
Assos Assos
|
'#attributes' => array(
|
80 |
5721e759
|
Assos Assos
|
'id' => $table_id,
|
81 |
|
|
'class' => array('token-insert-text-table'),
|
82 |
85ad3d82
|
Assos Assos
|
),
|
83 |
5721e759
|
Assos Assos
|
'#attached' => array(
|
84 |
|
|
'js' => array(
|
85 |
|
|
array(
|
86 |
|
|
'data' => $settings,
|
87 |
|
|
'type' => 'setting',
|
88 |
|
|
),
|
89 |
|
|
array(
|
90 |
|
|
'data' => drupal_get_path('module', 'token_insert') . '/token_insert.js',
|
91 |
|
|
),
|
92 |
|
|
array(
|
93 |
|
|
'data' => drupal_get_path('module', 'token_insert_text') . '/token_insert_text.js',
|
94 |
|
|
)
|
95 |
|
|
),
|
96 |
|
|
),
|
97 |
|
|
);
|
98 |
|
|
$form['token_insert_text_table_wrapper']['token_insert_text_table'] = array(
|
99 |
|
|
'#theme' => 'token_insert_tree',
|
100 |
85ad3d82
|
Assos Assos
|
);
|
101 |
|
|
}
|
102 |
|
|
return $form;
|
103 |
|
|
|
104 |
|
|
} |