-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtagging.module
150 lines (132 loc) · 4.36 KB
/
tagging.module
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
<?php
// Author: Eugen Mayer (http://kontextwork.de)
// Copyright 2010
require_once('tagging.field.inc');
require_once('tagging_base.class.inc');
/**
* hook_menu
*/
function tagging_menu() {
return tagging_base::instance()->hook_menu();
}
/**
* Implementing hook_elements
* Registering the new form element, so we can render the tagging form element properly
*/
function tagging_elements() {
$type['tagging_widget'] = array(
'#input' => TRUE,
'#after_build' => array('_tagging_widget_javascript'),
'#process' => array('_tagging_add_suggestions'),
'#default_value' => -1,
);
return $type;
}
/**
* Implementation of hook_form_alter.
*
*/
function tagging_form_alter(&$form, $form_state, $form_id) {
tagging_base::instance()->hook_tagging_form_alter($form, $form_state, $form_id);
}
/**
* Implementation of hook_form_ID_alter.
*
*/
function tagging_form_taxonomy_form_vocabulary_alter(&$form, $form_state) {
tagging_base::instance()->hook_tagging_form_taxonomy_form_vocabulary_alter($form, $form_state);
}
/**
* Implementing hook_theme.
*/
function tagging_theme() {
return tagging_base::instance()->hook_theme();
}
/**
* Rendering the tagging widget.
*/
function theme_tagging_widget($element) {
$args = func_get_args();
return call_user_func_array(array(tagging_base::instance(), 'theme_tagging_widget'), $args);
}
/**
* Rendering the widget button
*/
function theme_tagging_widget_button() {
$args = func_get_args();
return call_user_func_array(array(tagging_base::instance(), 'theme_tagging_widget_button'), $args);
}
/**
* Rendering the wrapper of the widget
*/
function theme_tagging_widget_wrapper() {
$args = func_get_args();
return call_user_func_array(array(tagging_base::instance(), 'theme_tagging_widget_wrapper'), $args);
}
/**
* Rendering suggestions for a specific vocabulary
*/
function theme_tagging_tags_list($variables) {
$args = func_get_args();
return call_user_func_array(array(tagging_base::instance(), 'theme_tagging_tags_list'), $args);
}
function _tagging_check_tag($tag) {
$tag = trim(check_plain($tag));
return $tag;
}
/**
* Rendering suggestions
* we need $vid for namespacing only
*/
function theme_tagging_suggestions_list($variables) {
$args = func_get_args();
return call_user_func_array(array(tagging_base::instance(), 'theme_tagging_suggestions_list'), $args);
}
/**
* Defining new hook: hook_tagging_suggestion
* Modules can use this hook to implement their methods to provide suggestions for tagging
* the current node
*/
function _tagging_add_suggestions($element) {
$suggestions = _tagging_get_suggestions($element['#vid'], $element['#nid']);
$element['#suggestions'] = $suggestions;
return $element;
}
/**
* @param number $vid: This is the vid the suggestions have been called for. You can use this to decide whether you
* want to suggest something or not for this vocabulary
* @param stdClass $node: This is the complete expanded node object. Use this to e.g. base your suggestions on the body
* of the node or the title or whatever you wish on
*/
function _tagging_get_suggestions($vid, $node = null) {
if(is_numeric($node)) {
$node = node_load($node);
}
$suggestions = module_invoke_all('tagging_suggestions', $vid, $node);
drupal_alter('tagging_suggestions', $suggestions);
// Validation
if (!is_array($suggestions)) {
$suggestions = array();
watchdog(WATCHDOG_WARNING, 'Tagging: Could not parse suggestion array - maybe some hooks are out of bound?');
}
// Iam not going to hold the devs hand and validate if we got a valid array with #name / #weight
uasort($suggestions, 'element_sort');
if (variable_get('tagging_show_max_suggestion', 20) > 0) {
$suggestions = array_slice($suggestions, 0, variable_get('tagging_show_max_suggestion', 20));
}
return $suggestions;
}
/**
* Implementing #process of the form element tagging_widget.
* Adding Javascript-Libraries needed, if a widget has been placed.
*/
function _tagging_widget_javascript($form_element = null, &$form_state = array()) {
return tagging_base::instance()->_tagging_widget_javascript($form_element, $form_state);
}
/**
* Saving the variable, whether to show the widget for a taxonomy or not
*/
function tagging_form_vocabulary_submit($form, &$form_state) {
variable_set('tagging_inject_' . $form_state['values']['vid'], $form_state['values']['tagging_inject']);
return TRUE;
}