field.pre.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. $element = $vars['element'];
  3. // dsm($vars, $element['#field_name'].' vars');
  4. # QUEST-CE QUE C4EST QUE CE TRUC ?
  5. if(count($vars['items']) == 1 && $element["#field_type"] == 'text' && $vars['element']['#field_name'] != 'field_date_de_debut'){
  6. if($vars['items'][0]['#markup'] == '' || count($vars['items'][0]['#markup']) < 5)
  7. $vars['items'] = array();
  8. }
  9. if(($element["#field_type"] == 'text_long') && count($vars['items']) == 1){
  10. if($vars['items'][0]['#markup'] == '')
  11. $vars['items'] = array();
  12. }
  13. $personnes_fields = array('field_concepteur', 'field_executant', 'field_organisateur', 'field_temoin');
  14. if(in_array($vars['element']['#field_name'], $personnes_fields)){
  15. $vars['classes_array'][] = 'field-personne';
  16. // dsm($vars, 'vars');
  17. foreach ($vars['element']['#items'] as $index => $item) {
  18. $term = $item['taxonomy_term'];
  19. // dsm($term, 'term');
  20. $children = array();
  21. foreach(taxonomy_get_children($term->tid, $term->vid) as $child){
  22. // dsm($child, 'child');
  23. $children[] = $child->name;
  24. }
  25. if(count($children)){
  26. // dsm($children, 'children');
  27. $vars['items'][$index]["#markup"] .= ' ('.implode(', ', $children).')';
  28. }
  29. }
  30. }
  31. #images
  32. if($element['#field_type'] == 'image' && $element['#object']->type == 'performance'){
  33. $vars['item_classes'] = array();
  34. $delta = 0;
  35. foreach ($vars['items'] as $item) {
  36. // $classes = array();
  37. $classes[] = 'image image-'.$delta;//.' '.($delta % 2 ? 'odd' : 'even');
  38. // if($delta == 0){
  39. // $vars['items'][$delta]['#image_style'] = "grid_large";
  40. // $classes[] = 'grid-large-image';
  41. // }else if($delta < 4){
  42. // $vars['items'][$delta]['#image_style'] = "grid_medium";
  43. // $classes[] = 'grid-medium-image';
  44. // }else{
  45. // $vars['items'][$delta]['#image_style'] = "grid_small";
  46. // $classes[] = 'grid-small-image';
  47. // }
  48. $vars['item_classes'][] = implode(' ', $classes);
  49. $delta++;
  50. }
  51. }
  52. #date
  53. if($vars['element']['#field_name'] == 'field_date_de_debut' || $vars['element']['#field_name'] == 'field_date_de_fin'){
  54. global $language;
  55. //dsm($vars, "vars");
  56. foreach ($vars['items'] as $i => $item) {
  57. if($item['#markup'] != ''){
  58. $date_parts = explode('/', $item['#markup']);
  59. $date_str = $date_parts[0].'-'.(isset($date_parts[1]) ? $date_parts[1] : '1').'-'.(isset($date_parts[2]) ? $date_parts[2] : '1').' 00:00:00';
  60. $date = strtotime($date_str);
  61. //$vars['items'][$i]['#markup'] .= ' || '.$date_str . ' || '. date('d m Y', $date);
  62. switch($language->language){
  63. case 'fr':
  64. $date_frmt = (isset($date_parts[1]) && isset($date_parts[2])) ? 'd m Y' : 'Y' ;
  65. break;
  66. case 'en':
  67. $date_frmt = (isset($date_parts[1]) && isset($date_parts[2])) ? 'm d Y' : 'Y' ;
  68. break;
  69. }
  70. $vars['items'][$i]['#markup'] = date($date_frmt, $date);
  71. }
  72. }
  73. }