Taxonomy tooltip funkciók bővítése/átalkítása

tiburi képe

Sziasztok!

Ti hogy oldanátok meg azt, hogy egy tag-hez a "további kapcsolódó tartalmak" ne egy blokkban, hanem mondjuk tooltip formájában jelenjen meg?

Én így próbálkoztam:

A taxonomy tooltip egy egyszerű és szép modul, ami a content body field-ben lévő minden olyan kifejezést, ami a taxonomy-ban is megtalálható kiemel és tooltip formájában a tag descriptiont kiírja, ha a kifejezés fölé visszük az egeret.

Ez kiindulásnak úgy gondoltam elég. Valahova a taxonomy_tooltip.module fájlba kéne behívni, direkt erre a célra egy általam létrehozott taxonomy nézet. De egyáltalán jól gondolom, vagy van ennél egyszerűbb megoldás is? :)

Próbálkoztam még a taxonomy description mezőkbe Token Insertek behívásával, de sajnos nem mentek (meg az inserteket ha lehet kerülném, mert volt velük már bajom).

Köszönöm!

  1. <?php
  2. /**
  3.  * @file
  4.  * Tha main file of the module.
  5.  */
  6.  
  7. /**
  8.  * Implements hook_menu().
  9.  */
  10. function taxonomy_tooltip_menu() {
  11. $items['admin/config/content/taxonomy-tooltip'] = array(
  12. 'title' => 'Taxonomy tooltip',
  13. 'page callback' => 'drupal_get_form',
  14. 'page arguments' => array('taxonomy_tooltip_settings_form'),
  15. 'access arguments' => array('administer taxonomy tooltip'),
  16. 'file' => 'taxonomy_tooltip.admin.inc',
  17. );
  18.  
  19. return $items;
  20. }
  21.  
  22. /**
  23.  * Implements hook_permission().
  24.  */
  25. function taxonomy_tooltip_permission() {
  26. return array(
  27. 'administer taxonomy tooltip' => array(
  28. 'title' => t('Administer taxonomy tooltip'),
  29. ),
  30. );
  31. }
  32.  
  33. /**
  34.  * Implements hook_init().
  35.  */
  36. function taxonomy_tooltip_init() {
  37. libraries_load('jquery-tooltip');
  38. drupal_add_js(drupal_get_path('module', 'taxonomy_tooltip') . '/taxonomy_tooltip.js');
  39. drupal_add_css(drupal_get_path('module', 'taxonomy_tooltip') . '/taxonomy_tooltip.css');
  40. }
  41.  
  42. /**
  43.  * Implements hook_libraries_info().
  44.  */
  45. function taxonomy_tooltip_libraries_info() {
  46. $libraries['jquery-tooltip'] = array(
  47. 'name' => 'jQuery Tooltip',
  48. 'vendor url' => 'http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/',
  49. 'download url' => 'http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/',
  50. 'version arguments' => array(
  51. 'file' => 'jquery.tooltip.min.js',
  52. 'pattern' => '/jQuery Tooltip plugin ([0-9\.]+)/',
  53. 'lines' => 2,
  54. ),
  55. 'files' => array(
  56. 'js' => array(
  57. 'jquery.tooltip.min.js',
  58. ),
  59. 'css' => array(
  60. 'jquery.tooltip.css',
  61. ),
  62. ),
  63. 'variants' => array(
  64. 'minified' => array(
  65. 'files' => array(
  66. 'js' => array(
  67. 'jquery.tooltip.min.js',
  68. ),
  69. 'css' => array(
  70. 'jquery.tooltip.css',
  71. ),
  72. ),
  73. ),
  74. 'source' => array(
  75. 'files' => array(
  76. 'js' => array(
  77. 'jquery.tooltip.js',
  78. ),
  79. 'css' => array(
  80. 'jquery.tooltip.css',
  81. ),
  82. ),
  83. ),
  84. ),
  85. );
  86.  
  87. return $libraries;
  88. }
  89.  
  90. /**
  91.  * Implements hook_filter_info().
  92.  */
  93. function taxonomy_tooltip_filter_info() {
  94. $filters['taxonomy_tooltip'] = array(
  95. 'title' => t('Taxonomy tooltip'),
  96. 'process callback' => 'taxonomy_tooltip_filter_process',
  97. );
  98.  
  99. return $filters;
  100. }
  101.  
  102. /**
  103.  * Returns with the replaced content.
  104.  *
  105.  * Finds for the term names and changes with the description tooltip.
  106.  */
  107. function taxonomy_tooltip_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
  108. // Check that the variable is set.
  109. if ($vocabs = variable_get('taxonomy_tooltip_vocabs', array())) {
  110. // Performance tuning.
  111. $pattern_map = &drupal_static(__FUNCTION__);
  112.  
  113. if (!$pattern_map) {
  114. // Initialize the array.
  115. $pattern_map['map'] = array();
  116. $pattern_map['tooltips'] = '';
  117.  
  118. foreach ($vocabs as $vid => $enabled) {
  119. if ($enabled) {
  120. $vids[] = $vid;
  121. }
  122. }
  123.  
  124. // Get the terms.
  125. $query = db_select('taxonomy_term_data', 't');
  126. $result = $query
  127. ->addTag('translatable')
  128. ->addTag('term_access')
  129. ->fields('t')
  130. ->condition('t.vid', $vids, 'IN')
  131. ->execute();
  132.  
  133. // Create map array. The first character must be a space and after the
  134. // word must be space, ".", ",", "?" or "!" character.
  135. foreach ($result as $id => $term) {
  136. if (trim($term->description)) {
  137. $pattern_map['map']['/( ' . drupal_strtolower($term->name) . '[ .,?!])/i'] = '<span class="taxonomy-tooltip-element" rel="taxonomy-tooltip-' . $id .'">$1</span>';
  138. // Move the tooltips to a separate to keep valid HTML.
  139. $pattern_map['tooltips'] .= '<div class="taxonomy-tooltip-' . $id .' taxonomy-tooltip">' . check_markup($term->description, $term->format) . '</div>';
  140. }
  141. }
  142. }
  143.  
  144. // Replace the text with the modified "tooltipped" one.
  145. foreach ($pattern_map['map'] as $pattern => $replace) {
  146. $text = preg_replace($pattern, $replace, $text);
  147. }
  148. // Append tooltips to the end of the content.
  149. $text .= $pattern_map['tooltips'];
  150. }
  151.  
  152. return $text;
  153. }
Melyik modulhoz, modulokhoz kapcsolódik a téma?: 
Drupal verzió: 
pp képe

Én írnék egy field formattert, ami az eredeti formattert bővíteni ki a kívánt funkcionalitással. A description-öket viszont vagy ajaxxal, vagy valamilyen lazy load technikával tolnám a kliens felé, és csak akkor használnám a fenti modul megoldását, ha biztos lehetek benne, hogy a termek száma pár tíz elemnél nem lesz több. Persze akkor sem, mert nem kell minden egyes termhez kirendeleni az összes többi létező term leírását. Mert ugye az felesleges, és az id egyediség miatt még valid se lesz a html. (működni azt fog. lol)

pp

0
0