I have a view that extarct a specific content type, this view shows the teaser view mode for rendering fields and not fields format :
the teaser view mode is managed with display suite module to order content type's fields in custom regions.
Im using hook_node_view to add a new field conditionally :
function MYMODULE_node_view($node, $view_mode, $langcode){
global $user;
$uuid = $user->uid;
switch ($node->type){
case "rewards" :
if(!empty($node->field_reward_users) && isset($node->field_reward_users[LANGUAGE_NONE][0]['target_id'])){
if($uuid == $node->field_reward_users[LANGUAGE_NONE][0]['target_id']){
$node->content['get_reward_link'] = array(
'#type' => 'markup',
'#markup' => l('Click Here', '/', array('attributes'=>array('class'=>'my-link-class'))),
'#weight' => 100,
);
}
}
// dpm($node);
break;
}
}
when i debug i can see the new field in the $node object, but it's not rendered. Have you any idea how to add fields conditionally in my case?
Update
I added a new preprocess field ("pre_rewards") via display suite, like montionned in the answer of Reynold, then I added the following prerocess function :
function MYMODULE_preprocess_node(&$vars){
if(isset($vars['preprocess_fields'])){
foreach ($vars['preprocess_fields'] as $key => $pre){
if($pre == 'pre_rewards' && isset($vars['content']['get_reward_link'])){
$reward_link = drupal_render($vars['content']['get_reward_link']);
$vars['preprocess_fields'][$key] = $reward_link;
}
}
}
dpm($vars);
}
and the same thing the element won't be rendered! and it exists in the $vars variable when i debug!
also the new field created exists in manage field page of my content type :
So why it's always not rendering the content of this field in my page!?
Thanks in advance.