field.pre.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // remove links of title
  20. $vars['items'][$index] = array("#markup" => $term->name);
  21. // dsm($term, 'term');
  22. $children = array();
  23. foreach(taxonomy_get_children($term->tid, $term->vid) as $child){
  24. // dsm($child, 'child');
  25. $children[] = $child->name;
  26. }
  27. if(count($children)){
  28. // dsm($children, 'children');
  29. $vars['items'][$index]["#markup"] .= ' ('.implode(', ', $children).')';
  30. }
  31. }
  32. }
  33. #images
  34. if($element['#field_type'] == 'image' && $element['#object']->type == 'performance'){
  35. $vars['item_classes'] = array();
  36. $delta = 0;
  37. foreach ($vars['items'] as $item) {
  38. // $classes = array();
  39. $classes[] = 'image image-'.$delta;//.' '.($delta % 2 ? 'odd' : 'even');
  40. // if($delta == 0){
  41. // $vars['items'][$delta]['#image_style'] = "grid_large";
  42. // $classes[] = 'grid-large-image';
  43. // }else if($delta < 4){
  44. // $vars['items'][$delta]['#image_style'] = "grid_medium";
  45. // $classes[] = 'grid-medium-image';
  46. // }else{
  47. // $vars['items'][$delta]['#image_style'] = "grid_small";
  48. // $classes[] = 'grid-small-image';
  49. // }
  50. $vars['item_classes'][] = implode(' ', $classes);
  51. $delta++;
  52. }
  53. }
  54. #date
  55. if($vars['element']['#field_name'] == 'field_date_de_debut' || $vars['element']['#field_name'] == 'field_date_de_fin'){
  56. global $language;
  57. //dsm($vars, "vars");
  58. foreach ($vars['items'] as $i => $item) {
  59. if($item['#markup'] != ''){
  60. $date_parts = explode('/', $item['#markup']);
  61. $date_str = $date_parts[0].'-'.(isset($date_parts[1]) ? $date_parts[1] : '1').'-'.(isset($date_parts[2]) ? $date_parts[2] : '1').' 00:00:00';
  62. $date = strtotime($date_str);
  63. //$vars['items'][$i]['#markup'] .= ' || '.$date_str . ' || '. date('d m Y', $date);
  64. switch($language->language){
  65. case 'fr':
  66. $date_frmt = (isset($date_parts[1]) && isset($date_parts[2])) ? 'd m Y' : 'Y' ;
  67. break;
  68. case 'en':
  69. $date_frmt = (isset($date_parts[1]) && isset($date_parts[2])) ? 'm d Y' : 'Y' ;
  70. break;
  71. }
  72. $vars['items'][$i]['#markup'] = date($date_frmt, $date);
  73. }
  74. }
  75. }