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; }