How to use the view_mode in hook_preprocess_flag? I'm using Drupal 7 and Flag.

I try to modify the output of my flags according to the view mode with preprocess_flag :

function mytheme_preprocess_flag(&amp;$variables) {
  $variables['full'] = $variables['view_mode'] == 'full';
  if ($variables['full']) {
...
  }
}


But i have an error : Notice : Undefined index: view_mode dans publiu_preprocess_flag().

Do you know how to use the view_mode in hook_preprocess_flag ?
view_mode key is not in variables object, which you get as argument. You can check for the same, by printing variables object.

print '&lt;pre&gt;';
print_r($variables);
print '&lt;/pre&gt;';


However if u still want to get view mode, you can use somewhat like below.

function bartik_preprocess_flag(&amp;$variables) {
  $arg_1 = arg(1);
  if( isset($arg_1) &amp;&amp; !empty($arg_1) ) {
    $menu_obj = menu_get_object();
    $menu_obj_content = $menu_obj['content'];
    foreach($menu_obj_content as $menu_key=&gt;$menu_val) {
      $node_view_mode = $menu_val['#view_mode'];
      break;
    }
    print $node_view_mode;
  }
}


Here node_view_mode will return "View Mode" of current node.