1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* This module provides CKEditor module support for token insert.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_menu().
|
10
|
*/
|
11
|
function token_insert_ckeditor_menu() {
|
12
|
$items = array();
|
13
|
$items['token_insert_ckeditor/insert/%'] = array(
|
14
|
'page callback' => '_token_insert_ckeditor_tokens_output',
|
15
|
'page arguments' => array(2),
|
16
|
'access arguments' => array('access content'),
|
17
|
'type' => MENU_CALLBACK,
|
18
|
'delivery callback' => 'ajax_deliver',
|
19
|
);
|
20
|
|
21
|
return $items;
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Implements hook_ckeditor_plugin().
|
26
|
*/
|
27
|
function token_insert_ckeditor_ckeditor_plugin() {
|
28
|
return array(
|
29
|
'token_insert_ckeditor' => array(
|
30
|
'name' => 'token_insert_ckeditor',
|
31
|
'desc' => t('Token insert'),
|
32
|
'path' => drupal_get_path('module', 'token_insert_ckeditor') . '/plugins/token_insert_ckeditor/',
|
33
|
'buttons' => array('TokenInsert' => array(
|
34
|
'icon' => 'images/insert.png',
|
35
|
'label' => 'Token insert',
|
36
|
)),
|
37
|
)
|
38
|
);
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Print out the tokens in a CKEditor-readable format.
|
43
|
*/
|
44
|
function _token_insert_ckeditor_tokens_output($id) {
|
45
|
$html = theme('token_insert_tree');
|
46
|
$commands = array();
|
47
|
$commands[] = array(
|
48
|
'command' => 'insert',
|
49
|
'method' => 'html',
|
50
|
'selector' => '#' . $id,
|
51
|
'data' => $html,
|
52
|
'settings' => NULL,
|
53
|
);
|
54
|
$commands[] = ajax_command_invoke('#' . $id, 'trigger', array('token-insert-table-loaded'));
|
55
|
return array('#type' => 'ajax', '#commands' => $commands);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Implements hook_element_info_alter().
|
60
|
*/
|
61
|
function token_insert_ckeditor_element_info_alter(&$types) {
|
62
|
$types['text_format']['#pre_render'][] = 'token_insert_ckeditor_pre_render_text_format';
|
63
|
}
|
64
|
|
65
|
function token_insert_ckeditor_pre_render_text_format($element) {
|
66
|
$element['#attached']['library'][] = array('system', 'drupal.ajax');
|
67
|
return $element;
|
68
|
}
|
69
|
|
70
|
function token_insert_ckeditor_custom_theme() {
|
71
|
if (strpos(current_path(), 'token_insert_ckeditor/insert') === 0) {
|
72
|
return 'seven';
|
73
|
}
|
74
|
}
|