materio_taxonomy.module 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_taxonomy_permission() {
  6. $perms = array();
  7. // foreach (taxonomy_get_vocabularies() as $voc) {
  8. // dsm($voc, '$voc');
  9. // // $perms['access taxonomy term page'] => array(
  10. // // 'title' => t(''),
  11. // // 'description' => t(''),
  12. // // );
  13. // }
  14. $perms['access taxonomy terms page'] = array(
  15. 'title' => t('access taxonomy terms page'),
  16. 'description' => t(''),
  17. );
  18. return $perms;
  19. }
  20. function materio_taxonomy_menu_alter(&$items) {
  21. $items['taxonomy/term/%taxonomy_term']['access arguments'] = array('access taxonomy terms page');
  22. $items['taxonomy/term/%taxonomy_term/view']['access arguments'] = array('access taxonomy terms page');
  23. $items['taxonomy/term/%taxonomy_term/feed']['access arguments'] = array('access taxonomy terms page');
  24. }
  25. /**
  26. * Implementation of hook_query_term_access_alter().
  27. *
  28. * debug de i18n_select_query_term_access_alter()
  29. * qui filtre les terms par language mm pour les vocabulaires en mode localized.
  30. * utile pour la recherche avancée de materio_search_api materio_search_api_advanced_search_form()
  31. *
  32. */
  33. function materio_taxonomy_query_term_access_alter(QueryAlterableInterface $query) {
  34. // dsm($query, 'materio taxo query');
  35. $conditions =& $query->conditions();
  36. # roll over condition first time to determine i18n_voc_mode
  37. $i18n_voc_mode = 0;
  38. foreach ($conditions as $condition) {
  39. if (is_array($condition)) {
  40. // dsm($condition, 'conditon '.$condition['field']);
  41. if($condition['field'] == 't.vid'){
  42. $vid = $condition['value'];
  43. $i18n_voc_mode = i18n_taxonomy_vocabulary_mode($vid);
  44. // dsm($i18n_voc_mode, 'i18n_voc_mode');
  45. }
  46. }
  47. }
  48. # roll over conditions a second time to re-alter/fixe language selection
  49. # i18n vocabulary mode is 1 for localized terms
  50. if($i18n_voc_mode == 1){
  51. foreach ($conditions as $index => $condition) {
  52. if (is_array($condition)) {
  53. // dsm($condition, 'conditon '.$condition['field']);
  54. if($condition['field'] == 't.language' && $i18n_voc_mode == 1){
  55. $l = array('und');
  56. $ll = i18n_language_list();
  57. // dsm($ll, 'list language');
  58. foreach ($ll as $langcode => $langname) {
  59. $l[] = $langcode;
  60. }
  61. $conditions[$index]['value'] = $l;
  62. }
  63. }
  64. }
  65. }
  66. }