<?php

// dsm($vars);
$node = $vars['node'];


$vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];

$vars['print_title'] = !$vars['page'];

$alias = str_replace('/', '-', drupal_get_path_alias('node/'.$vars['node']->nid));

$vars['anchor_target'] = null;
if($node->type == "thematique"){
  // $vars['id'] =  $alias;
  // dsm($node, 'node');
  // $current_state = workflow_state_load_single($node->workflow);
  // dsm($current_state, "state");
  $vars['anchor_target'] = $alias;
}else{
  $vars["classes_array"][] = $alias;
  $vars['id'] =  "node-".$node->nid;

  if($vars['view_mode'] == "accueil"){
    $vars['print_title'] = false;
  }
}

if($node->workflow == 3){
  $vars["classes_array"][] = 'en_attente';
}

$scheduled_transitions = WorkflowScheduledTransition::load('node', $node->nid, NULL, 1);
$transition = false;
if(count($scheduled_transitions)){
  // if($node->type == "episode"){
  //   dsm($scheduled_transitions, "scheduled_transitions");
  // }
  $transition = $scheduled_transitions[0];
}
$vars['wf_stamp'] = $transition ? $transition->scheduled : false;

if($node->type == "episode" && $transition){
  // dsm($transition, "transition");
  // dsm($vars['content'], "content");
  // $vars['content']['transition'] = array(
  //   "#type"=> "markup",
  //   "#markup"=> format_date($transition->scheduled, 'custom', "d F Y"),
  //   "#prefix"=>"<span class='date'>",
  //   "#suffix"=>"</span>"
  // );
  $vars['content']['title_field'][0]['#markup'] .= "<span class='date'>".format_date($transition->scheduled, 'custom', "d F Y")."</span>";
}


$vars["classes_array"][] = "node-".$node->nid;
